https://github.com/hamed-rezaee/dart_shortest_path
https://github.com/hamed-rezaee/dart_shortest_path
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hamed-rezaee/dart_shortest_path
- Owner: hamed-rezaee
- Created: 2023-03-02T04:39:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-02T04:43:58.000Z (over 2 years ago)
- Last Synced: 2025-01-03T19:32:10.361Z (9 months ago)
- Language: Dart
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Shortest Path Algorithm using A\* Algorithm
This code defines two classes, Node and Graph, to implement the A\* algorithm for finding the shortest path between two nodes in a graph.
## Node Class
The Node class represents a node in the graph. It has three properties:
- id: A unique identifier for the node.
- neighbors: A list of Node objects representing the neighbors of the node.
- heuristic: A heuristic value for the node used by the A\* algorithm.## Graph Class
The Graph class represents the graph. It has one property:
- nodes: A list of Node objects representing the nodes in the graph.
It also has one method:
- shortestPath(start, goal): Takes in two Node objects representing the start and goal nodes and returns the shortest path between them using the A\* algorithm.
## Usage
To use the code, create a Graph object and set its nodes property to a list of Node objects representing the nodes in the graph. Then, call the shortestPath method on the Graph object, passing in the start and goal Node objects as arguments.
The code also includes an example of how to print the graph as a matrix and how to print the shortest path between two nodes if one exists.