Skip to content

Commit f09c6e7

Browse files
committed
fix format and move code
1 parent 8f3188b commit f09c6e7

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

src/sage/graphs/connectivity.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ def blocks_and_cuts_tree(G):
814814
return g
815815

816816
def biconnected_components_subgraphs(G):
817-
"""
817+
r"""
818818
Return a list of biconnected components as graph objects.
819819
820820
A biconnected component is a maximal subgraph that is biconnected, i.e.,

src/sage/graphs/cycle_enumeration.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ def _all_simple_cycles_iterator_edge(self, edge, max_length=None,
318318
for component in components:
319319
if component.has_edge(edge):
320320
h = component
321-
if h is None:
321+
break
322+
else:
322323
# edge connects two strongly connected components, so
323324
# no simple cycle starting with edge exists.
324325
return
@@ -548,32 +549,47 @@ def all_cycles_iterator(self, starting_vertices=None, simple=False,
548549
"""
549550
if starting_vertices is None:
550551
starting_vertices = self
551-
552-
if self.is_directed():
553-
# Since a cycle is always included in a given strongly connected
554-
# component, we may remove edges from the graph
555-
sccs = self.strongly_connected_components()
556-
d = {}
557-
for id, component in enumerate(sccs):
558-
for v in component:
559-
d[v] = id
560-
h = copy(self)
561-
h.delete_edges((u, v) for u, v in h.edge_iterator(labels=False) if d[u] != d[v])
562-
else:
563-
h = copy(self)
552+
553+
if algorithm == 'A' and not self.is_directed():
554+
raise ValueError("The algorithm 'A' is available only for directed graphs.")
555+
if algorithm == 'B' and not simple:
556+
raise ValueError("The algorithm 'B' is available only when simple=True.")
557+
558+
# if self.is_directed():
559+
# # Since a cycle is always included in a given strongly connected
560+
# # component, we may remove edges from the graph
561+
# sccs = self.strongly_connected_components()
562+
# d = {}
563+
# for id, component in enumerate(sccs):
564+
# for v in component:
565+
# d[v] = id
566+
# h = copy(self)
567+
# h.delete_edges((u, v) for u, v in h.edge_iterator(labels=False) if d[u] != d[v])
568+
# else:
569+
# h = copy(self)
564570

565571
by_weight, weight_function = self._get_weight_function(by_weight=by_weight,
566572
weight_function=weight_function,
567573
check_weight=check_weight)
568574

569575
if by_weight:
570-
for e in h.edge_iterator():
576+
for e in self.edge_iterator():
571577
if weight_function(e) < 0:
572578
raise ValueError("negative weight is not allowed")
573579

574580
if algorithm == 'A':
575-
if not self.is_directed():
576-
raise ValueError("The algorithm 'A' is available only for directed graphs.")
581+
if self.is_directed():
582+
# Since a cycle is always included in a given strongly connected
583+
# component, we may remove edges from the graph
584+
sccs = self.strongly_connected_components()
585+
d = {}
586+
for id, component in enumerate(sccs):
587+
for v in component:
588+
d[v] = id
589+
h = copy(self)
590+
h.delete_edges((u, v) for u, v in h.edge_iterator(labels=False) if d[u] != d[v])
591+
else:
592+
h = self
577593
# We create one cycles iterator per vertex. This is necessary if we
578594
# want to iterate over cycles with increasing length.
579595
def cycle_iter(v):
@@ -591,8 +607,6 @@ def cycle_iter(v):
591607

592608
iterators = {v: cycle_iter(v) for v in starting_vertices}
593609
elif algorithm == 'B':
594-
if not simple:
595-
raise ValueError("The algorithm 'B' is available only when simple=True.")
596610
def simple_cycle_iter(hh, e):
597611
return hh._all_simple_cycles_iterator_edge(e,
598612
max_length=max_length,
@@ -601,14 +615,14 @@ def simple_cycle_iter(hh, e):
601615
by_weight=by_weight,
602616
check_weight=check_weight,
603617
report_weight=True)
604-
if h.is_directed():
618+
if self.is_directed():
605619
def decompose(hh):
606620
return hh.strongly_connected_components_subgraphs()
607621
else:
608622
def decompose(hh):
609623
return hh.biconnected_components_subgraphs()
610624

611-
components = decompose(h)
625+
components = decompose(self)
612626
iterators = dict()
613627
while components:
614628
hh = components.pop()

0 commit comments

Comments
 (0)