Skip to content

Commit 133a345

Browse files
author
Release Manager
committed
gh-35533: Fix bug in graph.maximum_average_degree Fixes #35532. ### 📚 Description Fix corner cases (empty graph, graph without edges) in `graph.maximum_average_degree`. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [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. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35533 Reported by: David Coudert Reviewer(s): Travis Scrimshaw
2 parents 3c2ba82 + dcddb70 commit 133a345

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/sage/graphs/graph.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,9 +4673,30 @@ def maximum_average_degree(self, value_only=True, solver=None, verbose=0):
46734673
sage: mad_g = g.maximum_average_degree(value_only=False)
46744674
sage: g.is_isomorphic(mad_g)
46754675
True
4676+
4677+
TESTS:
4678+
4679+
Check corner cases::
4680+
4681+
sage: Graph().maximum_average_degree(value_only=True)
4682+
0
4683+
sage: Graph().maximum_average_degree(value_only=False)
4684+
Graph on 0 vertices
4685+
sage: Graph(1).maximum_average_degree(value_only=True)
4686+
0
4687+
sage: Graph(1).maximum_average_degree(value_only=False)
4688+
Graph on 1 vertex
4689+
sage: Graph(2).maximum_average_degree(value_only=True)
4690+
0
4691+
sage: Graph(2).maximum_average_degree(value_only=False)
4692+
Graph on 1 vertex
46764693
"""
46774694
self._scream_if_not_simple()
46784695
g = self
4696+
if not g:
4697+
return ZZ.zero() if value_only else g.parent()()
4698+
elif not g.size():
4699+
return ZZ.zero() if value_only else g.parent()([[next(g.vertex_iterator())], []])
46794700
from sage.numerical.mip import MixedIntegerLinearProgram
46804701

46814702
p = MixedIntegerLinearProgram(maximization=True, solver=solver)

0 commit comments

Comments
 (0)