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

Create simple_paths_generator_with_score.rs #1284

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

ranjana-mishra
Copy link

@ranjana-mishra ranjana-mishra commented Sep 20, 2024

It uses Dijkstra Algo to generate all possible paths , by deleting one edge at a time, and gives the paths with their score.
Also provides a alternative for existing k-shortest-paths function, as that fails on some test cases.
Related to #671

It uses Dijkstra Algo to generate all possible paths , by deleting one edge at a time, and gives the paths with their score.
@CLAassistant
Copy link

CLAassistant commented Sep 20, 2024

CLA assistant check
All committers have signed the CLA.

@ranjana-mishra
Copy link
Author

ranjana-mishra commented Sep 20, 2024

@mtreinish can you review the PR and suggest how we move forward.

@coveralls
Copy link

coveralls commented Sep 20, 2024

Pull Request Test Coverage Report for Build 11030598879

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.816%

Totals Coverage Status
Change from base Build 10928052046: 0.0%
Covered Lines: 17999
Relevant Lines: 18785

💛 - Coveralls

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your first contribution to rustworkx, I did a quick first pass through the code and left some high level inline comments. The biggest things missing right now is that this code isn't actually included in the library, the module isn't included anywhere that gets linked in from the root library. This means while the source file is in tree nothing is building it as part of rustworkx-core. Besides not including the source as part of the library this is preventing things like the formatter and linter from actually running on it. I think you should move your new file out of rustworkx-core/src/generators/ and into rustworkx-core/src/shortest_path, then you will need to modify https://github.com/Qiskit/rustworkx/blob/main/rustworkx-core/src/shortest_path/mod.rs to include your new module and re-export the public interface like is done for the other shortest path functions. Once that is done then the code will be included in the library at build time.

Following that I expect there will be lint and formatting things to fix as I observed a couple of places that needed to be fixed. The other thing is I left a comment inline about tests we should be sure we're exercising the code as part of the PR to make sure we're adequately testing everything. I would suggest taking a look at the project's contributing guide: https://github.com/Qiskit/rustworkx/blob/main/CONTRIBUTING.md which covers these aspects in a bit more detail.

I haven't gone through the bulk of the logic of the new function yet, I'll review the algorithm and the function in more depth along with a deeper code review when these higher level issues are fixed. There is also the question of introducing a python interface too, but we can discuss that after we have a functional rustworkx-core function.

rustworkx-core/src/generators/simple_shortest_paths.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/simple_shortest_paths.rs Outdated Show resolved Hide resolved
}

// This is mutation of petgraph dijkastra to get full path between source to target
fn dijkstra<G, F, K>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not review this specific Dijkastra, but petgraph dijkastra returns only score of each node between source & target. but how to find the path from source -> target is not clear from that score. thats why i have updated the code to return the previous node as, that it followed to reach to the destination.
like - if the path for lowest score was A->B-->C->D, it will return the score, also Node (C), which is the previous node, similarly for C , it will return score & B as previous node, and for B it will return A as previous node, which we can use to reach till A from D.

Let me know if I am missing something on existing Dijkastra functioning.

rustworkx-core/src/generators/simple_shortest_paths.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/simple_shortest_paths.rs Outdated Show resolved Hide resolved
Comment on lines 263 to 270
loop {
let pre_node = path.get(node).expect("Error");
paths.push(*pre_node);
if *pre_node == s.source {
break;
}
node = pre_node;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it'd be better to rework this as a while loop so the exit conditions are a bit more clear.

Copy link
Author

@ranjana-mishra ranjana-mishra Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it'd be better to rework this as a while loop so the exit conditions are a bit more clear.

it actually back tracks the path till source, if the next node is source, then it exits.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see the current status, even though its same with comment one will get to know the exit state.

rustworkx-core/src/generators/simple_shortest_paths.rs Outdated Show resolved Hide resolved
@ranjana-mishra
Copy link
Author

Please review the PR -

  • it is fix over k-shortest paths ( same cost paths ), as that is not considering already visited points and fails on test cases.
  • Provide function to get n paths in increasing cost order.

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

Successfully merging this pull request may close these issues.

4 participants