Wrong ShortestAll() paths
Chekunin opened this issue · comments
Aleksei Chekunin commented
package main
import (
"github.com/RyanCarrier/dijkstra"
"fmt"
)
func main() {
graph := dijkstra.NewGraph()
graph.AddVertex(0)
graph.AddVertex(1)
graph.AddVertex(2)
graph.AddVertex(3)
graph.AddVertex(4)
graph.AddVertex(5)
graph.AddArc(0,1,1)
graph.AddArc(0,3,1)
graph.AddArc(1,2,1)
graph.AddArc(1,4,1)
graph.AddArc(2,5,1)
graph.AddArc(3,4,1)
graph.AddArc(4,2,1)
graph.AddArc(4,5,1)
paths, err := graph.ShortestAll(0, 5)
if err != nil {
panic(err)
}
for _, path := range paths {
fmt.Printf("dist=%d path=%v\n", path.Distance, path.Path)
}
}
The printed result:
dist=3 path=[0 1 4 0 3 4 5]
dist=3 path=[0 1 2 5]
So the first one is incorrect.
Ryan commented
True, I'll check weekend
Boris Strelchik commented