passagemath-graphs 10.5.10__cp39-cp39-macosx_14_0_arm64.whl → 10.5.43__cp39-cp39-macosx_14_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {passagemath_graphs-10.5.10.dist-info → passagemath_graphs-10.5.43.dist-info}/METADATA +126 -30
- passagemath_graphs-10.5.43.dist-info/RECORD +256 -0
- {passagemath_graphs-10.5.10.dist-info → passagemath_graphs-10.5.43.dist-info}/WHEEL +2 -1
- passagemath_graphs.dylibs/libgmp.10.dylib +0 -0
- sage/all__sagemath_graphs.py +5 -0
- sage/combinat/abstract_tree.py +1 -1
- sage/combinat/binary_tree.py +1 -1
- sage/combinat/cluster_algebra_quiver/all.py +1 -1
- sage/combinat/cluster_algebra_quiver/cluster_seed.py +28 -24
- sage/combinat/cluster_algebra_quiver/interact.py +4 -0
- sage/combinat/designs/MOLS_handbook_data.py +5 -5
- sage/combinat/designs/bibd.py +10 -9
- sage/combinat/designs/covering_array.py +3 -3
- sage/combinat/designs/covering_design.py +2 -1
- sage/combinat/designs/database.py +11 -10
- sage/combinat/designs/designs_pyx.cpython-39-darwin.so +0 -0
- sage/combinat/designs/designs_pyx.pyx +13 -45
- sage/combinat/designs/difference_family.py +6 -6
- sage/combinat/designs/difference_matrices.py +1 -1
- sage/combinat/designs/evenly_distributed_sets.cpython-39-darwin.so +0 -0
- sage/combinat/designs/evenly_distributed_sets.pyx +15 -22
- sage/combinat/designs/ext_rep.py +9 -14
- sage/combinat/designs/gen_quadrangles_with_spread.cpython-39-darwin.so +0 -0
- sage/combinat/designs/gen_quadrangles_with_spread.pyx +1 -1
- sage/combinat/designs/group_divisible_designs.py +1 -1
- sage/combinat/designs/incidence_structures.py +8 -8
- sage/combinat/designs/latin_squares.py +1 -1
- sage/combinat/designs/orthogonal_arrays_build_recursive.py +8 -7
- sage/combinat/designs/orthogonal_arrays_find_recursive.cpython-39-darwin.so +0 -0
- sage/combinat/designs/resolvable_bibd.py +1 -1
- sage/combinat/designs/steiner_quadruple_systems.py +1 -1
- sage/combinat/designs/subhypergraph_search.cpython-39-darwin.so +0 -0
- sage/combinat/designs/subhypergraph_search.pyx +9 -9
- sage/combinat/finite_state_machine_generators.py +2 -2
- sage/combinat/graph_path.py +3 -3
- sage/combinat/interval_posets.py +10 -10
- sage/combinat/ordered_tree.py +1 -1
- sage/combinat/posets/cartesian_product.py +1 -1
- sage/combinat/posets/d_complete.py +1 -1
- sage/combinat/posets/forest.py +1 -1
- sage/combinat/posets/hasse_cython.cpython-39-darwin.so +0 -0
- sage/combinat/posets/hasse_diagram.py +8 -6
- sage/combinat/posets/incidence_algebras.py +8 -8
- sage/combinat/posets/lattices.py +28 -4
- sage/combinat/posets/linear_extension_iterator.cpython-39-darwin.so +0 -0
- sage/combinat/posets/linear_extension_iterator.pyx +2 -0
- sage/combinat/posets/linear_extensions.py +7 -16
- sage/combinat/posets/moebius_algebra.py +1 -1
- sage/combinat/posets/poset_examples.py +1 -1
- sage/combinat/posets/posets.py +54 -56
- sage/combinat/rooted_tree.py +3 -3
- sage/combinat/tamari_lattices.py +1 -1
- sage/ext_data/kenzo/CP2.txt +45 -0
- sage/ext_data/kenzo/CP3.txt +349 -0
- sage/ext_data/kenzo/CP4.txt +4774 -0
- sage/ext_data/kenzo/README.txt +49 -0
- sage/ext_data/kenzo/S4.txt +20 -0
- sage/graphs/asteroidal_triples.cpython-39-darwin.so +0 -0
- sage/graphs/base/boost_graph.cpython-39-darwin.so +0 -0
- sage/graphs/base/boost_graph.pxd +1 -1
- sage/graphs/base/boost_graph.pyx +1 -1
- sage/graphs/base/c_graph.cpython-39-darwin.so +0 -0
- sage/graphs/base/c_graph.pxd +4 -4
- sage/graphs/base/c_graph.pyx +270 -184
- sage/graphs/base/dense_graph.cpython-39-darwin.so +0 -0
- sage/graphs/base/graph_backends.cpython-39-darwin.so +0 -0
- sage/graphs/base/sparse_graph.cpython-39-darwin.so +0 -0
- sage/graphs/base/static_dense_graph.cpython-39-darwin.so +0 -0
- sage/graphs/base/static_sparse_backend.cpython-39-darwin.so +0 -0
- sage/graphs/base/static_sparse_backend.pyx +93 -6
- sage/graphs/base/static_sparse_graph.cpython-39-darwin.so +0 -0
- sage/graphs/base/static_sparse_graph.pyx +1 -1
- sage/graphs/bipartite_graph.py +0 -1
- sage/graphs/centrality.cpython-39-darwin.so +0 -0
- sage/graphs/centrality.pyx +0 -0
- sage/graphs/comparability.cpython-39-darwin.so +0 -0
- sage/graphs/comparability.pyx +172 -138
- sage/graphs/connectivity.cpython-39-darwin.so +0 -0
- sage/graphs/connectivity.pyx +194 -18
- sage/graphs/convexity_properties.cpython-39-darwin.so +0 -0
- sage/graphs/digraph_generators.py +118 -74
- sage/graphs/distances_all_pairs.cpython-39-darwin.so +0 -0
- sage/graphs/distances_all_pairs.pyx +145 -27
- sage/graphs/edge_connectivity.cpython-39-darwin.so +0 -0
- sage/graphs/generators/basic.py +471 -130
- sage/graphs/generators/distance_regular.cpython-39-darwin.so +0 -0
- sage/graphs/generators/distance_regular.pyx +12 -12
- sage/graphs/generators/families.py +2 -2
- sage/graphs/generators/random.py +8 -13
- sage/graphs/generators/smallgraphs.py +12 -11
- sage/graphs/generic_graph.py +687 -265
- sage/graphs/generic_graph_pyx.cpython-39-darwin.so +0 -0
- sage/graphs/genus.cpython-39-darwin.so +0 -0
- sage/graphs/graph.py +12 -46
- sage/graphs/graph_coloring.cpython-39-darwin.so +0 -0
- sage/graphs/graph_database.py +1 -1
- sage/graphs/graph_decompositions/bandwidth.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/clique_separators.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/cutwidth.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/fast_digraph.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/graph_products.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/modular_decomposition.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/slice_decomposition.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/tree_decomposition.cpython-39-darwin.so +0 -0
- sage/graphs/graph_decompositions/vertex_separation.cpython-39-darwin.so +0 -0
- sage/graphs/graph_generators.py +110 -55
- sage/graphs/graph_generators_pyx.cpython-39-darwin.so +0 -0
- sage/graphs/graph_latex.py +1 -1
- sage/graphs/graph_list.py +2 -3
- sage/graphs/graph_plot.py +225 -30
- sage/graphs/hyperbolicity.cpython-39-darwin.so +0 -0
- sage/graphs/independent_sets.cpython-39-darwin.so +0 -0
- sage/graphs/isgci.py +3 -8
- sage/graphs/isoperimetric_inequalities.cpython-39-darwin.so +0 -0
- sage/graphs/line_graph.cpython-39-darwin.so +0 -0
- sage/graphs/matching.py +14 -25
- sage/graphs/matching_covered_graph.py +871 -60
- sage/graphs/orientations.py +190 -134
- sage/graphs/path_enumeration.cpython-39-darwin.so +0 -0
- sage/graphs/path_enumeration.pyx +25 -25
- sage/graphs/spanning_tree.cpython-39-darwin.so +0 -0
- sage/graphs/strongly_regular_db.cpython-39-darwin.so +0 -0
- sage/graphs/strongly_regular_db.pyx +54 -52
- sage/graphs/traversals.cpython-39-darwin.so +0 -0
- sage/graphs/traversals.pyx +114 -46
- sage/graphs/trees.cpython-39-darwin.so +0 -0
- sage/graphs/views.cpython-39-darwin.so +0 -0
- sage/graphs/weakly_chordal.cpython-39-darwin.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.cpython-39-darwin.so +0 -0
- sage/knots/free_knotinfo_monoid.py +2 -3
- sage/knots/knot.py +1 -1
- sage/knots/knotinfo.py +4 -4
- sage/knots/link.py +58 -57
- sage/sandpiles/sandpile.py +2 -3
- sage/topology/cell_complex.py +1 -1
- sage/topology/cubical_complex.py +7 -7
- sage/topology/delta_complex.py +4 -4
- sage/topology/simplicial_complex.py +7 -22
- passagemath_graphs-10.5.10.dist-info/RECORD +0 -251
- {passagemath_graphs-10.5.10.dist-info → passagemath_graphs-10.5.43.dist-info}/top_level.txt +0 -0
sage/graphs/comparability.pyx
CHANGED
@@ -16,12 +16,12 @@ The following methods are implemented in this module
|
|
16
16
|
:widths: 30, 70
|
17
17
|
:delim: |
|
18
18
|
|
19
|
-
:meth:`~is_comparability_MILP` |
|
20
|
-
:meth:`~greedy_is_comparability` |
|
21
|
-
:meth:`~greedy_is_comparability_with_certificate` |
|
22
|
-
:meth:`~is_comparability` |
|
23
|
-
:meth:`~is_permutation` |
|
24
|
-
:meth:`~is_transitive` |
|
19
|
+
:meth:`~is_comparability_MILP` | Check whether the graph is a comparability graph (MILP)
|
20
|
+
:meth:`~greedy_is_comparability` | Check whether the graph is a comparability graph (greedy algorithm)
|
21
|
+
:meth:`~greedy_is_comparability_with_certificate` | Check whether the graph is a comparability graph and returns certificates (greedy algorithm)
|
22
|
+
:meth:`~is_comparability` | Check whether the graph is a comparability graph
|
23
|
+
:meth:`~is_permutation` | Check whether the graph is a permutation graph.
|
24
|
+
:meth:`~is_transitive` | Check whether the digraph is transitive.
|
25
25
|
|
26
26
|
Author:
|
27
27
|
|
@@ -211,7 +211,7 @@ from copy import copy
|
|
211
211
|
|
212
212
|
def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
|
213
213
|
r"""
|
214
|
-
|
214
|
+
Check whether the graph is a comparability graph (greedy algorithm).
|
215
215
|
|
216
216
|
This method only returns no-certificates.
|
217
217
|
|
@@ -220,6 +220,8 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
|
|
220
220
|
|
221
221
|
INPUT:
|
222
222
|
|
223
|
+
- ``g`` -- a graph
|
224
|
+
|
223
225
|
- ``no_certificate`` -- whether to return a *no*-certificate when the graph
|
224
226
|
is not a comparability graph. This certificate is an odd cycle of edges,
|
225
227
|
each of which implies the next. It is set to ``False`` by default.
|
@@ -240,23 +242,33 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
|
|
240
242
|
|
241
243
|
The Petersen Graph is not transitively orientable::
|
242
244
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
245
|
+
sage: from sage.graphs.comparability import greedy_is_comparability as is_comparability
|
246
|
+
sage: g = graphs.PetersenGraph()
|
247
|
+
sage: is_comparability(g)
|
248
|
+
False
|
249
|
+
sage: is_comparability(g, no_certificate=True)
|
250
|
+
(False, [2, 1, 0, 4, 3, 2])
|
249
251
|
|
250
252
|
But the Bull graph is::
|
251
253
|
|
252
|
-
|
253
|
-
|
254
|
-
|
254
|
+
sage: g = graphs.BullGraph()
|
255
|
+
sage: is_comparability(g)
|
256
|
+
True
|
257
|
+
|
258
|
+
TESTS:
|
259
|
+
|
260
|
+
Check that the method is working even when vertices are of incomparable
|
261
|
+
types::
|
262
|
+
|
263
|
+
sage: from sage.graphs.comparability import greedy_is_comparability
|
264
|
+
sage: G = Graph([('a', 1), (1, 2), (2, 3)])
|
265
|
+
sage: greedy_is_comparability(G, equivalence_class=True)
|
266
|
+
(True, [('a', 1), (2, 1), (2, 3)])
|
255
267
|
"""
|
256
268
|
cdef int i, j
|
257
269
|
|
258
270
|
# Each vertex can partition its neighbors into equivalence classes
|
259
|
-
equivalence_classes = {}
|
271
|
+
cdef dict equivalence_classes = {}
|
260
272
|
for v in g:
|
261
273
|
equivalence_classes[v] = g.subgraph(vertices=g.neighbors(v)).complement().connected_components(sort=False)
|
262
274
|
|
@@ -287,39 +299,43 @@ def greedy_is_comparability(g, no_certificate=False, equivalence_class=False):
|
|
287
299
|
|
288
300
|
if isit:
|
289
301
|
if equivalence_class:
|
302
|
+
# We use a mapping between vertices and integers to deal with
|
303
|
+
# vertices of different types
|
304
|
+
int_to_vertex = list(g)
|
305
|
+
vertex_to_int = {u: i for i, u in enumerate(int_to_vertex)}
|
290
306
|
|
291
307
|
# Returning the largest equivalence class
|
292
|
-
cc =
|
308
|
+
cc = max(h.connected_components(sort=False), key=len)
|
293
309
|
|
294
310
|
edges = []
|
295
311
|
for v, sid in cc:
|
296
312
|
s = equivalence_classes[v][sid]
|
297
313
|
|
298
314
|
# For each edge we pick the good orientations
|
315
|
+
vi = vertex_to_int[v]
|
299
316
|
if certif[v, sid] == 1:
|
300
|
-
for vv in s
|
301
|
-
edges.append((v, vv))
|
317
|
+
edges.extend((vi, vertex_to_int[vv]) for vv in s)
|
302
318
|
else:
|
303
|
-
for vv in s
|
304
|
-
edges.append((vv, v))
|
319
|
+
edges.extend((vertex_to_int[vv], vi) for vv in s)
|
305
320
|
|
306
321
|
# We return the value but take care of removing edges that were
|
307
322
|
# added twice.
|
308
|
-
|
323
|
+
edges = [(int_to_vertex[u], int_to_vertex[v]) for u, v in sorted(set(edges))]
|
324
|
+
return True, edges
|
309
325
|
|
310
326
|
return True
|
311
327
|
|
312
328
|
if no_certificate:
|
313
|
-
certif.append(certif[0])
|
314
329
|
cycle = [v for v, _ in certif]
|
330
|
+
cycle.append(cycle[0])
|
315
331
|
return False, cycle
|
316
332
|
return False
|
317
333
|
|
318
334
|
|
319
335
|
def greedy_is_comparability_with_certificate(g, certificate=False):
|
320
336
|
r"""
|
321
|
-
|
322
|
-
certificates(greedy algorithm).
|
337
|
+
Check whether the graph is a comparability graph and returns
|
338
|
+
certificates (greedy algorithm).
|
323
339
|
|
324
340
|
This method can return certificates of both *yes* and *no* answers.
|
325
341
|
|
@@ -328,6 +344,8 @@ def greedy_is_comparability_with_certificate(g, certificate=False):
|
|
328
344
|
|
329
345
|
INPUT:
|
330
346
|
|
347
|
+
- ``g`` -- a graph
|
348
|
+
|
331
349
|
- ``certificate`` -- boolean; whether to return a
|
332
350
|
certificate. *Yes*-answers the certificate is a transitive orientation of
|
333
351
|
`G`, and a *no* certificates is an odd cycle of sequentially forcing
|
@@ -337,24 +355,34 @@ def greedy_is_comparability_with_certificate(g, certificate=False):
|
|
337
355
|
|
338
356
|
The 5-cycle or the Petersen Graph are not transitively orientable::
|
339
357
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
358
|
+
sage: from sage.graphs.comparability import greedy_is_comparability_with_certificate as is_comparability
|
359
|
+
sage: is_comparability(graphs.CycleGraph(5), certificate=True)
|
360
|
+
(False, [2, 1, 0, 4, 3, 2])
|
361
|
+
sage: g = graphs.PetersenGraph()
|
362
|
+
sage: is_comparability(g)
|
363
|
+
False
|
364
|
+
sage: is_comparability(g, certificate=True)
|
365
|
+
(False, [2, 1, 0, 4, 3, 2])
|
348
366
|
|
349
367
|
But the Bull graph is::
|
350
368
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
369
|
+
sage: g = graphs.BullGraph()
|
370
|
+
sage: is_comparability(g)
|
371
|
+
True
|
372
|
+
sage: is_comparability(g, certificate = True)
|
373
|
+
(True, Digraph on 5 vertices)
|
374
|
+
sage: is_comparability(g, certificate = True)[1].is_transitive()
|
375
|
+
True
|
376
|
+
|
377
|
+
TESTS:
|
378
|
+
|
379
|
+
Check that the method is working even when vertices are of incomparable
|
380
|
+
types::
|
381
|
+
|
382
|
+
sage: from sage.graphs.comparability import greedy_is_comparability_with_certificate
|
383
|
+
sage: G = Graph([('a', 1), (1, 2), (2, 3)])
|
384
|
+
sage: greedy_is_comparability_with_certificate(G, certificate=True)
|
385
|
+
(True, Digraph on 4 vertices)
|
358
386
|
"""
|
359
387
|
isit, certif = greedy_is_comparability(g, no_certificate=True, equivalence_class=True)
|
360
388
|
if not isit:
|
@@ -394,73 +422,70 @@ def greedy_is_comparability_with_certificate(g, certificate=False):
|
|
394
422
|
|
395
423
|
def is_comparability_MILP(g, certificate=False, solver=None, verbose=0):
|
396
424
|
r"""
|
397
|
-
|
425
|
+
Check whether the graph is a comparability graph (MILP).
|
398
426
|
|
399
427
|
INPUT:
|
400
428
|
|
401
|
-
- ``
|
402
|
-
yes instances. This method cannot return negative certificates.
|
429
|
+
- ``g`` -- a graph
|
403
430
|
|
404
|
-
- ``
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
431
|
+
- ``certificate`` -- boolean (default: ``False``); whether to return a
|
432
|
+
certificate for yes instances. This method cannot return negative
|
433
|
+
certificates.
|
434
|
+
|
435
|
+
- ``solver`` -- string (default: ``None``); specifies a Mixed Integer Linear
|
436
|
+
Programming (MILP) solver to be used. If set to ``None``, the default one
|
437
|
+
is used. For more information on MILP solvers and which default solver is
|
438
|
+
used, see the method :meth:`solve
|
439
|
+
<sage.numerical.mip.MixedIntegerLinearProgram.solve>` of the class
|
440
|
+
:class:`MixedIntegerLinearProgram
|
441
|
+
<sage.numerical.mip.MixedIntegerLinearProgram>`.
|
409
442
|
|
410
443
|
- ``verbose`` -- integer (default: 0); sets the level of verbosity. Set
|
411
444
|
to 0 by default, which means quiet.
|
412
445
|
|
413
|
-
|
446
|
+
EXAMPLES:
|
414
447
|
|
415
448
|
The 5-cycle or the Petersen Graph are not transitively orientable::
|
416
449
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
450
|
+
sage: from sage.graphs.comparability import is_comparability_MILP as is_comparability
|
451
|
+
sage: is_comparability(graphs.CycleGraph(5), certificate=True) # needs sage.numerical.mip
|
452
|
+
(False, None)
|
453
|
+
sage: g = graphs.PetersenGraph()
|
454
|
+
sage: is_comparability(g, certificate=True) # needs sage.numerical.mip
|
455
|
+
(False, None)
|
423
456
|
|
424
457
|
But the Bull graph is::
|
425
458
|
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
459
|
+
sage: g = graphs.BullGraph()
|
460
|
+
sage: is_comparability(g) # needs sage.numerical.mip
|
461
|
+
True
|
462
|
+
sage: is_comparability(g, certificate=True) # needs sage.numerical.mip
|
463
|
+
(True, Digraph on 5 vertices)
|
464
|
+
sage: is_comparability(g, certificate=True)[1].is_transitive() # needs sage.numerical.mip
|
465
|
+
True
|
433
466
|
"""
|
434
467
|
from sage.numerical.mip import MixedIntegerLinearProgram, MIPSolverException
|
435
|
-
cdef int i
|
436
|
-
|
437
468
|
p = MixedIntegerLinearProgram(solver=solver)
|
438
469
|
o = p.new_variable(binary=True)
|
439
470
|
|
440
471
|
for u, v in g.edge_iterator(labels=False):
|
441
472
|
p.add_constraint(o[u, v] + o[v, u] == 1)
|
442
473
|
|
474
|
+
from itertools import combinations
|
443
475
|
for u in g:
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
v
|
448
|
-
|
449
|
-
vv
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
# If there is no edge, there are only two
|
459
|
-
# orientations possible (see the module's documentation
|
460
|
-
# about edges which imply each other)
|
461
|
-
else:
|
462
|
-
p.add_constraint(o[u, v] + o[vv, u] <= 1)
|
463
|
-
p.add_constraint(o[u, vv] + o[v, u] <= 1)
|
476
|
+
for v, vv in combinations(g.neighbors(u), 2):
|
477
|
+
|
478
|
+
# If there is an edge between v and vv, we must be sure it is in the
|
479
|
+
# good direction when v-u-vv is a directed path
|
480
|
+
if g.has_edge(v, vv):
|
481
|
+
p.add_constraint(o[u, v] + o[vv, u] - o[vv, v] <= 1)
|
482
|
+
p.add_constraint(o[u, vv] + o[v, u] - o[v, vv] <= 1)
|
483
|
+
|
484
|
+
# If there is no edge, there are only two orientations possible (see
|
485
|
+
# the module's documentation about edges which imply each other)
|
486
|
+
else:
|
487
|
+
p.add_constraint(o[u, v] + o[vv, u] <= 1)
|
488
|
+
p.add_constraint(o[u, vv] + o[v, u] <= 1)
|
464
489
|
|
465
490
|
try:
|
466
491
|
p.solve(log=verbose)
|
@@ -495,11 +520,14 @@ def is_comparability_MILP(g, certificate=False, solver=None, verbose=0):
|
|
495
520
|
def is_comparability(g, algorithm='greedy', certificate=False, check=True,
|
496
521
|
solver=None, verbose=0):
|
497
522
|
r"""
|
498
|
-
|
523
|
+
Check whether the graph is a comparability graph.
|
499
524
|
|
500
525
|
INPUT:
|
501
526
|
|
502
|
-
- ``
|
527
|
+
- ``g`` -- a graph
|
528
|
+
|
529
|
+
- ``algorithm`` -- string (default: ``'greedy'``); choose the implementation
|
530
|
+
used to do the test
|
503
531
|
|
504
532
|
- ``'greedy'`` -- a greedy algorithm (see the documentation of the
|
505
533
|
:mod:`comparability module <sage.graphs.comparability>`)
|
@@ -509,20 +537,22 @@ def is_comparability(g, algorithm='greedy', certificate=False, check=True,
|
|
509
537
|
certificates ! When ``certificate = True``, negative certificates are
|
510
538
|
always equal to ``None``. ``True`` certificates are valid, though.
|
511
539
|
|
512
|
-
- ``certificate`` -- boolean; whether to return a
|
540
|
+
- ``certificate`` -- boolean (default: ``False``); whether to return a
|
513
541
|
certificate. *Yes*-answers the certificate is a transitive orientation of
|
514
542
|
`G`, and a *no* certificates is an odd cycle of sequentially forcing
|
515
543
|
edges.
|
516
544
|
|
517
|
-
- ``check`` -- boolean; whether to check that the
|
545
|
+
- ``check`` -- boolean (default: ``True``); whether to check that the
|
518
546
|
yes-certificates are indeed transitive. As it is very quick
|
519
547
|
compared to the rest of the operation, it is enabled by default.
|
520
548
|
|
521
|
-
- ``solver`` -- (default: ``None``)
|
522
|
-
be used. If set to ``None``, the default one
|
523
|
-
on
|
524
|
-
|
525
|
-
|
549
|
+
- ``solver`` -- string (default: ``None``); specifies a Mixed Integer Linear
|
550
|
+
Programming (MILP) solver to be used. If set to ``None``, the default one
|
551
|
+
is used. For more information on MILP solvers and which default solver is
|
552
|
+
used, see the method :meth:`solve
|
553
|
+
<sage.numerical.mip.MixedIntegerLinearProgram.solve>` of the class
|
554
|
+
:class:`MixedIntegerLinearProgram
|
555
|
+
<sage.numerical.mip.MixedIntegerLinearProgram>`.
|
526
556
|
|
527
557
|
- ``verbose`` -- integer (default: 0); sets the level of verbosity. Set
|
528
558
|
to 0 by default, which means quiet.
|
@@ -538,15 +568,14 @@ def is_comparability(g, algorithm='greedy', certificate=False, check=True,
|
|
538
568
|
|
539
569
|
TESTS:
|
540
570
|
|
541
|
-
Let us ensure that no exception is raised when we go over all
|
542
|
-
small graphs::
|
571
|
+
Let us ensure that no exception is raised when we go over all small graphs::
|
543
572
|
|
544
573
|
sage: from sage.graphs.comparability import is_comparability
|
545
574
|
sage: [len([g for g in graphs(i) if is_comparability(g, certificate=True)[0]]) for i in range(7)] # needs nauty
|
546
575
|
[1, 1, 2, 4, 11, 33, 144]
|
547
576
|
"""
|
548
577
|
g._scream_if_not_simple()
|
549
|
-
if g.size()
|
578
|
+
if not g.size():
|
550
579
|
if certificate:
|
551
580
|
from sage.graphs.digraph import DiGraph
|
552
581
|
return True, DiGraph(g)
|
@@ -569,8 +598,8 @@ def is_comparability(g, algorithm='greedy', certificate=False, check=True,
|
|
569
598
|
if check and isit and (not certif.is_transitive()):
|
570
599
|
raise ValueError("Looks like there is a bug somewhere. The "
|
571
600
|
"algorithm thinks that the orientation is "
|
572
|
-
"transitive, but we just checked and it is not."
|
573
|
-
"Please report the bug on sage-devel, and give"
|
601
|
+
"transitive, but we just checked and it is not. "
|
602
|
+
"Please report the bug on sage-devel, and give "
|
574
603
|
"us the graph that made this method fail !")
|
575
604
|
|
576
605
|
return isit, certif
|
@@ -579,15 +608,17 @@ def is_comparability(g, algorithm='greedy', certificate=False, check=True,
|
|
579
608
|
def is_permutation(g, algorithm='greedy', certificate=False, check=True,
|
580
609
|
solver=None, verbose=0):
|
581
610
|
r"""
|
582
|
-
|
611
|
+
Check whether the graph is a permutation graph.
|
583
612
|
|
584
613
|
For more information on permutation graphs, refer to the documentation of
|
585
614
|
the :mod:`comparability module <sage.graphs.comparability>`.
|
586
615
|
|
587
616
|
INPUT:
|
588
617
|
|
589
|
-
- ``
|
590
|
-
|
618
|
+
- ``g`` -- a graph
|
619
|
+
|
620
|
+
- ``algorithm`` -- string (default: ``'greedy'``); choose the implementation
|
621
|
+
used for the subcalls to :meth:`is_comparability`
|
591
622
|
|
592
623
|
- ``'greedy'`` -- a greedy algorithm (see the documentation of the
|
593
624
|
:mod:`comparability module <sage.graphs.comparability>`)
|
@@ -597,20 +628,23 @@ def is_permutation(g, algorithm='greedy', certificate=False, check=True,
|
|
597
628
|
certificates ! When ``certificate = True``, negative certificates are
|
598
629
|
always equal to ``None``. ``True`` certificates are valid, though.
|
599
630
|
|
600
|
-
- ``certificate`` -- boolean; whether to return a
|
601
|
-
answer given. For ``True`` answers the certificate is
|
602
|
-
``False`` answers it is a no-certificate for the test
|
603
|
-
co-comparability.
|
631
|
+
- ``certificate`` -- boolean (default: ``False``); whether to return a
|
632
|
+
certificate for the answer given. For ``True`` answers the certificate is
|
633
|
+
a permutation, for ``False`` answers it is a no-certificate for the test
|
634
|
+
of comparability or co-comparability.
|
604
635
|
|
605
|
-
- ``check`` -- boolean; whether to check that the
|
606
|
-
indeed create the expected Permutation graph. Pretty
|
607
|
-
rest, hence a good investment. It is enabled by
|
636
|
+
- ``check`` -- boolean (default: ``True``); whether to check that the
|
637
|
+
permutations returned indeed create the expected Permutation graph. Pretty
|
638
|
+
cheap compared to the rest, hence a good investment. It is enabled by
|
639
|
+
default.
|
608
640
|
|
609
|
-
- ``solver`` -- (default: ``None``)
|
610
|
-
be used. If set to ``None``, the default one
|
611
|
-
on
|
612
|
-
|
613
|
-
|
641
|
+
- ``solver`` -- string (default: ``None``); specifies a Mixed Integer Linear
|
642
|
+
Programming (MILP) solver to be used. If set to ``None``, the default one
|
643
|
+
is used. For more information on MILP solvers and which default solver is
|
644
|
+
used, see the method :meth:`solve
|
645
|
+
<sage.numerical.mip.MixedIntegerLinearProgram.solve>` of the class
|
646
|
+
:class:`MixedIntegerLinearProgram
|
647
|
+
<sage.numerical.mip.MixedIntegerLinearProgram>`.
|
614
648
|
|
615
649
|
- ``verbose`` -- integer (default: 0); sets the level of verbosity. Set
|
616
650
|
to 0 by default, which means quiet.
|
@@ -645,33 +679,33 @@ def is_permutation(g, algorithm='greedy', certificate=False, check=True,
|
|
645
679
|
|
646
680
|
Trying random permutations, first with the greedy algorithm::
|
647
681
|
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
682
|
+
sage: from sage.graphs.comparability import is_permutation
|
683
|
+
sage: for i in range(20):
|
684
|
+
....: p = Permutations(10).random_element()
|
685
|
+
....: g1 = graphs.PermutationGraph(p)
|
686
|
+
....: isit, certif = is_permutation(g1, certificate=True)
|
687
|
+
....: if not isit:
|
688
|
+
....: print("Something is wrong here !!")
|
689
|
+
....: break
|
690
|
+
....: g2 = graphs.PermutationGraph(*certif)
|
691
|
+
....: if not g1.is_isomorphic(g2):
|
692
|
+
....: print("Something is wrong here !!")
|
693
|
+
....: break
|
660
694
|
|
661
695
|
Then with MILP::
|
662
696
|
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
697
|
+
sage: from sage.graphs.comparability import is_permutation
|
698
|
+
sage: for i in range(20): # needs sage.numerical.mip
|
699
|
+
....: p = Permutations(10).random_element()
|
700
|
+
....: g1 = graphs.PermutationGraph(p)
|
701
|
+
....: isit, certif = is_permutation(g1, algorithm='MILP', certificate=True)
|
702
|
+
....: if not isit:
|
703
|
+
....: print("Something is wrong here !!")
|
704
|
+
....: break
|
705
|
+
....: g2 = graphs.PermutationGraph(*certif)
|
706
|
+
....: if not g1.is_isomorphic(g2):
|
707
|
+
....: print("Something is wrong here !!")
|
708
|
+
....: break
|
675
709
|
"""
|
676
710
|
if not certificate:
|
677
711
|
# No certificate... A piece of cake
|
Binary file
|