Skip to content

Commit 4b4a3e3

Browse files
committed
Merge branch 'report_weight_in_yen' into enum_cycle_undirected
2 parents 9057ffd + f2ef353 commit 4b4a3e3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/sage/graphs/path_enumeration.pyx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,12 @@ def yen_k_shortest_simple_paths(self, source, target, weight_function=None,
735735
[1, 6, 9, 3, 4, 5],
736736
[1, 6, 9, 11, 10, 5]]
737737
738+
When ``s == t`` and ``report_edge == True`` and ``report_weight == True`` (:issue:`40247`)::
739+
740+
sage: g = DiGraph([(1, 2)])
741+
sage: list(yen_k_shortest_simple_paths(g, 1, 1, report_edges=True, report_weight=True))
742+
[(0, [])]
743+
738744
No path between two vertices exists::
739745
740746
sage: g = Graph(2)
@@ -747,12 +753,8 @@ def yen_k_shortest_simple_paths(self, source, target, weight_function=None,
747753
raise ValueError("vertex '{}' is not in the graph".format(target))
748754

749755
if source == target:
750-
if report_edges:
751-
yield []
752-
elif report_weight:
753-
yield (0, [source])
754-
else:
755-
yield [source]
756+
P = [] if report_edges else [source]
757+
yield (0, P) if report_weight else P
756758
return
757759

758760
if self.has_loops() or self.allows_multiple_edges():

0 commit comments

Comments
 (0)