-
-
Notifications
You must be signed in to change notification settings - Fork 649
Improve Feng, PNC algorithm #40510
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
Improve Feng, PNC algorithm #40510
Conversation
How difficult would it be to avoid the duplication of methods |
I think the easiest option is to integrates two functions and use common code except for The plan is to integrate |
I suggest to start with the "easy" parts that can be shared. I assume that mixing Feng and PNC is much more involved and prone to errors. |
Now, L1103-L1236 is exactly same as L1401-L1534 in path_enumeartion.pyx.
will keep two algorithms independent, so will not make serious error. |
I am not sure how to handle deleted functions (e.g., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An option is to keep both methods feng_k_shortest...
and pnc_k_shortest...
with only few tests and doing only yield from nc_k_shortest...
.
This way we avoid the need for deprecation.
Furthermore, it ease the manipulation of the different algorithms if one wants to do some benchmark.
@@ -571,11 +570,12 @@ def shortest_simple_paths(self, source, target, weight_function=None, | |||
if not self.is_directed(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this part can be simplified as follows
if algorithm in ("Feng", '"PNC"):
if not self.is_directed():
raise ValueError(f"{algorithm}'s algorithm works only for directed graphs")
yield from nc_k_shortest_simple_paths(self, source=source, target=target,
weight_function=weight_function,
by_weight=by_weight, check_weight=check_weight,
report_edges=report_edges,
labels=labels, report_weight=report_weight,
postponed=algorithm == "PNC")
elif algorithm == "Yen":
yield from yen_k_shortest_simple_paths(self, source=source, target=target,
weight_function=weight_function,
by_weight=by_weight, check_weight=check_weight,
report_edges=report_edges,
labels=labels, report_weight=report_weight)
- instead of using parameter
algorithm
innc_k_shortest_simple_paths
, I propose to simply use a booleanpostponed=True|False
src/sage/graphs/path_enumeration.pyx
Outdated
# (i.e. real length = cost + shortest_path_length in T_0) | ||
# this is used in the "postponed" algorithm | ||
cdef priority_queue[pair[pair[double, bint], pair[int, int]]] candidate_paths2 | ||
if algorithm == "normal": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an empty line before/after to improve readability.
src/sage/graphs/path_enumeration.pyx
Outdated
new_cost = cost + deviation_weight | ||
candidate_paths.push(((-new_cost, True), (new_path_idx, dev_idx))) | ||
former_part.remove(path[deviation_i]) | ||
elif algorithm == "postponed": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line before/after
you should update the branch on the last beta now that #40364 has been merged |
Documentation preview for this PR (built with commit dfa5625; changes) is ready! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Further improvements are certainly possible, but it is enough for this PR.
sagemathgh-40510: Improve Feng, PNC algorithm <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> + Fix several bugs of PNC algorithm. + Improve implementation of Feng algorithm. + Add PNC as a supported algorithm in shortest_simple_paths ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40364 URL: sagemath#40510 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40547: Update NC k shortest simple path for Undirected graphs <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Update nc_k_shortest_simple_path algorithm for undirected graphs. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40510 URL: sagemath#40547 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40510: Improve Feng, PNC algorithm <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> + Fix several bugs of PNC algorithm. + Improve implementation of Feng algorithm. + Add PNC as a supported algorithm in shortest_simple_paths ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40364 URL: sagemath#40510 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40547: Update NC k shortest simple path for Undirected graphs <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Update nc_k_shortest_simple_path algorithm for undirected graphs. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40510 URL: sagemath#40547 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40510: Improve Feng, PNC algorithm <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> + Fix several bugs of PNC algorithm. + Improve implementation of Feng algorithm. + Add PNC as a supported algorithm in shortest_simple_paths ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40364 URL: sagemath#40510 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40547: Update NC k shortest simple path for Undirected graphs <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Update nc_k_shortest_simple_path algorithm for undirected graphs. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40510 URL: sagemath#40547 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40510: Improve Feng, PNC algorithm <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> + Fix several bugs of PNC algorithm. + Improve implementation of Feng algorithm. + Add PNC as a supported algorithm in shortest_simple_paths ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40364 URL: sagemath#40510 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40547: Update NC k shortest simple path for Undirected graphs <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Update nc_k_shortest_simple_path algorithm for undirected graphs. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40510 URL: sagemath#40547 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40547: Update NC k shortest simple path for Undirected graphs <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes sagemath#12345". --> Update nc_k_shortest_simple_path algorithm for undirected graphs. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> sagemath#40510 URL: sagemath#40547 Reported by: Yuta Inoue Reviewer(s): David Coudert
📝 Checklist
⌛ Dependencies
#40364