@@ -306,15 +306,13 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
306
306
# added twice.
307
307
return True, sorted( set( edges))
308
308
309
- else:
310
- return True
311
- else:
312
- if no_certificate:
313
- certif. append( certif[0 ])
314
- cycle = [v for v, _ in certif ]
315
- return False, cycle
316
- else:
317
- return False
309
+ return True
310
+
311
+ if no_certificate:
312
+ certif. append( certif[0 ])
313
+ cycle = [v for v, _ in certif ]
314
+ return False, cycle
315
+ return False
318
316
319
317
320
318
def greedy_is_comparability_with_certificate( g, certificate=False) :
@@ -361,8 +359,7 @@ def greedy_is_comparability_with_certificate(g, certificate=False):
361
359
if not isit:
362
360
if certificate:
363
361
return False, certif
364
- else:
365
- return False
362
+ return False
366
363
367
364
elif not certificate:
368
365
return True
@@ -552,8 +549,7 @@ def is_comparability(g, algorithm="greedy", certificate=False, check=True,
552
549
if certificate:
553
550
from sage.graphs.digraph import DiGraph
554
551
return True, DiGraph(g)
555
- else:
556
- return True
552
+ return True
557
553
558
554
if algorithm == "greedy":
559
555
comparability_test = greedy_is_comparability_with_certificate(g, certificate=certificate)
@@ -677,46 +673,44 @@ def is_permutation(g, algorithm="greedy", certificate=False, check=True,
677
673
....: break
678
674
679
675
"""
680
- if certificate:
681
-
682
- # First poset, we stop if it fails
683
- isit, certif = is_comparability(g, algorithm=algorithm, certificate=True,
684
- solver=solver, verbose=verbose)
685
- if not isit:
686
- return False, certif
687
-
688
- # Second poset
689
- isit, co_certif = is_comparability(g.complement(), algorithm=algorithm, certificate=True,
690
- solver=solver, verbose=verbose)
691
- if not isit:
692
- return False, co_certif
693
-
694
- # Building the two orderings
695
- tmp = list(co_certif.edges(labels=False, sort=False))
696
- for u, v in certif.edge_iterator(labels=False):
697
- co_certif.add_edge(v, u)
698
- certif.add_edges(tmp)
699
-
700
- ordering = certif.topological_sort()
701
- co_ordering = co_certif.topological_sort()
702
-
703
- # Try to build the Permutation graph from the permutations, just to make
704
- # sure nothing weird happened !
705
- if check:
706
- from sage.graphs.graph_generators import GraphGenerators
707
- pg = GraphGenerators().PermutationGraph(ordering, co_ordering)
708
- if not pg.is_isomorphic(g):
709
- raise ValueError("There is a mistake somewhere ! It looks like "
710
- "the Permutation Graph model computed does "
711
- "not match the input graph !")
712
-
713
- return True, (ordering, co_ordering)
714
-
715
- # No certificate... A piece of cake
716
- else:
676
+ if not certificate:
677
+ # No certificate... A piece of cake
717
678
return (is_comparability(g, algorithm=algorithm, solver=solver, verbose=verbose) and
718
679
is_comparability(g.complement(), algorithm=algorithm, solver=solver, verbose=verbose))
719
680
681
+ # First poset, we stop if it fails
682
+ isit, certif = is_comparability(g, algorithm=algorithm, certificate=True,
683
+ solver=solver, verbose=verbose)
684
+ if not isit:
685
+ return False, certif
686
+
687
+ # Second poset
688
+ isit, co_certif = is_comparability(g.complement(), algorithm=algorithm, certificate=True,
689
+ solver=solver, verbose=verbose)
690
+ if not isit:
691
+ return False, co_certif
692
+
693
+ # Building the two orderings
694
+ tmp = list(co_certif.edges(labels=False, sort=False))
695
+ for u, v in certif.edge_iterator(labels=False):
696
+ co_certif.add_edge(v, u)
697
+ certif.add_edges(tmp)
698
+
699
+ ordering = certif.topological_sort()
700
+ co_ordering = co_certif.topological_sort()
701
+
702
+ # Try to build the Permutation graph from the permutations, just to make
703
+ # sure nothing weird happened !
704
+ if check:
705
+ from sage.graphs.graph_generators import GraphGenerators
706
+ pg = GraphGenerators().PermutationGraph(ordering, co_ordering)
707
+ if not pg.is_isomorphic(g):
708
+ raise ValueError("There is a mistake somewhere ! It looks like "
709
+ "the Permutation Graph model computed does "
710
+ "not match the input graph !")
711
+
712
+ return True, (ordering, co_ordering)
713
+
720
714
721
715
def is_transitive(g, certificate=False):
722
716
r"""
0 commit comments