Infinite loop detectedFrom node '1' to node '0'
sonygod opened this issue · comments
Mr zhan commented
func main() {
fmt.Print("开始计算\n")
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)
graph.AddArc(1, 2, 2)
graph.ExportToFile("B.txt")
best, err := graph.Shortest(0, 2)
if err != nil {
log.Fatal(err)
}
fmt.Println("Shortest distance ", best.Distance, " following path ", best.Path)
best2, err2 := graph.Longest(0, 2)
if err2 != nil {
log.Fatal(err2)
}
fmt.Println("Longest distance ", best2.Distance, " following path ", best2.Path)
}
Ryan commented
Working as intended. If you wanted the longest distance, you would keep going from 1->0->1->0 infinite times (as this makes the distance longer), then to 2 after. This would make the longest path infinite.