RyanCarrier / dijkstra

Fastest golang Dijkstra path finder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error use graph

Peakchen opened this issue · comments

package main

func main(){
graph:=dijkstra.NewGraph()
//Add the 3 verticies
graph.AddVertex(0)
graph.AddVertex(1)
graph.AddVertex(2)
//Add the arcs
graph.AddArc(0,1,1)
graph.AddArc(0,2,1)
graph.AddArc(1,0,1) // should be delete then print right.
graph.AddArc(1,2,2)

shortbest, err := graph.Shortest(0, 2)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Shortest distance ", shortbest.Distance, " following path ", shortbest.Path)

longbest, err := graph.Longest(0, 2)
if err != nil {
	log.Fatal(err)
}
fmt.Println("Longest distance ", longbest.Distance, " following path ", longbest.Path)

}

print result:
Shortest distance 1 following path [0 2]
Longest distance 3 following path [0 1 2]

commented

?