Skip to content

Commit 764c2af

Browse files
Saatvik RaosaatvikraoIITGN
authored andcommitted
minor fixes in function and tests
1 parent 83a3007 commit 764c2af

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/sage/graphs/graph.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4891,17 +4891,18 @@ def independent_set_of_representatives(self, family, solver=None, verbose=0,
48914891
return repr
48924892

48934893
@doc_index("Algorithmically hard stuff")
4894-
def minor(self, H, solver=None, verbose=0, *, integrality_tolerance=1e-3, induced=False):
4894+
def minor(self, H, solver=None, verbose=0, induced=False, *, integrality_tolerance=1e-3):
48954895
r"""
4896-
Return the vertices of a minor isomorphic to `H` in the current graph for induced=False
4896+
Return the vertices of a minor isomorphic to `H` in the current graph.
48974897
48984898
We say that a graph `G` has a `H`-minor (or that it has a graph
48994899
isomorphic to `H` as a minor), if for all `h\in H`, there exist disjoint
49004900
sets `S_h \subseteq V(G)` such that once the vertices of each `S_h` have
49014901
been merged to create a new graph `G'`, this new graph contains `H` as a
49024902
subgraph.
49034903
4904-
Returns an induced minor isomorphic to `H` if it exists for induced=True
4904+
When parameter ``induced`` is ``True``, this method returns an induced minor
4905+
isomorphic to `H`, if it exists.
49054906
49064907
We say that a graph `G` has an induced `H`-minor (or that it has a
49074908
graph isomorphic to `H` as an induced minor), if `H` can be obtained
@@ -4930,7 +4931,7 @@ def minor(self, H, solver=None, verbose=0, *, integrality_tolerance=1e-3, induce
49304931
:meth:`MixedIntegerLinearProgram.get_values`.
49314932
49324933
- ``induced`` -- boolean (default: ``False``); if ``True``, returns an
4933-
induced minor isomorphic to `H` if it exists, and ``None`` otherwise.
4934+
induced minor isomorphic to `H` if it exists, and ``ValueError`` otherwise.
49344935
49354936
OUTPUT:
49364937
@@ -5004,19 +5005,22 @@ def minor(self, H, solver=None, verbose=0, *, integrality_tolerance=1e-3, induce
50045005
50055006
TESTS::
50065007
5007-
sage: g = Graph()
5008-
sage: g.add_edges([(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (3, 5), (4, 5), (6, 5)])
5009-
sage: h = Graph()
5010-
sage: h.add_edges([(9, 10), (9, 11), (9, 12), (9, 13)])
5008+
sage: g = Graph([(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (3, 5), (4, 5), (6, 5)])
5009+
sage: h = Graph([(9, 10), (9, 11), (9, 12), (9, 13)])
50115010
sage: l = g.minor(h, induced=True)
50125011
Traceback (most recent call last):
50135012
...
50145013
ValueError: This graph has no induced minor isomorphic to H !
5015-
5016-
sage: g = Graph()
5017-
sage: g.add_edges([(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (3, 5), (4, 5), (6, 5)])
5018-
sage: h = Graph()
5019-
sage: h.add_edges([(7, 8), (8, 9), (9, 10), (10, 11)])
5014+
5015+
sage: # induced minor does not exist, but minor does
5016+
sage: g = Graph([(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (3, 5), (4, 5), (6, 5)])
5017+
sage: h = Graph([(9, 10), (9, 11), (9, 12), (9, 13)])
5018+
sage: l = g.minor(h, induced=False)
5019+
sage: print("minor exists")
5020+
minor exists
5021+
5022+
sage: g = Graph([(0, 1), (0, 2), (1, 2), (2, 3), (3, 4), (3, 5), (4, 5), (6, 5)])
5023+
sage: h = Graph([(7, 8), (8, 9), (9, 10), (10, 11)])
50205024
sage: L = g.minor(h, induced=True)
50215025
sage: gg = g.subgraph(flatten(L.values(), max_level = 1))
50225026
sage: _ = [gg.merge_vertices(l) for l in L.values() if len(l)>1]
@@ -5091,12 +5095,11 @@ def minor(self, H, solver=None, verbose=0, *, integrality_tolerance=1e-3, induce
50915095
# condition for induced subgraph ensures that if there
50925096
# doesnt exist an edge(h1, h2) in H then there should
50935097
# not be an edge between representative sets of h1 and h2 in G
5094-
if (induced):
5095-
for h1 in H:
5096-
for h2 in H:
5097-
if not h1 == h2 and not H.has_edge(h1, h2):
5098-
for v1, v2 in self.edge_iterator(labels=None):
5099-
p.add_constraint(rs[h1, v1] + rs[h2, v2], max=1)
5098+
if induced:
5099+
for h1, h2 in H.complement().edge_iterator(labels=False):
5100+
for v1, v2 in self.edge_iterator(labels=False):
5101+
p.add_constraint(rs[h1, v1] + rs[h2, v2], max=1)
5102+
p.add_constraint(rs[h2, v1] + rs[h1, v2], max=1)
51005103

51015104
p.set_objective(None)
51025105

0 commit comments

Comments
 (0)