Skip to content

Commit bab1966

Browse files
committed
gh #35300: fix radius and diameter for digraphs with non-comparable vertices
1 parent c00e6c2 commit bab1966

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/sage/graphs/digraph.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ def eccentricity(self, v=None, by_weight=False, algorithm=None,
22492249
if with_labels:
22502250
return dict(zip(v, eccentricity(self, algorithm=algo, vertex_list=v)))
22512251
else:
2252-
return eccentricity(self, algorithm=algo)
2252+
return eccentricity(self, algorithm=algo, vertex_list=v)
22532253

22542254
if algorithm in ['Floyd-Warshall-Python', 'Floyd-Warshall-Cython', 'Johnson_Boost']:
22552255
dist_dict = self.shortest_path_all_pairs(by_weight=by_weight, algorithm=algorithm,
@@ -2343,11 +2343,17 @@ def radius(self, by_weight=False, algorithm=None, weight_function=None,
23432343
Traceback (most recent call last):
23442344
...
23452345
ValueError: radius is not defined for the empty DiGraph
2346+
2347+
Check that :trac:`35300` is fixed::
2348+
2349+
sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
2350+
sage: H.radius()
2351+
1
23462352
"""
23472353
if not self.order():
23482354
raise ValueError("radius is not defined for the empty DiGraph")
23492355

2350-
return min(self.eccentricity(v=None, by_weight=by_weight,
2356+
return min(self.eccentricity(v=list(self), by_weight=by_weight,
23512357
weight_function=weight_function,
23522358
check_weight=check_weight,
23532359
algorithm=algorithm))
@@ -2476,6 +2482,15 @@ def diameter(self, by_weight=False, algorithm=None, weight_function=None,
24762482
3
24772483
sage: G.diameter(algorithm='DiFUB', by_weight=True)
24782484
3.0
2485+
2486+
Check that :trac:`35300` is fixed::
2487+
2488+
sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
2489+
sage: H.diameter()
2490+
+Infinity
2491+
sage: H.add_edge('John', 42)
2492+
sage: H.diameter()
2493+
1
24792494
"""
24802495
if not self.order():
24812496
raise ValueError("diameter is not defined for the empty DiGraph")
@@ -2507,7 +2522,7 @@ def diameter(self, by_weight=False, algorithm=None, weight_function=None,
25072522
from sage.graphs.distances_all_pairs import diameter
25082523
return diameter(self, algorithm='standard')
25092524

2510-
return max(self.eccentricity(v=None, by_weight=by_weight,
2525+
return max(self.eccentricity(v=list(self), by_weight=by_weight,
25112526
weight_function=weight_function,
25122527
check_weight=False,
25132528
algorithm=algorithm))

0 commit comments

Comments
 (0)