-
-
Notifications
You must be signed in to change notification settings - Fork 648
Improve PNC algorithm #40364
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 PNC algorithm #40364
Conversation
I am wondering whether there can be more improvement of this implementation of PNC algorithm. when getting a path in |
Documentation preview for this PR (built with commit 53d8308; changes) is ready! 🎉 |
Some ideas to be tested:
cdef list int_to_vertex = list(G)
cdef dict vertex_to_int = {u: i for i, u in enumerate(int_to_vertex)}
G.relabel{perm=vertex_to_int, inplace=True)
cdef int id_source = vertex_to_int[source]
cdef int id_target = vertex_to_int[target]
|
I have done the second, the fourth improvements. It became slightly faster. I have already done the first one. |
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.
the light be other possible improvements, but I'm not sure which ones yet.
Let me know if you plan to do more on this PR or if you prefer to use a follow up PR for other changes. |
Sorry for the inconvenience. I will plan to do more on this PR. |
I implemented the shortest path computation for a set of target vertices (not one target vertex) and use it to compute shortest path to green vertices in PNC algorithm. It became faster than previous one in my laptop (150-160ms to 90-100ms for graphs.Grid2dGraph(5, 5)). |
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.
a few suggestions to improve method shortest_path_to_set
:
- prefer
source
andtargets
tox
andy_set
- Ensure that
exclude_vertices
is turned to a set when not empty to speed up tests - add tests for cases when the source is in
exclude_vertices
or in targets - is the method working well if a target is in
exclude_vertices
? - is it faster to use a priority queue or a pairing heap (this data structure has decrease key operation) ?
- when iterating over edges, prefer
label
tol
to avoid confusion with1
They are not much different. Either one is ok. |
you should rebase on the last beta to better highlight the changes done in this PR. |
…on in pnc algorithm)
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.
Shouldn't we raise an error when no path can be found ?
I agree with the addition of the shortest path to set method. This might be useful to others. |
I agree with you. Coloring only necessary portions of graphs will be faster. I try to implement it. |
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.
is it faster in your experiments ?
It is a little faster, though I tested only one instance.
will take about 90ms now, but previous one takes about 110ms. And execution time becomes stable (the previous one sometimes takes 150ms), but I don't know why. I would like to also know how execution time changed in your environment. |
on a linux computer I get sage: D = graphs.Grid2dGraph(5, 5).relabel(inplace=False).to_directed()
sage: %time len(list(pnc(D, 0, 24)))
CPU times: user 159 ms, sys: 6 µs, total: 159 ms
Wall time: 159 ms
8512 on a Mac M1 I get sage: %time len(list(pnc(D, 0, 24)))
CPU times: user 232 ms, sys: 1.02 ms, total: 233 ms
Wall time: 232 ms
8512 both are faster than what I get before. |
@dcoudert |
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.
I agree that it's faster than before. Thanks.
LGTM.
sagemathgh-40364: Improve 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". --> Improve the implementation of PNC algorithm. See comments in sagemath#40284. ### 📝 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. - [x] 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#40284 URL: sagemath#40364 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40364: Improve 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". --> Improve the implementation of PNC algorithm. See comments in sagemath#40284. ### 📝 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. - [x] 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#40284 URL: sagemath#40364 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40364: Improve 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". --> Improve the implementation of PNC algorithm. See comments in sagemath#40284. ### 📝 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. - [x] 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#40284 URL: sagemath#40364 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40364: Improve 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". --> Improve the implementation of PNC algorithm. See comments in sagemath#40284. ### 📝 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. - [x] 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#40284 URL: sagemath#40364 Reported by: Yuta Inoue Reviewer(s): David Coudert
sagemathgh-40364: Improve 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". --> Improve the implementation of PNC algorithm. See comments in sagemath#40284. ### 📝 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. - [x] 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#40284 URL: sagemath#40364 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-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-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-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-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
Improve the implementation of PNC algorithm.
See comments in #40284.
📝 Checklist
⌛ Dependencies
#40284