-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
base: develop
Are you sure you want to change the base?
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.
📝 Checklist
⌛ Dependencies
#40364