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

Can not get more than 1 path with ShortestAll #7

Closed
tegk opened this issue Jul 25, 2019 · 3 comments
Closed

Can not get more than 1 path with ShortestAll #7

tegk opened this issue Jul 25, 2019 · 3 comments

Comments

@tegk
Copy link

tegk commented Jul 25, 2019

How do i use the new ShortestAll function properly?

Output generated:


1
Shortest distance  1  following path  [0 2 3]

Expected output:

2
Shortest distance  1  following path  [0 1 3]
Shortest distance  1  following path  [0 2 3]

Code:


package main

import (
	"fmt"
	"github.com/RyanCarrier/dijkstra"
	"log"
)


func main() {
	graph := dijkstra.NewGraph()
	//Add the 4 verticies
	graph.AddVertex(0)

	graph.AddVertex(1)
	graph.AddVertex(2)

	graph.AddVertex(3)

	//Add the arcs
	graph.AddArc(0, 1, 1)
	graph.AddArc(0, 2, 1)

	graph.AddArc(1, 3, 0)
	graph.AddArc(2, 3, 0)

	best, err := graph.ShortestAll(0, 3)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(len(best))
	for _, v := range best {
		fmt.Println("Shortest distance ", v.Distance, " following path ", v.Path)

	}
}


@RyanCarrier
Copy link
Owner

Turns out I'm actually braindead, I'll fix this at some point, sorry

RyanCarrier added a commit that referenced this issue Jul 26, 2019
@RyanCarrier
Copy link
Owner

Working correctly now. Thanks for letting me know

@tegk
Copy link
Author

tegk commented Jul 26, 2019

I can confirm that this works now. Thank you, for the great work!

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