@@ -4891,17 +4891,18 @@ def independent_set_of_representatives(self, family, solver=None, verbose=0,
4891
4891
return repr
4892
4892
4893
4893
@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 ):
4895
4895
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.
4897
4897
4898
4898
We say that a graph `G` has a `H`-minor (or that it has a graph
4899
4899
isomorphic to `H` as a minor), if for all `h\in H`, there exist disjoint
4900
4900
sets `S_h \subseteq V(G)` such that once the vertices of each `S_h` have
4901
4901
been merged to create a new graph `G'`, this new graph contains `H` as a
4902
4902
subgraph.
4903
4903
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.
4905
4906
4906
4907
We say that a graph `G` has an induced `H`-minor (or that it has a
4907
4908
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
4930
4931
:meth:`MixedIntegerLinearProgram.get_values`.
4931
4932
4932
4933
- ``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.
4934
4935
4935
4936
OUTPUT:
4936
4937
@@ -5004,19 +5005,22 @@ def minor(self, H, solver=None, verbose=0, *, integrality_tolerance=1e-3, induce
5004
5005
5005
5006
TESTS::
5006
5007
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)])
5011
5010
sage: l = g.minor(h, induced=True)
5012
5011
Traceback (most recent call last):
5013
5012
...
5014
5013
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)])
5020
5024
sage: L = g.minor(h, induced=True)
5021
5025
sage: gg = g.subgraph(flatten(L.values(), max_level = 1))
5022
5026
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
5091
5095
# condition for induced subgraph ensures that if there
5092
5096
# doesnt exist an edge(h1, h2) in H then there should
5093
5097
# 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 )
5100
5103
5101
5104
p .set_objective (None )
5102
5105
0 commit comments