Conversation
|
This is a WIP - does it do the right thing, does the API have the right shape, and so on. |
Breadth first search for all paths from a given starting point to all reachable nodes. Paths are sequences of edge ids for this implementation.
6bfabd8 to
03082ed
Compare
|
Consider |
|
This is very neat! I'm definitely in favor of calling this |
Peiffap
left a comment
There was a problem hiding this comment.
A minor comment/question; I'm not familiar enough with Rust to quickly see what this is doing and I'm definitely not familiar enough with petgraph to know whether this fits. Also adding here (for visibility) that I'm +1 on using trail nomenclature instead of non-repeating path.
|
One question I had about this algorithm - not related to uv - if we start at 0, aren't both A, D and A, D, E, F, G valid trails from 0 to 3? The current implementation only produces the first trail. The second is disallowed because it starts with the same sequence as the first. (I think this implementation is useful, but not sure what's correct w.r.t finding all trails.) |
|
I got confused about paths vs. trails. I think you should actually allow the second trail too, since it's purely about the edges being traversed. |
|
@bluss I noticed this PR the other day and thought it might be worth mentioning that a very similar thing was done in a recent student project here. Your approach is less rough to be sure, but I'm putting this out there on account of the fact that using: pub fn all_non_repeating_paths_from<
G: IntoEdges + GraphProp<EdgeType = Directed> + GraphProp<NodeId = N> + GraphProp<EdgeId = E>,
N: Eq + Copy + Clone,
E: Eq + Copy + Clone,
>(
graph: G,
starting_node: G::NodeId,
) -> Vec<(G::NodeId, Vec<Path<G::EdgeId>>)> { ... }gets to avoid using |
|
@DeliciousHair I think that suggestion changes the algorithmic complexity of the implementation (not that I've analyzed fully), there needs to be some replacement of the O(1) hashmap lookup (could use compact space of integer indexes, but that's another constraint on the graph interface required - doesn't work well with the induced subgraph usecase of NodeFiltered?) Also a tip, you don't need to have type parameters for N and E, they are available as G::NodeId and G::EdgeId (as seen in the PR). |
|
@Peiffap I saw your edit now. I think we say the same thing now, the current algorithm finds only one path from 0 to 1 in this graph:
I think the current algorithm because of this is an "all simple paths" algorithm, and that's fine for me. (Is there something we're missing?) |
3288632 to
267253b
Compare
|
How does this differ from the existing Note that for the uv use-case this originally spawned from, I don't think trails that aren't paths are particularly interesting - they just add additional markers, if I understand correctly. |
e401df9 to
7e76d10
Compare
7e76d10 to
9b55d77
Compare
|
The existing |
|
User ms on the ndarray zulip endorsed the function as "it's very useful and solid" 🙂, so it's gotten one review |
|
May I suggest that the documentation contain a note/warning added about the size of the result being potentially quite large in the case where the graph contains parallel edges? |
This commit ends up touching a fair chunk of code outside of the (proposed) `all_simple_paths_from` function. * rename `all_simple_paths` -> `all_simple_node_paths` * rename `all_simple_paths_from` -> `all_simple_edge_paths_from` * add analogous function `all_simple_edge_paths` that gives an iteralbe over paths, specified by edges * function signature altered to clarify language + remove opaque counting feature * checking added, both functions will panic instead of quitely fixing things for the user * tests added, including negative tests
|
Hi all! Is there anything else that separates the adoption of this new algorithm in the next release? |
|
Happy to put my hand up to fix the conflicts if that will get this merged? |
|
@DeliciousHair I think that would be helpful |
Thanks for the offer, that'd be wonderful 🌞 Note however, that currently a new major release is in the making which will break a lot of the existing functionality, which is why this change might need some time to be adopted until the scaffolding for 0.9 is done. As the algorithm will probably mostly use the current graph traits however, it should not be affected by the first "wave" of changes, which will keep the existing graph traits intact :) TLDR: It might take more time than usual until this PR is merged :) Please also note the algorithm doc template we are using 👍 EDIT: Forgot to link the issue laying out the changes ^^ |
|
Thanks for the heads up! With that in mind, if there are no objections I'll simply make a new pr to account for these details rather than trying to massage this one into a passing state. Sound OK? |

Breadth first search for all paths from a given starting point to all reachable nodes.
Paths are sequences of edge ids for this implementation.
This implementation is intentionally written using the visit traits so that it is compatible with multiple graph implementations, including graphs wrapped in NodeFiltered which enables running the algorithm on an induced subgraph.
This comes from this discussion: astral-sh/uv#4645
The graph in the test looks like this.