Skip to content

Commit ad0ea73

Browse files
author
Release Manager
committed
gh-35310: Fix radius and diameter for digraphs with non-comparable vertices
Fixes #35300. ### 📚 Description We specify an ordering of the vertices in the call to `eccentricity`. This way we fix both `radius` and `diameter`. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35310 Reported by: David Coudert Reviewer(s): Frédéric Chapoton
2 parents 85da6cc + bab1966 commit ad0ea73

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=c9dfa61ff70a2dceec85ad01fc37ee42232402c0
3-
md5=7479fb53c1b9fd56aea37f83a34cdac3
4-
cksum=3525422540
2+
sha1=a2e3104800baa46c2b8a8f85d7c27c4e46f8de3d
3+
md5=948e0a3542ef1e0a42dd275d183c5478
4+
cksum=1690902157
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4452928a1a41758883e2f0e3a445b015dfa0e593
1+
4f29240074c53ae1e439b4a02b1be86b2e80aa68

src/sage/graphs/digraph.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,7 +2259,7 @@ def eccentricity(self, v=None, by_weight=False, algorithm=None,
22592259
if with_labels:
22602260
return dict(zip(v, eccentricity(self, algorithm=algo, vertex_list=v)))
22612261
else:
2262-
return eccentricity(self, algorithm=algo)
2262+
return eccentricity(self, algorithm=algo, vertex_list=v)
22632263

22642264
if algorithm in ['Floyd-Warshall-Python', 'Floyd-Warshall-Cython', 'Johnson_Boost']:
22652265
dist_dict = self.shortest_path_all_pairs(by_weight=by_weight, algorithm=algorithm,
@@ -2353,11 +2353,17 @@ def radius(self, by_weight=False, algorithm=None, weight_function=None,
23532353
Traceback (most recent call last):
23542354
...
23552355
ValueError: radius is not defined for the empty DiGraph
2356+
2357+
Check that :trac:`35300` is fixed::
2358+
2359+
sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
2360+
sage: H.radius()
2361+
1
23562362
"""
23572363
if not self.order():
23582364
raise ValueError("radius is not defined for the empty DiGraph")
23592365

2360-
return min(self.eccentricity(v=None, by_weight=by_weight,
2366+
return min(self.eccentricity(v=list(self), by_weight=by_weight,
23612367
weight_function=weight_function,
23622368
check_weight=check_weight,
23632369
algorithm=algorithm))
@@ -2486,6 +2492,15 @@ def diameter(self, by_weight=False, algorithm=None, weight_function=None,
24862492
3
24872493
sage: G.diameter(algorithm='DiFUB', by_weight=True)
24882494
3.0
2495+
2496+
Check that :trac:`35300` is fixed::
2497+
2498+
sage: H = DiGraph([[42, 'John'], [(42, 'John')]])
2499+
sage: H.diameter()
2500+
+Infinity
2501+
sage: H.add_edge('John', 42)
2502+
sage: H.diameter()
2503+
1
24892504
"""
24902505
if not self.order():
24912506
raise ValueError("diameter is not defined for the empty DiGraph")
@@ -2517,7 +2532,7 @@ def diameter(self, by_weight=False, algorithm=None, weight_function=None,
25172532
from sage.graphs.distances_all_pairs import diameter
25182533
return diameter(self, algorithm='standard')
25192534

2520-
return max(self.eccentricity(v=None, by_weight=by_weight,
2535+
return max(self.eccentricity(v=list(self), by_weight=by_weight,
25212536
weight_function=weight_function,
25222537
check_weight=False,
25232538
algorithm=algorithm))

0 commit comments

Comments
 (0)