passagemath-graphs 10.6.1rc1__cp310-cp310-musllinux_1_2_aarch64.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.6.1rc1.dist-info/METADATA +292 -0
- passagemath_graphs-10.6.1rc1.dist-info/RECORD +260 -0
- passagemath_graphs-10.6.1rc1.dist-info/WHEEL +5 -0
- passagemath_graphs-10.6.1rc1.dist-info/top_level.txt +2 -0
- passagemath_graphs.libs/libgcc_s-69c45f16.so.1 +0 -0
- passagemath_graphs.libs/libgmp-8e78bd9b.so.10.5.0 +0 -0
- passagemath_graphs.libs/libstdc++-1f1a71be.so.6.0.33 +0 -0
- sage/all__sagemath_graphs.py +39 -0
- sage/combinat/abstract_tree.py +2723 -0
- sage/combinat/all__sagemath_graphs.py +34 -0
- sage/combinat/binary_tree.py +5306 -0
- sage/combinat/cluster_algebra_quiver/all.py +22 -0
- sage/combinat/cluster_algebra_quiver/cluster_seed.py +5208 -0
- sage/combinat/cluster_algebra_quiver/interact.py +124 -0
- sage/combinat/cluster_algebra_quiver/mutation_class.py +625 -0
- sage/combinat/cluster_algebra_quiver/mutation_type.py +1555 -0
- sage/combinat/cluster_algebra_quiver/quiver.py +2290 -0
- sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +2468 -0
- sage/combinat/designs/MOLS_handbook_data.py +570 -0
- sage/combinat/designs/all.py +58 -0
- sage/combinat/designs/bibd.py +1655 -0
- sage/combinat/designs/block_design.py +1071 -0
- sage/combinat/designs/covering_array.py +269 -0
- sage/combinat/designs/covering_design.py +530 -0
- sage/combinat/designs/database.py +5615 -0
- sage/combinat/designs/design_catalog.py +122 -0
- sage/combinat/designs/designs_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/designs_pyx.pxd +21 -0
- sage/combinat/designs/designs_pyx.pyx +993 -0
- sage/combinat/designs/difference_family.py +3951 -0
- sage/combinat/designs/difference_matrices.py +279 -0
- sage/combinat/designs/evenly_distributed_sets.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/evenly_distributed_sets.pyx +661 -0
- sage/combinat/designs/ext_rep.py +1064 -0
- sage/combinat/designs/gen_quadrangles_with_spread.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/gen_quadrangles_with_spread.pyx +339 -0
- sage/combinat/designs/group_divisible_designs.py +361 -0
- sage/combinat/designs/incidence_structures.py +2357 -0
- sage/combinat/designs/latin_squares.py +581 -0
- sage/combinat/designs/orthogonal_arrays.py +2244 -0
- sage/combinat/designs/orthogonal_arrays_build_recursive.py +1780 -0
- sage/combinat/designs/orthogonal_arrays_find_recursive.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +967 -0
- sage/combinat/designs/resolvable_bibd.py +815 -0
- sage/combinat/designs/steiner_quadruple_systems.py +1306 -0
- sage/combinat/designs/subhypergraph_search.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/subhypergraph_search.pyx +530 -0
- sage/combinat/designs/twographs.py +306 -0
- sage/combinat/finite_state_machine.py +14874 -0
- sage/combinat/finite_state_machine_generators.py +2006 -0
- sage/combinat/graph_path.py +448 -0
- sage/combinat/interval_posets.py +3908 -0
- sage/combinat/nu_tamari_lattice.py +269 -0
- sage/combinat/ordered_tree.py +1446 -0
- sage/combinat/posets/all.py +46 -0
- sage/combinat/posets/bubble_shuffle.py +247 -0
- sage/combinat/posets/cartesian_product.py +493 -0
- sage/combinat/posets/d_complete.py +182 -0
- sage/combinat/posets/elements.py +273 -0
- sage/combinat/posets/forest.py +30 -0
- sage/combinat/posets/hasse_cython.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/posets/hasse_cython.pyx +174 -0
- sage/combinat/posets/hasse_diagram.py +3672 -0
- sage/combinat/posets/hochschild_lattice.py +158 -0
- sage/combinat/posets/incidence_algebras.py +794 -0
- sage/combinat/posets/lattices.py +5117 -0
- sage/combinat/posets/linear_extension_iterator.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/posets/linear_extension_iterator.pyx +292 -0
- sage/combinat/posets/linear_extensions.py +1037 -0
- sage/combinat/posets/mobile.py +275 -0
- sage/combinat/posets/moebius_algebra.py +776 -0
- sage/combinat/posets/poset_examples.py +2178 -0
- sage/combinat/posets/posets.py +9360 -0
- sage/combinat/rooted_tree.py +1070 -0
- sage/combinat/shard_order.py +239 -0
- sage/combinat/tamari_lattices.py +384 -0
- sage/combinat/yang_baxter_graph.py +923 -0
- sage/databases/all__sagemath_graphs.py +1 -0
- sage/databases/knotinfo_db.py +1231 -0
- sage/ext_data/all__sagemath_graphs.py +1 -0
- sage/ext_data/graphs/graph_plot_js.html +330 -0
- 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/all.py +42 -0
- sage/graphs/asteroidal_triples.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/asteroidal_triples.pyx +320 -0
- sage/graphs/base/all.py +1 -0
- sage/graphs/base/boost_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/boost_graph.pxd +106 -0
- sage/graphs/base/boost_graph.pyx +3045 -0
- sage/graphs/base/c_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/c_graph.pxd +106 -0
- sage/graphs/base/c_graph.pyx +5096 -0
- sage/graphs/base/dense_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/dense_graph.pxd +28 -0
- sage/graphs/base/dense_graph.pyx +801 -0
- sage/graphs/base/graph_backends.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/graph_backends.pxd +5 -0
- sage/graphs/base/graph_backends.pyx +797 -0
- sage/graphs/base/overview.py +85 -0
- sage/graphs/base/sparse_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/sparse_graph.pxd +90 -0
- sage/graphs/base/sparse_graph.pyx +1653 -0
- sage/graphs/base/static_dense_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_dense_graph.pxd +5 -0
- sage/graphs/base/static_dense_graph.pyx +1032 -0
- sage/graphs/base/static_sparse_backend.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_sparse_backend.pxd +27 -0
- sage/graphs/base/static_sparse_backend.pyx +1583 -0
- sage/graphs/base/static_sparse_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_sparse_graph.pxd +37 -0
- sage/graphs/base/static_sparse_graph.pyx +1375 -0
- sage/graphs/bipartite_graph.py +2732 -0
- sage/graphs/centrality.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/centrality.pyx +1038 -0
- sage/graphs/cographs.py +519 -0
- sage/graphs/comparability.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/comparability.pyx +851 -0
- sage/graphs/connectivity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/connectivity.pxd +157 -0
- sage/graphs/connectivity.pyx +4813 -0
- sage/graphs/convexity_properties.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/convexity_properties.pxd +16 -0
- sage/graphs/convexity_properties.pyx +870 -0
- sage/graphs/digraph.py +4754 -0
- sage/graphs/digraph_generators.py +1993 -0
- sage/graphs/distances_all_pairs.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/distances_all_pairs.pxd +12 -0
- sage/graphs/distances_all_pairs.pyx +2938 -0
- sage/graphs/domination.py +1363 -0
- sage/graphs/dot2tex_utils.py +100 -0
- sage/graphs/edge_connectivity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/edge_connectivity.pyx +1215 -0
- sage/graphs/generators/all.py +1 -0
- sage/graphs/generators/basic.py +1769 -0
- sage/graphs/generators/chessboard.py +538 -0
- sage/graphs/generators/classical_geometries.py +1611 -0
- sage/graphs/generators/degree_sequence.py +235 -0
- sage/graphs/generators/distance_regular.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/generators/distance_regular.pyx +2846 -0
- sage/graphs/generators/families.py +4759 -0
- sage/graphs/generators/intersection.py +565 -0
- sage/graphs/generators/platonic_solids.py +262 -0
- sage/graphs/generators/random.py +2623 -0
- sage/graphs/generators/smallgraphs.py +5741 -0
- sage/graphs/generators/world_map.py +724 -0
- sage/graphs/generic_graph.py +26867 -0
- sage/graphs/generic_graph_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/generic_graph_pyx.pxd +34 -0
- sage/graphs/generic_graph_pyx.pyx +1673 -0
- sage/graphs/genus.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/genus.pyx +622 -0
- sage/graphs/graph.py +9645 -0
- sage/graphs/graph_coloring.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_coloring.pyx +2284 -0
- sage/graphs/graph_database.py +1177 -0
- sage/graphs/graph_decompositions/all.py +1 -0
- sage/graphs/graph_decompositions/bandwidth.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/bandwidth.pyx +428 -0
- sage/graphs/graph_decompositions/clique_separators.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/clique_separators.pyx +616 -0
- sage/graphs/graph_decompositions/cutwidth.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/cutwidth.pyx +753 -0
- sage/graphs/graph_decompositions/fast_digraph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/fast_digraph.pxd +13 -0
- sage/graphs/graph_decompositions/fast_digraph.pyx +212 -0
- sage/graphs/graph_decompositions/graph_products.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/graph_products.pyx +508 -0
- sage/graphs/graph_decompositions/modular_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/modular_decomposition.pxd +27 -0
- sage/graphs/graph_decompositions/modular_decomposition.pyx +1536 -0
- sage/graphs/graph_decompositions/slice_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/slice_decomposition.pxd +18 -0
- sage/graphs/graph_decompositions/slice_decomposition.pyx +1106 -0
- sage/graphs/graph_decompositions/tree_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/tree_decomposition.pxd +17 -0
- sage/graphs/graph_decompositions/tree_decomposition.pyx +1996 -0
- sage/graphs/graph_decompositions/vertex_separation.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/vertex_separation.pxd +5 -0
- sage/graphs/graph_decompositions/vertex_separation.pyx +1963 -0
- sage/graphs/graph_editor.py +82 -0
- sage/graphs/graph_generators.py +3314 -0
- sage/graphs/graph_generators_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_generators_pyx.pyx +95 -0
- sage/graphs/graph_input.py +812 -0
- sage/graphs/graph_latex.py +2064 -0
- sage/graphs/graph_list.py +410 -0
- sage/graphs/graph_plot.py +1756 -0
- sage/graphs/graph_plot_js.py +338 -0
- sage/graphs/hyperbolicity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/hyperbolicity.pyx +1704 -0
- sage/graphs/hypergraph_generators.py +364 -0
- sage/graphs/independent_sets.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/independent_sets.pxd +13 -0
- sage/graphs/independent_sets.pyx +402 -0
- sage/graphs/isgci.py +1033 -0
- sage/graphs/isoperimetric_inequalities.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/isoperimetric_inequalities.pyx +489 -0
- sage/graphs/line_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/line_graph.pyx +743 -0
- sage/graphs/lovasz_theta.py +77 -0
- sage/graphs/matching.py +1633 -0
- sage/graphs/matching_covered_graph.py +3590 -0
- sage/graphs/orientations.py +1489 -0
- sage/graphs/partial_cube.py +459 -0
- sage/graphs/path_enumeration.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/path_enumeration.pyx +2040 -0
- sage/graphs/pq_trees.py +1129 -0
- sage/graphs/print_graphs.py +201 -0
- sage/graphs/schnyder.py +865 -0
- sage/graphs/spanning_tree.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/spanning_tree.pyx +1457 -0
- sage/graphs/strongly_regular_db.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/strongly_regular_db.pyx +3340 -0
- sage/graphs/traversals.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/traversals.pxd +9 -0
- sage/graphs/traversals.pyx +1872 -0
- sage/graphs/trees.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/trees.pxd +15 -0
- sage/graphs/trees.pyx +310 -0
- sage/graphs/tutte_polynomial.py +713 -0
- sage/graphs/views.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/views.pyx +794 -0
- sage/graphs/weakly_chordal.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/weakly_chordal.pyx +604 -0
- sage/groups/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/partn_ref/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.pxd +38 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +1666 -0
- sage/knots/all.py +6 -0
- sage/knots/free_knotinfo_monoid.py +507 -0
- sage/knots/gauss_code.py +291 -0
- sage/knots/knot.py +682 -0
- sage/knots/knot_table.py +284 -0
- sage/knots/knotinfo.py +2900 -0
- sage/knots/link.py +4715 -0
- sage/sandpiles/all.py +13 -0
- sage/sandpiles/examples.py +225 -0
- sage/sandpiles/sandpile.py +6365 -0
- sage/topology/all.py +22 -0
- sage/topology/cell_complex.py +1214 -0
- sage/topology/cubical_complex.py +1976 -0
- sage/topology/delta_complex.py +1806 -0
- sage/topology/filtered_simplicial_complex.py +744 -0
- sage/topology/moment_angle_complex.py +823 -0
- sage/topology/simplicial_complex.py +5160 -0
- sage/topology/simplicial_complex_catalog.py +92 -0
- sage/topology/simplicial_complex_examples.py +1680 -0
- sage/topology/simplicial_complex_homset.py +205 -0
- sage/topology/simplicial_complex_morphism.py +836 -0
- sage/topology/simplicial_set.py +4102 -0
- sage/topology/simplicial_set_catalog.py +55 -0
- sage/topology/simplicial_set_constructions.py +2954 -0
- sage/topology/simplicial_set_examples.py +865 -0
- sage/topology/simplicial_set_morphism.py +1464 -0
Binary file
|
sage/graphs/trees.pxd
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-graphs
|
2
|
+
|
3
|
+
cdef class TreeIterator:
|
4
|
+
cdef int vertices
|
5
|
+
cdef int first_time
|
6
|
+
cdef int p
|
7
|
+
cdef int q
|
8
|
+
cdef int h1
|
9
|
+
cdef int h2
|
10
|
+
cdef int c
|
11
|
+
cdef int r
|
12
|
+
cdef int *l
|
13
|
+
cdef int *current_level_sequence
|
14
|
+
cdef int generate_first_level_sequence(self) noexcept
|
15
|
+
cdef int generate_next_level_sequence(self) noexcept
|
sage/graphs/trees.pyx
ADDED
@@ -0,0 +1,310 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-graphs
|
2
|
+
r"""
|
3
|
+
Generation of trees
|
4
|
+
|
5
|
+
This is an implementation of the algorithm for generating trees with `n`
|
6
|
+
vertices (up to isomorphism) in constant time per tree described in
|
7
|
+
[WROM1986]_.
|
8
|
+
|
9
|
+
AUTHORS:
|
10
|
+
|
11
|
+
- Ryan Dingman (2009-04-16): initial version
|
12
|
+
"""
|
13
|
+
|
14
|
+
from libc.limits cimport INT_MAX
|
15
|
+
from cysignals.memory cimport check_allocarray, sig_free
|
16
|
+
|
17
|
+
# from networkx import MultiGraph
|
18
|
+
|
19
|
+
from sage.graphs.graph import Graph
|
20
|
+
from sage.graphs.base.sparse_graph cimport SparseGraph
|
21
|
+
from sage.graphs.base.sparse_graph cimport SparseGraphBackend
|
22
|
+
|
23
|
+
cdef class TreeIterator:
|
24
|
+
r"""
|
25
|
+
This class iterates over all trees with n vertices (up to isomorphism).
|
26
|
+
|
27
|
+
EXAMPLES::
|
28
|
+
|
29
|
+
sage: from sage.graphs.trees import TreeIterator
|
30
|
+
sage: def check_trees(n):
|
31
|
+
....: trees = []
|
32
|
+
....: for t in TreeIterator(n):
|
33
|
+
....: if not t.is_tree():
|
34
|
+
....: return False
|
35
|
+
....: if t.num_verts() != n:
|
36
|
+
....: return False
|
37
|
+
....: if t.num_edges() != n - 1:
|
38
|
+
....: return False
|
39
|
+
....: for tree in trees:
|
40
|
+
....: if tree.is_isomorphic(t):
|
41
|
+
....: return False
|
42
|
+
....: trees.append(t)
|
43
|
+
....: return True
|
44
|
+
sage: check_trees(10)
|
45
|
+
True
|
46
|
+
|
47
|
+
::
|
48
|
+
|
49
|
+
sage: from sage.graphs.trees import TreeIterator
|
50
|
+
sage: count = 0
|
51
|
+
sage: for t in TreeIterator(15):
|
52
|
+
....: count += 1
|
53
|
+
sage: count
|
54
|
+
7741
|
55
|
+
"""
|
56
|
+
|
57
|
+
def __init__(self, int vertices):
|
58
|
+
r"""
|
59
|
+
Initialize an iterator over all trees with `n` vertices.
|
60
|
+
|
61
|
+
EXAMPLES::
|
62
|
+
|
63
|
+
sage: from sage.graphs.trees import TreeIterator
|
64
|
+
sage: t = TreeIterator(100) # indirect doctest
|
65
|
+
sage: print(t)
|
66
|
+
Iterator over all trees with 100 vertices
|
67
|
+
"""
|
68
|
+
self.vertices = vertices
|
69
|
+
self.l = NULL
|
70
|
+
self.current_level_sequence = NULL
|
71
|
+
self.first_time = 1
|
72
|
+
|
73
|
+
def __dealloc__(self):
|
74
|
+
r"""
|
75
|
+
EXAMPLES::
|
76
|
+
|
77
|
+
sage: from sage.graphs.trees import TreeIterator
|
78
|
+
sage: t = TreeIterator(100)
|
79
|
+
sage: t = None # indirect doctest
|
80
|
+
"""
|
81
|
+
sig_free(self.l)
|
82
|
+
sig_free(self.current_level_sequence)
|
83
|
+
|
84
|
+
def __str__(self):
|
85
|
+
r"""
|
86
|
+
EXAMPLES::
|
87
|
+
|
88
|
+
sage: from sage.graphs.trees import TreeIterator
|
89
|
+
sage: t = TreeIterator(100)
|
90
|
+
sage: print(t) # indirect doctest
|
91
|
+
Iterator over all trees with 100 vertices
|
92
|
+
"""
|
93
|
+
return "Iterator over all trees with %s vertices" % (self.vertices)
|
94
|
+
|
95
|
+
def __iter__(self):
|
96
|
+
r"""
|
97
|
+
Return an iterator over all the trees with `n` vertices.
|
98
|
+
|
99
|
+
EXAMPLES::
|
100
|
+
|
101
|
+
sage: from sage.graphs.trees import TreeIterator
|
102
|
+
sage: t = TreeIterator(4)
|
103
|
+
sage: list(iter(t))
|
104
|
+
[Graph on 4 vertices, Graph on 4 vertices]
|
105
|
+
"""
|
106
|
+
return self
|
107
|
+
|
108
|
+
def __next__(self):
|
109
|
+
r"""
|
110
|
+
Return the next tree with `n` vertices.
|
111
|
+
|
112
|
+
EXAMPLES::
|
113
|
+
|
114
|
+
sage: from sage.graphs.trees import TreeIterator
|
115
|
+
sage: T = TreeIterator(5)
|
116
|
+
sage: [t for t in T] # indirect doctest
|
117
|
+
[Graph on 5 vertices, Graph on 5 vertices, Graph on 5 vertices]
|
118
|
+
|
119
|
+
|
120
|
+
TESTS:
|
121
|
+
|
122
|
+
This used to be broken for trees with no vertices
|
123
|
+
and was fixed in :issue:`13719` ::
|
124
|
+
|
125
|
+
sage: from sage.graphs.trees import TreeIterator
|
126
|
+
sage: T = TreeIterator(0)
|
127
|
+
sage: [t for t in T] # indirect doctest
|
128
|
+
[Graph on 0 vertices]
|
129
|
+
"""
|
130
|
+
|
131
|
+
if not self.first_time and not self.q:
|
132
|
+
raise StopIteration
|
133
|
+
|
134
|
+
if self.first_time == 1:
|
135
|
+
self.first_time = 0
|
136
|
+
if self.vertices:
|
137
|
+
self.l = <int *>check_allocarray(self.vertices, sizeof(int))
|
138
|
+
self.current_level_sequence = <int *>check_allocarray(self.vertices, sizeof(int))
|
139
|
+
|
140
|
+
self.generate_first_level_sequence()
|
141
|
+
else:
|
142
|
+
self.q = 0
|
143
|
+
else:
|
144
|
+
self.generate_next_level_sequence()
|
145
|
+
|
146
|
+
cdef int i
|
147
|
+
cdef int vertex1
|
148
|
+
cdef int vertex2
|
149
|
+
cdef object G
|
150
|
+
|
151
|
+
G = Graph(self.vertices, sparse=True)
|
152
|
+
cdef SparseGraph SG = (<SparseGraphBackend?> G._backend)._cg
|
153
|
+
|
154
|
+
for i in range(2, self.vertices + 1):
|
155
|
+
vertex1 = i - 1
|
156
|
+
vertex2 = self.current_level_sequence[i - 1] - 1
|
157
|
+
SG.add_arc_unsafe(vertex1, vertex2)
|
158
|
+
|
159
|
+
return G
|
160
|
+
|
161
|
+
cdef int generate_first_level_sequence(self) noexcept:
|
162
|
+
r"""
|
163
|
+
Generates the level sequence representing the first tree with `n` vertices
|
164
|
+
"""
|
165
|
+
cdef int i
|
166
|
+
cdef int k
|
167
|
+
|
168
|
+
k = (self.vertices / 2) + 1
|
169
|
+
|
170
|
+
if self.vertices == 4:
|
171
|
+
self.p = 3
|
172
|
+
else:
|
173
|
+
self.p = self.vertices
|
174
|
+
self.q = self.vertices - 1
|
175
|
+
self.h1 = k
|
176
|
+
self.h2 = self.vertices
|
177
|
+
if self.vertices % 2:
|
178
|
+
self.c = INT_MAX # oo
|
179
|
+
else:
|
180
|
+
self.c = self.vertices + 1
|
181
|
+
|
182
|
+
self.r = k
|
183
|
+
|
184
|
+
for i in range(1, k + 1):
|
185
|
+
self.l[i - 1] = i
|
186
|
+
for i in range(k + 1, self.vertices + 1):
|
187
|
+
self.l[i - 1] = i - k + 1
|
188
|
+
for i in range(self.vertices):
|
189
|
+
self.current_level_sequence[i] = i
|
190
|
+
if self.vertices > 2:
|
191
|
+
self.current_level_sequence[k] = 1
|
192
|
+
if self.vertices <= 3:
|
193
|
+
self.q = 0
|
194
|
+
|
195
|
+
return 0
|
196
|
+
|
197
|
+
cdef int generate_next_level_sequence(self) noexcept:
|
198
|
+
r"""
|
199
|
+
Generates the level sequence representing the next tree with `n` vertices
|
200
|
+
"""
|
201
|
+
cdef int i
|
202
|
+
cdef int fixit = 0
|
203
|
+
|
204
|
+
cdef int needr = 0
|
205
|
+
cdef int needc = 0
|
206
|
+
cdef int needh2 = 0
|
207
|
+
|
208
|
+
cdef int n = self.vertices
|
209
|
+
cdef int p = self.p
|
210
|
+
cdef int q = self.q
|
211
|
+
cdef int h1 = self.h1
|
212
|
+
cdef int h2 = self.h2
|
213
|
+
cdef int c = self.c
|
214
|
+
cdef int r = self.r
|
215
|
+
cdef int *l = self.l
|
216
|
+
cdef int *w = self.current_level_sequence
|
217
|
+
|
218
|
+
if c == n + 1 or p == h2 and (l[h1 - 1] == l[h2 - 1] + 1 and n - h2 > r - h1 or l[h1 - 1] == l[h2 - 1] and n - h2 + 1 < r - h1):
|
219
|
+
if l[r - 1] > 3:
|
220
|
+
p = r
|
221
|
+
q = w[r - 1]
|
222
|
+
if h1 == r:
|
223
|
+
h1 = h1 - 1
|
224
|
+
fixit = 1
|
225
|
+
else:
|
226
|
+
p = r
|
227
|
+
r = r - 1
|
228
|
+
q = 2
|
229
|
+
|
230
|
+
if p <= h1:
|
231
|
+
h1 = p - 1
|
232
|
+
if p <= r:
|
233
|
+
needr = 1
|
234
|
+
elif p <= h2:
|
235
|
+
needh2 = 1
|
236
|
+
elif l[h2 - 1] == l[h1 - 1] - 1 and n - h2 == r - h1:
|
237
|
+
if p <= c:
|
238
|
+
needc = 1
|
239
|
+
else:
|
240
|
+
c = INT_MAX
|
241
|
+
|
242
|
+
cdef int oldp = p
|
243
|
+
cdef int delta = q - p
|
244
|
+
cdef int oldlq = l[q - 1]
|
245
|
+
cdef int oldwq = w[q - 1]
|
246
|
+
p = INT_MAX
|
247
|
+
|
248
|
+
for i in range(oldp, n + 1):
|
249
|
+
l[i - 1] = l[i - 1 + delta]
|
250
|
+
if l[i - 1] == 2:
|
251
|
+
w[i - 1] = 1
|
252
|
+
else:
|
253
|
+
p = i
|
254
|
+
if l[i - 1] == oldlq:
|
255
|
+
q = oldwq
|
256
|
+
else:
|
257
|
+
q = w[i - 1 + delta] - delta
|
258
|
+
w[i - 1] = q
|
259
|
+
if needr == 1 and l[i - 1] == 2:
|
260
|
+
needr = 0
|
261
|
+
needh2 = 1
|
262
|
+
r = i - 1
|
263
|
+
if needh2 == 1 and l[i - 1] <= l[i - 2] and i > r + 1:
|
264
|
+
needh2 = 0
|
265
|
+
h2 = i - 1
|
266
|
+
if l[h2 - 1] == l[h1 - 1] - 1 and n - h2 == r - h1:
|
267
|
+
needc = 1
|
268
|
+
else:
|
269
|
+
c = INT_MAX
|
270
|
+
if needc == 1:
|
271
|
+
if l[i - 1] != l[h1 - h2 + i - 1] - 1:
|
272
|
+
needc = 0
|
273
|
+
c = i
|
274
|
+
else:
|
275
|
+
c = i + 1
|
276
|
+
|
277
|
+
if fixit == 1:
|
278
|
+
r = n - h1 + 1
|
279
|
+
for i in range(r + 1, n + 1):
|
280
|
+
l[i - 1] = i - r + 1
|
281
|
+
w[i - 1] = i - 1
|
282
|
+
w[r] = 1
|
283
|
+
h2 = n
|
284
|
+
p = n
|
285
|
+
q = p - 1
|
286
|
+
c = INT_MAX
|
287
|
+
else:
|
288
|
+
if p == INT_MAX:
|
289
|
+
if l[oldp - 2] != 2:
|
290
|
+
p = oldp - 1
|
291
|
+
else:
|
292
|
+
p = oldp - 2
|
293
|
+
q = w[p - 1]
|
294
|
+
if needh2 == 1:
|
295
|
+
h2 = n
|
296
|
+
if l[h2 - 1] == l[h1 - 1] - 1 and h1 == r:
|
297
|
+
c = n + 1
|
298
|
+
else:
|
299
|
+
c = INT_MAX
|
300
|
+
|
301
|
+
self.p = p
|
302
|
+
self.q = q
|
303
|
+
self.h1 = h1
|
304
|
+
self.h2 = h2
|
305
|
+
self.c = c
|
306
|
+
self.r = r
|
307
|
+
self.l = l
|
308
|
+
self.current_level_sequence = w
|
309
|
+
|
310
|
+
return 0
|