-
Notifications
You must be signed in to change notification settings - Fork 91
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
Change A* output to a vector of tuples #116
Conversation
For anyone interested, this is literally a 4-line review and can help a great deal! |
@paulmelis since you opened the initial issue, does this solve your problem? |
Codecov Report
@@ Coverage Diff @@
## master #116 +/- ##
==========================================
- Coverage 97.54% 97.54% -0.01%
==========================================
Files 109 109
Lines 6318 6317 -1
==========================================
- Hits 6163 6162 -1
Misses 155 155 |
Well, I just checked the original issue I created, but it seems LightGraphs is no longer in development, and my original example now fails with the latest versions (can't create weighted edges it seems). |
That's weird, it works on my side. Is this the snippet you ran? using Graphs
using SimpleWeightedGraphs
g = SimpleWeightedDiGraph(3)
add_edge!(g, 1, 2, 0.5)
add_edge!(g, 2, 3, 0.8)
add_edge!(g, 1, 3, 2.0)
a_star(g, 1, 3) |
Almost, I was doing |
Well the fix isn't there yet in Graphs.jl, but it's in the current PR, so if you want to test, you'll have to do using Pkg
Pkg.add("SimpleWeightedGraphs")
Pkg.add(url="https://github.com/gdalle/Graphs.jl/", rev="shortest_paths") |
This is a breaking change and I'm not very confident with tags and releases, so I wouldn't mind if someone else took over the merging so I can see how it's done 😊 |
It would be better if we can make this a non-breaking change, for example by adding a new method rather than removing the previous one, or adding an optional argument indicating how to construct edges |
I agree, we should enforce in the interface for edges types the implementation of a constructor given only start and end points, which would set default values for weights, labels and other data. |
I'm not sure about this. Until now, the Graphs.jl interface only specified things about the graphs themselves, not their edges, so that would be an even bigger change for many ecosystem packages, wouldn't it? |
I don't think it is that breaking to ask to implement a new method for edges. If users were using an edge type without implementing this type of constructor, A* would error anyway. It will be breaking only if we make some existing functions rely on the assumptions that these constructors must be implemented. Moreover, keeping the actual behavior would allow us to allow multigraphs without deprecating A*, if we would be willing one day to support them. |
On the other hand this would mean that for weighted edges, we ask the users to implement a method |
I would rather find a way to return a |
yes that sounds sensible |
That would set a default that can be overwritten |
To me, it feels like #13, if our graphs are not multigraphs, there is no reason to return edges, we could just return the sequence of vertices, and have an helper function that gives edges from the sequence of vertices. If we choose to be breaking, why not getting rid of edges ? |
If we choose to be breaking, that is what we should do. But the solution outlined by @matbesancon only changes the behavior when it errors anyway, so it is not breaking |
That would work but isn't it weird to return an object not of type |
In any case it will be weird. But I think it would be weirder to return a path made of weighted edges with fake weights all equal to 1 for instance |
Ok, last try, could it be possible to ask for a graph |
@etiennedeg that would make sense to me, since it would allow returning a path that is made of native edges associated with the graph object. And the fix by @matbesancon would be a fallback that returns |
If that's okay with you, I'll get to it soon, and try to fix #120 in the process |
But wait isn't it breaking to ask users to implement an additional function, especially if we plan on using it elsewhere in the codebase? |
Yes, I think it will even be breaking for every graph implementation outside of |
I would rather avoid defining |
If we discard this solution, I think the only remaining reasonable suggestion is Mathieu's suggestion. For the Also something to take note: if we add a new method |
I'll close this PR since it has a misleading name, and open a new one to fix the issue with @etiennedeg 's suggestion without adding it to the documented API. That way it is non-breaking and remains hidden. We can always go back to it at a later date, the important thing being that A* finally starts working on weighted graphs. Okay with you both ? |
This PR solves #59 by making the output of A* independent from the underlying graph type.
Until now,
a_star(g, ...)
tried to reconstruct the shortest path as aVector{E}
, whereE
is the edge type ofg
. However, for labelled or weighted graphs, callingE(s, d)
was not enough to create a valid edge, leading to a bug.