https://github.com/baifei2014/pathfinding
pathfinding library about dijkstra and a_star algorithm
https://github.com/baifei2014/pathfinding
Last synced: 4 months ago
JSON representation
pathfinding library about dijkstra and a_star algorithm
- Host: GitHub
- URL: https://github.com/baifei2014/pathfinding
- Owner: baifei2014
- Created: 2023-10-23T11:48:43.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T02:40:31.000Z (about 2 years ago)
- Last Synced: 2025-06-20T11:07:23.481Z (7 months ago)
- Language: Go
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
pathfinding library about dijkstra and a_star algorithm
## Examples
The following are demonstration examples of two algorithms
### Dijkstra
#### first step
- generate graph
- define start, goal
- define cost of cost so far and shortest path by came from
```go
graph := implementions.MakeDiagram4()
start := implementions.Location{X: 1, Y: 4}
goal := implementions.Location{X: 8, Y: 5}
came_from := map[implementions.Location]implementions.Location{}
cost_so_far := map[implementions.Location]int{}
```
#### second step
- do search
- construct path
```go
implementions.DijkstraSearch(graph, start, goal, came_from, cost_so_far)
path := implementions.ReconstructPath(start, goal, came_from)
```
#### third step
- draw path on graph
```go
implementions.DrawGrid(graph, path)
```
### A_Star|A*
#### first step
- generate graph
- define start, goal
- define cost of cost so far and shortest path by came from
```go
graph := implementions.MakeDiagram4()
start := implementions.Location{X: 1, Y: 4}
goal := implementions.Location{X: 8, Y: 5}
came_from := map[implementions.Location]implementions.Location{}
cost_so_far := map[implementions.Location]int{}
```
#### second step
- do search
- construct path
```go
implementions.AStarSearch(graph, start, goal, came_from, cost_so_far)
path := implementions.ReconstructPath(start, goal, came_from)
```
#### third step
- draw path on graph
```go
implementions.DrawGrid(graph, path)
```