Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop detectedFrom node '1' to node '0' #8

Closed
sonygod opened this issue Aug 30, 2019 · 1 comment
Closed

Infinite loop detectedFrom node '1' to node '0' #8

sonygod opened this issue Aug 30, 2019 · 1 comment

Comments

@sonygod
Copy link

sonygod commented Aug 30, 2019

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)
}
@RyanCarrier
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants