Skip to content

Commit e8362fd

Browse files
committed
report weight if s=t in yen_k_shortest_simple_paths
1 parent 9352a32 commit e8362fd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/sage/graphs/path_enumeration.pyx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,19 +734,29 @@ def yen_k_shortest_simple_paths(self, source, target, weight_function=None,
734734
[1, 6, 9, 10, 5],
735735
[1, 6, 9, 3, 4, 5],
736736
[1, 6, 9, 11, 10, 5]]
737+
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, [])]
737743
"""
738744
if source not in self:
739745
raise ValueError("vertex '{}' is not in the graph".format(source))
740746
if target not in self:
741747
raise ValueError("vertex '{}' is not in the graph".format(target))
742748

743749
if source == target:
744-
if report_edges:
745-
yield []
746-
elif report_weight:
747-
yield (0, [source])
750+
if report_weight:
751+
if report_edges:
752+
yield (0, [])
753+
else:
754+
yield (0, [source])
748755
else:
749-
yield [source]
756+
if report_edges:
757+
yield []
758+
else:
759+
yield [source]
750760
return
751761

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

0 commit comments

Comments
 (0)