Skip to content

Commit 9e1018a

Browse files
committed
comparability.pyx
1 parent 2f102ea commit 9e1018a

File tree

2 files changed

+45
-52
lines changed

2 files changed

+45
-52
lines changed

src/sage/graphs/bliss.pyx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ cdef canonical_form_from_edge_list(int Vnr, list Vout, list Vin, int Lnr=1, list
375375

376376
if certificate:
377377
return new_edges, relabel
378-
else:
379-
return new_edges
378+
return new_edges
380379

381380

382381
cpdef canonical_form(G, partition=None, return_graph=False, use_edge_labels=True, certificate=False):

src/sage/graphs/comparability.pyx

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,13 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
306306
# added twice.
307307
return True, sorted(set(edges))
308308
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
318316
319317
320318
def greedy_is_comparability_with_certificate(g, certificate=False):
@@ -361,8 +359,7 @@ def greedy_is_comparability_with_certificate(g, certificate=False):
361359
if not isit:
362360
if certificate:
363361
return False, certif
364-
else:
365-
return False
362+
return False
366363
367364
elif not certificate:
368365
return True
@@ -552,8 +549,7 @@ def is_comparability(g, algorithm="greedy", certificate=False, check=True,
552549
if certificate:
553550
from sage.graphs.digraph import DiGraph
554551
return True, DiGraph(g)
555-
else:
556-
return True
552+
return True
557553
558554
if algorithm == "greedy":
559555
comparability_test = greedy_is_comparability_with_certificate(g, certificate=certificate)
@@ -677,46 +673,44 @@ def is_permutation(g, algorithm="greedy", certificate=False, check=True,
677673
....: break
678674

679675
"""
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
717678
return (is_comparability(g, algorithm=algorithm, solver=solver, verbose=verbose) and
718679
is_comparability(g.complement(), algorithm=algorithm, solver=solver, verbose=verbose))
719680
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+
720714
721715
def is_transitive(g, certificate=False):
722716
r"""

0 commit comments

Comments
 (0)