Skip to content

Commit 34d9c98

Browse files
committed
PR #35891: fix issues in the graphs module
1 parent 1311c29 commit 34d9c98

16 files changed

+28
-28
lines changed

src/sage/graphs/base/c_graph.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4819,7 +4819,7 @@ cdef class Search_iterator:
48194819
48204820
Immutable graphs (see :trac:`16019`)::
48214821
4822-
sage: DiGraph([[1,2]], immutable=True).connected_components()
4822+
sage: DiGraph([(1, 2)], immutable=True).connected_components(sort=True)
48234823
[[1, 2]]
48244824
48254825
"""

src/sage/graphs/bipartite_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ def _check_bipartition_for_add_edges(self, edges):
12091209
vertex_in_left[v] = False
12101210

12111211
# Map each vertex to the connected component it belongs to
1212-
vertex_to_component = {v: comp for comp in self.connected_components()
1212+
vertex_to_component = {v: comp for comp in self.connected_components(sort=False)
12131213
for v in comp}
12141214

12151215
for e in edges:

src/sage/graphs/comparability.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
257257
# Each vertex can partition its neighbors into equivalence classes
258258
equivalence_classes = {}
259259
for v in g:
260-
equivalence_classes[v] = g.subgraph(vertices=g.neighbors(v)).complement().connected_components()
260+
equivalence_classes[v] = g.subgraph(vertices=g.neighbors(v)).complement().connected_components(sort=False)
261261
262262
# We build a graph h with one vertex per (vertex of g + equivalence class)
263263
from sage.graphs.graph import Graph
@@ -288,7 +288,7 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
288288
if equivalence_class:
289289
290290
# Returning the largest equivalence class
291-
cc = sorted(h.connected_components(), key=len)[-1]
291+
cc = sorted(h.connected_components(sort=False), key=len)[-1]
292292
293293
edges = []
294294
for v, sid in cc:

src/sage/graphs/distances_all_pairs.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@ def antipodal_graph(G):
25722572

25732573
if not G.is_connected():
25742574
import itertools
2575-
CC = G.connected_components()
2575+
CC = G.connected_components(sort=False)
25762576
for c1, c2 in itertools.combinations(CC, 2):
25772577
A.add_edges(itertools.product(c1, c2))
25782578
return A

src/sage/graphs/generators/world_map.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def AfricaMap(continental=False, year=2018):
9595
G = Graph(common_border, format='dict_of_lists')
9696

9797
if continental:
98-
G = G.subgraph(G.connected_component_containing_vertex('Central Africa'))
98+
G = G.subgraph(G.connected_component_containing_vertex('Central Africa', sort=False))
9999
G.name(new="Continental Africa Map")
100100
else:
101101
G.add_vertices(no_land_border)
@@ -172,7 +172,7 @@ def EuropeMap(continental=False, year=2018):
172172
G = Graph(common_border, format='dict_of_lists')
173173

174174
if continental:
175-
G = G.subgraph(G.connected_component_containing_vertex('Austria'))
175+
G = G.subgraph(G.connected_component_containing_vertex('Austria', sort=False))
176176
G.name(new="Continental Europe Map")
177177
else:
178178
G.add_vertices(no_land_border)
@@ -308,7 +308,7 @@ def WorldMap():
308308
True
309309
sage: g.gps_coordinates["Bolivia"]
310310
[[17, 'S'], [65, 'W']]
311-
sage: sorted(g.connected_component_containing_vertex('Ireland'))
311+
sage: g.connected_component_containing_vertex('Ireland', sort=True)
312312
['Ireland', 'United Kingdom']
313313
314314
TESTS:

src/sage/graphs/generic_graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6527,7 +6527,7 @@ def num_faces(self, embedding=None):
65276527
else:
65286528
if self.is_planar():
65296529
# We use Euler's formula: V-E+F-C=1
6530-
C = len(self.connected_components())
6530+
C = self.connected_components_number()
65316531
return self.size() - self.order() + C + 1
65326532
else:
65336533
raise ValueError("no embedding is provided and the graph is not planar")
@@ -6734,7 +6734,7 @@ def steiner_tree(self, vertices, weighted=False, solver=None, verbose=0,
67346734

67356735
# Can the problem be solved ? Are all the vertices in the same
67366736
# connected component ?
6737-
cc = g.connected_component_containing_vertex(vertices[0])
6737+
cc = g.connected_component_containing_vertex(vertices[0], sort=False)
67386738
if any(v not in cc for v in vertices):
67396739
from sage.categories.sets_cat import EmptySetError
67406740
raise EmptySetError("the given vertices do not all belong to the "
@@ -14752,7 +14752,7 @@ def is_gallai_tree(self):
1475214752
a special vertex `-1` is a ''star-shaped'' Gallai tree::
1475314753

1475414754
sage: g = 8 * graphs.CompleteGraph(6)
14755-
sage: g.add_edges([(-1, c[0]) for c in g.connected_components()])
14755+
sage: g.add_edges([(-1, c[0]) for c in g.connected_components(sort=False)])
1475614756
sage: g.is_gallai_tree()
1475714757
True
1475814758

@@ -19367,7 +19367,7 @@ def transitive_reduction(self):
1936719367
return Graph(self.min_spanning_tree(weight_function=lambda e: 1))
1936819368
else:
1936919369
G = Graph(list(self))
19370-
for cc in self.connected_components():
19370+
for cc in self.connected_components(sort=False):
1937119371
if len(cc) > 1:
1937219372
edges = self.subgraph(cc).min_spanning_tree(weight_function=lambda e: 1)
1937319373
G.add_edges(edges)

src/sage/graphs/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8910,7 +8910,7 @@ def perfect_matchings(self, labels=False):
89108910
if not self:
89118911
yield []
89128912
return
8913-
if self.order() % 2 or any(len(cc) % 2 for cc in self.connected_components()):
8913+
if self.order() % 2 or any(len(cc) % 2 for cc in self.connected_components(sort=False)):
89148914
return
89158915

89168916
def rec(G):
@@ -9164,7 +9164,7 @@ def effective_resistance(self, i, j, *, base_ring=None):
91649164

91659165
self._scream_if_not_simple()
91669166
if not self.is_connected():
9167-
connected_i = self.connected_component_containing_vertex(i)
9167+
connected_i = self.connected_component_containing_vertex(i, sort=False)
91689168
if j in connected_i:
91699169
component = self.subgraph(connected_i)
91709170
return component.effective_resistance(i, j)

src/sage/graphs/graph_coloring.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def vertex_coloring(g, k=None, value_only=False, hex_colors=False, solver=None,
602602
# by the test of degeneracy (as previously).
603603
if not g.is_connected():
604604
if value_only:
605-
for component in g.connected_components():
605+
for component in g.connected_components(sort=False):
606606
tmp = vertex_coloring(g.subgraph(component), k=k,
607607
value_only=value_only,
608608
hex_colors=hex_colors,
@@ -612,7 +612,7 @@ def vertex_coloring(g, k=None, value_only=False, hex_colors=False, solver=None,
612612
return False
613613
return True
614614
colorings = []
615-
for component in g.connected_components():
615+
for component in g.connected_components(sort=False):
616616
tmp = vertex_coloring(g.subgraph(component), k=k,
617617
value_only=value_only,
618618
hex_colors=False,

src/sage/graphs/graph_decompositions/clique_separators.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def atoms_and_clique_separators(G, tree=False, rooted_tree=False, separators=Fal
423423
if not G.is_connected():
424424
from sage.graphs.graph import Graph
425425

426-
for cc in G.connected_components():
426+
for cc in G.connected_components(sort=False):
427427
g = Graph([cc, G.edge_boundary(cc, cc, False, False)],
428428
format='vertices_and_edges',
429429
loops=True, multiedges=True)

src/sage/graphs/graph_decompositions/graph_products.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def is_cartesian_product(g, certificate=False, relabeling=False):
309309

310310
# Gathering the connected components, relabeling the vertices on-the-fly
311311
edges = [[(int_to_vertex[u], int_to_vertex[v]) for u, v in cc]
312-
for cc in h.connected_components()]
312+
for cc in h.connected_components(sort=False)]
313313

314314
# Only one connected component ?
315315
if len(edges) == 1:
@@ -320,7 +320,7 @@ def is_cartesian_product(g, certificate=False, relabeling=False):
320320
for cc in edges:
321321
tmp = Graph()
322322
tmp.add_edges(cc)
323-
factors.append(tmp.subgraph(vertices=tmp.connected_components()[0]))
323+
factors.append(tmp.subgraph(vertices=tmp.connected_components(sort=False)[0]))
324324

325325
# Computing the product of these graphs
326326
answer = factors[0]

0 commit comments

Comments
 (0)