@@ -318,7 +318,8 @@ def _all_simple_cycles_iterator_edge(self, edge, max_length=None,
318
318
for component in components :
319
319
if component .has_edge (edge ):
320
320
h = component
321
- if h is None :
321
+ break
322
+ else :
322
323
# edge connects two strongly connected components, so
323
324
# no simple cycle starting with edge exists.
324
325
return
@@ -548,32 +549,47 @@ def all_cycles_iterator(self, starting_vertices=None, simple=False,
548
549
"""
549
550
if starting_vertices is None :
550
551
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)
564
570
565
571
by_weight , weight_function = self ._get_weight_function (by_weight = by_weight ,
566
572
weight_function = weight_function ,
567
573
check_weight = check_weight )
568
574
569
575
if by_weight :
570
- for e in h .edge_iterator ():
576
+ for e in self .edge_iterator ():
571
577
if weight_function (e ) < 0 :
572
578
raise ValueError ("negative weight is not allowed" )
573
579
574
580
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
577
593
# We create one cycles iterator per vertex. This is necessary if we
578
594
# want to iterate over cycles with increasing length.
579
595
def cycle_iter (v ):
@@ -591,8 +607,6 @@ def cycle_iter(v):
591
607
592
608
iterators = {v : cycle_iter (v ) for v in starting_vertices }
593
609
elif algorithm == 'B' :
594
- if not simple :
595
- raise ValueError ("The algorithm 'B' is available only when simple=True." )
596
610
def simple_cycle_iter (hh , e ):
597
611
return hh ._all_simple_cycles_iterator_edge (e ,
598
612
max_length = max_length ,
@@ -601,14 +615,14 @@ def simple_cycle_iter(hh, e):
601
615
by_weight = by_weight ,
602
616
check_weight = check_weight ,
603
617
report_weight = True )
604
- if h .is_directed ():
618
+ if self .is_directed ():
605
619
def decompose (hh ):
606
620
return hh .strongly_connected_components_subgraphs ()
607
621
else :
608
622
def decompose (hh ):
609
623
return hh .biconnected_components_subgraphs ()
610
624
611
- components = decompose (h )
625
+ components = decompose (self )
612
626
iterators = dict ()
613
627
while components :
614
628
hh = components .pop ()
0 commit comments