Skip to content

Commit c78cd54

Browse files
author
Release Manager
committed
gh-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 #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 #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, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> #40364 URL: #40510 Reported by: Yuta Inoue Reviewer(s): David Coudert
2 parents 2732ffd + dfa5625 commit c78cd54

File tree

2 files changed

+410
-562
lines changed

2 files changed

+410
-562
lines changed

src/sage/graphs/cycle_enumeration.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ def _all_simple_cycles_iterator_edge(self, edge, max_length=None,
265265
sage: g = graphs.Grid2dGraph(2, 5).to_directed()
266266
sage: it = g._all_simple_cycles_iterator_edge(((0, 0), (0, 1), None), report_weight=True)
267267
sage: for i in range(5): print(next(it))
268-
(2, [(0, 0), (0, 1), (0, 0)])
269-
(4, [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
270-
(6, [(0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (0, 0)])
271-
(8, [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (1, 2), (1, 1), (1, 0), (0, 0)])
272-
(10, [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0), (0, 0)])
268+
(2.0, [(0, 0), (0, 1), (0, 0)])
269+
(4.0, [(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
270+
(6.0, [(0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (0, 0)])
271+
(8.0, [(0, 0), (0, 1), (0, 2), (0, 3), (1, 3), (1, 2), (1, 1), (1, 0), (0, 0)])
272+
(10.0, [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0), (0, 0)])
273273
274274
The function works for undirected graphs as well::
275275
@@ -841,12 +841,12 @@ def all_simple_cycles(self, starting_vertices=None, rooted=False,
841841
sage: cycles_B = g.all_simple_cycles(weight_function=lambda e:e[0]+e[1], by_weight=True,
842842
....: report_weight=True, algorithm='B')
843843
sage: cycles_B
844-
[(2, [0, 1, 0]), (4, [0, 2, 0]), (6, [0, 1, 2, 0]), (6, [0, 2, 1, 0]),
845-
(6, [0, 3, 0]), (6, [1, 2, 1]), (8, [0, 1, 3, 0]), (8, [0, 3, 1, 0]),
846-
(8, [1, 3, 1]), (10, [0, 2, 3, 0]), (10, [0, 3, 2, 0]), (10, [2, 3, 2]),
847-
(12, [0, 1, 3, 2, 0]), (12, [0, 1, 2, 3, 0]), (12, [0, 2, 3, 1, 0]),
848-
(12, [0, 2, 1, 3, 0]), (12, [0, 3, 2, 1, 0]), (12, [0, 3, 1, 2, 0]),
849-
(12, [1, 2, 3, 1]), (12, [1, 3, 2, 1])]
844+
[(2.0, [0, 1, 0]), (4.0, [0, 2, 0]), (6.0, [0, 1, 2, 0]), (6.0, [0, 2, 1, 0]),
845+
(6.0, [0, 3, 0]), (6.0, [1, 2, 1]), (8.0, [0, 1, 3, 0]), (8.0, [0, 3, 1, 0]),
846+
(8.0, [1, 3, 1]), (10.0, [0, 2, 3, 0]), (10.0, [0, 3, 2, 0]), (10.0, [2, 3, 2]),
847+
(12.0, [0, 1, 3, 2, 0]), (12.0, [0, 1, 2, 3, 0]), (12.0, [0, 2, 3, 1, 0]),
848+
(12.0, [0, 2, 1, 3, 0]), (12.0, [0, 3, 2, 1, 0]), (12.0, [0, 3, 1, 2, 0]),
849+
(12.0, [1, 2, 3, 1]), (12.0, [1, 3, 2, 1])]
850850
sage: cycles.sort() == cycles_B.sort()
851851
True
852852

0 commit comments

Comments
 (0)