Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in graph.maximum_average_degree #35533

Merged
merged 2 commits into from
Apr 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/sage/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4673,9 +4673,30 @@ def maximum_average_degree(self, value_only=True, solver=None, verbose=0):
sage: mad_g = g.maximum_average_degree(value_only=False)
sage: g.is_isomorphic(mad_g)
True

TESTS:

Check corner cases::

sage: Graph().maximum_average_degree(value_only=True)
0
sage: Graph().maximum_average_degree(value_only=False)
Graph on 0 vertices
sage: Graph(1).maximum_average_degree(value_only=True)
0
sage: Graph(1).maximum_average_degree(value_only=False)
Graph on 1 vertex
sage: Graph(2).maximum_average_degree(value_only=True)
0
sage: Graph(2).maximum_average_degree(value_only=False)
Graph on 1 vertex
"""
self._scream_if_not_simple()
g = self
if not g:
return ZZ.zero() if value_only else g.parent()()
elif not g.size():
return ZZ.zero() if value_only else g.parent()([[next(g.vertex_iterator())], []])
from sage.numerical.mip import MixedIntegerLinearProgram

p = MixedIntegerLinearProgram(maximization=True, solver=solver)
Expand Down