I'm currently trying to implement a path finding algorithm in Go. I'm currently committed to get Dijkstra working since that's supposed to be one of the simpler algorithms regarding path findinig. However I have a hard time getting it right. Most of my tests results in infinite loops.
For my tests I'm currently using a ESRI Shapefile as a source and build a graph with it that consists of Vertexes and Edge's (or Node's and Arcs, whatever suits you). This seems to work great, but it's a little memory hungry at the moment.
I started building on this question which seems to work according to the example. But once I adjusted it for my needs, which are real-world coordinates and no id's in the vertex, something seems wrong...
Relevant code that I'm suffering with (part of a gist):
const MAX_LENGTH = 1000000
type MinDistanceFromSource map[*Vertex]float64
func (G *Graph) Dijkstra(source, destination *Vertex) MinDistanceFromSource {
D := make(MinDistanceFromSource)
for _, vertex := range G.Vertexes {
D[vertex] = MAX_LENGTH
}
D[source] = 0
for edge := range source.GetAdjacentEdges() {
D[edge.Destination] = edge.Length
}
// calculateDistance(source, destination, D) // Fix me...?
for _, vertex := range G.Vertexes {
vertex.visited = false // fixme
}
return D
}
The main thing I'm asking myself is if I'm doing this right or am I just off by miles? And how can I make this work? Or am I better of trying to implement something like A*?
Also; the relevant Shapefile that I'm trying this with: NWB_01-01-2015 (100MB zip)