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
@@ -0,0 +1,448 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-graphs
|
2
|
+
r"""
|
3
|
+
Paths in directed acyclic graphs
|
4
|
+
"""
|
5
|
+
# ****************************************************************************
|
6
|
+
# Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,
|
7
|
+
#
|
8
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
9
|
+
#
|
10
|
+
# This code is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# General Public License for more details.
|
14
|
+
#
|
15
|
+
# The full text of the GPL is available at:
|
16
|
+
#
|
17
|
+
# http://www.gnu.org/licenses/
|
18
|
+
# ****************************************************************************
|
19
|
+
|
20
|
+
from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
|
21
|
+
from sage.structure.parent import Parent
|
22
|
+
import sage.graphs.digraph as digraph
|
23
|
+
|
24
|
+
|
25
|
+
def GraphPaths(g, source=None, target=None):
|
26
|
+
"""
|
27
|
+
Return the combinatorial class of paths in the directed acyclic graph g.
|
28
|
+
|
29
|
+
EXAMPLES::
|
30
|
+
|
31
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
32
|
+
|
33
|
+
If source and target are not given, then the returned class
|
34
|
+
contains all paths (including trivial paths containing only one
|
35
|
+
vertex).
|
36
|
+
|
37
|
+
::
|
38
|
+
|
39
|
+
sage: p = GraphPaths(G); p
|
40
|
+
Paths in Multi-digraph on 5 vertices
|
41
|
+
sage: p.cardinality()
|
42
|
+
37
|
43
|
+
sage: path = p.random_element()
|
44
|
+
sage: all(G.has_edge(*path[i:i+2]) for i in range(len(path) -1))
|
45
|
+
True
|
46
|
+
|
47
|
+
If the source is specified, then the returned class contains all of
|
48
|
+
the paths starting at the vertex source (including the trivial
|
49
|
+
path).
|
50
|
+
|
51
|
+
::
|
52
|
+
|
53
|
+
sage: p = GraphPaths(G, source=3); p
|
54
|
+
Paths in Multi-digraph on 5 vertices starting at 3
|
55
|
+
sage: p.list()
|
56
|
+
[[3], [3, 4], [3, 4, 5], [3, 4, 5]]
|
57
|
+
|
58
|
+
If the target is specified, then the returned class contains all of
|
59
|
+
the paths ending at the vertex target (including the trivial
|
60
|
+
path).
|
61
|
+
|
62
|
+
::
|
63
|
+
|
64
|
+
sage: p = GraphPaths(G, target=3); p
|
65
|
+
Paths in Multi-digraph on 5 vertices ending at 3
|
66
|
+
sage: p.cardinality()
|
67
|
+
5
|
68
|
+
sage: p.list()
|
69
|
+
[[3], [1, 3], [2, 3], [1, 2, 3], [1, 2, 3]]
|
70
|
+
|
71
|
+
If both the target and source are specified, then the returned
|
72
|
+
class contains all of the paths from source to target.
|
73
|
+
|
74
|
+
::
|
75
|
+
|
76
|
+
sage: p = GraphPaths(G, source=1, target=3); p
|
77
|
+
Paths in Multi-digraph on 5 vertices starting at 1 and ending at 3
|
78
|
+
sage: p.cardinality()
|
79
|
+
3
|
80
|
+
sage: p.list()
|
81
|
+
[[1, 2, 3], [1, 2, 3], [1, 3]]
|
82
|
+
|
83
|
+
Note that G must be a directed acyclic graph.
|
84
|
+
|
85
|
+
::
|
86
|
+
|
87
|
+
sage: G = DiGraph({1:[2,2,3,5], 2:[3,4], 3:[4], 4:[2,5,7], 5:[6]}, multiedges=True)
|
88
|
+
sage: GraphPaths(G)
|
89
|
+
Traceback (most recent call last):
|
90
|
+
...
|
91
|
+
TypeError: g must be a directed acyclic graph
|
92
|
+
"""
|
93
|
+
if not isinstance(g, digraph.DiGraph):
|
94
|
+
raise TypeError("g must be a DiGraph")
|
95
|
+
elif not g.is_directed_acyclic():
|
96
|
+
raise TypeError("g must be a directed acyclic graph")
|
97
|
+
|
98
|
+
if source is None and target is None:
|
99
|
+
return GraphPaths_all(g)
|
100
|
+
elif source is not None and target is None:
|
101
|
+
if source not in g:
|
102
|
+
raise ValueError("source must be in g")
|
103
|
+
return GraphPaths_s(g, source)
|
104
|
+
elif source is None and target is not None:
|
105
|
+
if target not in g:
|
106
|
+
raise ValueError("target must be in g")
|
107
|
+
return GraphPaths_t(g, target)
|
108
|
+
else:
|
109
|
+
if source not in g:
|
110
|
+
raise ValueError("source must be in g")
|
111
|
+
if target not in g:
|
112
|
+
raise ValueError("target must be in g")
|
113
|
+
return GraphPaths_st(g, source, target)
|
114
|
+
|
115
|
+
|
116
|
+
class GraphPaths_common:
|
117
|
+
def __eq__(self, other):
|
118
|
+
"""
|
119
|
+
Test for equality.
|
120
|
+
|
121
|
+
EXAMPLES::
|
122
|
+
|
123
|
+
sage: G1 = DiGraph({1:[2,3], 2:[3]})
|
124
|
+
sage: p1 = GraphPaths(G1)
|
125
|
+
sage: G2 = DiGraph({2:[3], 3:[4]})
|
126
|
+
sage: p2 = GraphPaths(G2)
|
127
|
+
sage: p1 == p1
|
128
|
+
True
|
129
|
+
sage: p1 == p2
|
130
|
+
False
|
131
|
+
"""
|
132
|
+
if not isinstance(other, GraphPaths_common):
|
133
|
+
return False
|
134
|
+
return self.graph == other.graph
|
135
|
+
|
136
|
+
def __ne__(self, other):
|
137
|
+
"""
|
138
|
+
Test for unequality.
|
139
|
+
|
140
|
+
EXAMPLES::
|
141
|
+
|
142
|
+
sage: G1 = DiGraph({1:[2,3], 2:[3]})
|
143
|
+
sage: p1 = GraphPaths(G1)
|
144
|
+
sage: G2 = DiGraph({2:[3], 3:[4]})
|
145
|
+
sage: p2 = GraphPaths(G2)
|
146
|
+
sage: p1 != p2
|
147
|
+
True
|
148
|
+
sage: p1 != p1
|
149
|
+
False
|
150
|
+
"""
|
151
|
+
return not (self == other)
|
152
|
+
|
153
|
+
def outgoing_edges(self, v):
|
154
|
+
"""
|
155
|
+
Return a list of v's outgoing edges.
|
156
|
+
|
157
|
+
EXAMPLES::
|
158
|
+
|
159
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
160
|
+
sage: p = GraphPaths(G)
|
161
|
+
sage: p.outgoing_edges(2)
|
162
|
+
[(2, 3, None), (2, 4, None)]
|
163
|
+
"""
|
164
|
+
return list(self.graph.outgoing_edge_iterator(v))
|
165
|
+
|
166
|
+
def incoming_edges(self, v):
|
167
|
+
"""
|
168
|
+
Return a list of v's incoming edges.
|
169
|
+
|
170
|
+
EXAMPLES::
|
171
|
+
|
172
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
173
|
+
sage: p = GraphPaths(G)
|
174
|
+
sage: p.incoming_edges(2)
|
175
|
+
[(1, 2, None), (1, 2, None)]
|
176
|
+
"""
|
177
|
+
return list(self.graph.incoming_edge_iterator(v))
|
178
|
+
|
179
|
+
def outgoing_paths(self, v):
|
180
|
+
"""
|
181
|
+
Return a list of the paths that start at v.
|
182
|
+
|
183
|
+
EXAMPLES::
|
184
|
+
|
185
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
186
|
+
sage: gp = GraphPaths(G)
|
187
|
+
sage: gp.outgoing_paths(3)
|
188
|
+
[[3], [3, 4], [3, 4, 5], [3, 4, 5]]
|
189
|
+
sage: gp.outgoing_paths(2)
|
190
|
+
[[2],
|
191
|
+
[2, 3],
|
192
|
+
[2, 3, 4],
|
193
|
+
[2, 3, 4, 5],
|
194
|
+
[2, 3, 4, 5],
|
195
|
+
[2, 4],
|
196
|
+
[2, 4, 5],
|
197
|
+
[2, 4, 5]]
|
198
|
+
"""
|
199
|
+
source_paths = [[v]]
|
200
|
+
for e in self.outgoing_edges(v):
|
201
|
+
target = e[1]
|
202
|
+
target_paths = self.outgoing_paths(target)
|
203
|
+
target_paths = [[v] + path for path in target_paths]
|
204
|
+
|
205
|
+
source_paths += target_paths
|
206
|
+
|
207
|
+
return source_paths
|
208
|
+
|
209
|
+
def incoming_paths(self, v):
|
210
|
+
"""
|
211
|
+
Return a list of paths that end at v.
|
212
|
+
|
213
|
+
EXAMPLES::
|
214
|
+
|
215
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
216
|
+
sage: gp = GraphPaths(G)
|
217
|
+
sage: gp.incoming_paths(2)
|
218
|
+
[[2], [1, 2], [1, 2]]
|
219
|
+
"""
|
220
|
+
target_paths = [[v]]
|
221
|
+
for e in self.incoming_edges(v):
|
222
|
+
source = e[0]
|
223
|
+
source_paths = self.incoming_paths(source)
|
224
|
+
source_paths = [path + [v] for path in source_paths]
|
225
|
+
target_paths += source_paths
|
226
|
+
return target_paths
|
227
|
+
|
228
|
+
def paths_from_source_to_target(self, source, target):
|
229
|
+
"""
|
230
|
+
Return a list of paths from source to target.
|
231
|
+
|
232
|
+
EXAMPLES::
|
233
|
+
|
234
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
235
|
+
sage: gp = GraphPaths(G)
|
236
|
+
sage: gp.paths_from_source_to_target(2,4)
|
237
|
+
[[2, 3, 4], [2, 4]]
|
238
|
+
"""
|
239
|
+
source_paths = self.outgoing_paths(source)
|
240
|
+
return [path for path in source_paths if path[-1] == target]
|
241
|
+
|
242
|
+
def paths(self):
|
243
|
+
"""
|
244
|
+
Return a list of all the paths of ``self``.
|
245
|
+
|
246
|
+
EXAMPLES::
|
247
|
+
|
248
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
249
|
+
sage: gp = GraphPaths(G)
|
250
|
+
sage: len(gp.paths())
|
251
|
+
37
|
252
|
+
"""
|
253
|
+
paths = []
|
254
|
+
for source in self.graph.vertex_iterator():
|
255
|
+
paths += self.outgoing_paths(source)
|
256
|
+
return paths
|
257
|
+
|
258
|
+
|
259
|
+
class GraphPaths_all(Parent, GraphPaths_common):
|
260
|
+
"""
|
261
|
+
EXAMPLES::
|
262
|
+
|
263
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
264
|
+
sage: p = GraphPaths(G)
|
265
|
+
sage: p.cardinality()
|
266
|
+
37
|
267
|
+
"""
|
268
|
+
|
269
|
+
def __init__(self, g):
|
270
|
+
"""
|
271
|
+
TESTS::
|
272
|
+
|
273
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
274
|
+
sage: p = GraphPaths(G)
|
275
|
+
sage: p == loads(dumps(p))
|
276
|
+
True
|
277
|
+
"""
|
278
|
+
self.graph = g
|
279
|
+
Parent.__init__(self, category=FiniteEnumeratedSets())
|
280
|
+
|
281
|
+
def __repr__(self):
|
282
|
+
"""
|
283
|
+
TESTS::
|
284
|
+
|
285
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
286
|
+
sage: p = GraphPaths(G)
|
287
|
+
sage: repr(p)
|
288
|
+
'Paths in Multi-digraph on 5 vertices'
|
289
|
+
"""
|
290
|
+
return "Paths in %s" % repr(self.graph)
|
291
|
+
|
292
|
+
def list(self):
|
293
|
+
"""
|
294
|
+
Return a list of the paths of ``self``.
|
295
|
+
|
296
|
+
EXAMPLES::
|
297
|
+
|
298
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
299
|
+
sage: len(GraphPaths(G).list())
|
300
|
+
37
|
301
|
+
"""
|
302
|
+
return self.paths()
|
303
|
+
|
304
|
+
|
305
|
+
class GraphPaths_t(Parent, GraphPaths_common):
|
306
|
+
def __init__(self, g, target):
|
307
|
+
"""
|
308
|
+
TESTS::
|
309
|
+
|
310
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
311
|
+
sage: p = GraphPaths(G, target=4)
|
312
|
+
sage: p == loads(dumps(p))
|
313
|
+
True
|
314
|
+
"""
|
315
|
+
self.graph = g
|
316
|
+
self.target = target
|
317
|
+
Parent.__init__(self, category=FiniteEnumeratedSets())
|
318
|
+
|
319
|
+
def __repr__(self):
|
320
|
+
"""
|
321
|
+
TESTS::
|
322
|
+
|
323
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
324
|
+
sage: p = GraphPaths(G, target=4)
|
325
|
+
sage: repr(p)
|
326
|
+
'Paths in Multi-digraph on 5 vertices ending at 4'
|
327
|
+
"""
|
328
|
+
return "Paths in %s ending at %s" % (repr(self.graph), self.target)
|
329
|
+
|
330
|
+
def list(self):
|
331
|
+
"""
|
332
|
+
EXAMPLES::
|
333
|
+
|
334
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
335
|
+
sage: p = GraphPaths(G, target=4)
|
336
|
+
sage: p.list()
|
337
|
+
[[4],
|
338
|
+
[2, 4],
|
339
|
+
[1, 2, 4],
|
340
|
+
[1, 2, 4],
|
341
|
+
[3, 4],
|
342
|
+
[1, 3, 4],
|
343
|
+
[2, 3, 4],
|
344
|
+
[1, 2, 3, 4],
|
345
|
+
[1, 2, 3, 4]]
|
346
|
+
"""
|
347
|
+
return self.incoming_paths(self.target)
|
348
|
+
|
349
|
+
|
350
|
+
class GraphPaths_s(Parent, GraphPaths_common):
|
351
|
+
def __init__(self, g, source):
|
352
|
+
"""
|
353
|
+
TESTS::
|
354
|
+
|
355
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
356
|
+
sage: p = GraphPaths(G, 4)
|
357
|
+
sage: p == loads(dumps(p))
|
358
|
+
True
|
359
|
+
"""
|
360
|
+
self.graph = g
|
361
|
+
self.source = source
|
362
|
+
Parent.__init__(self, category=FiniteEnumeratedSets())
|
363
|
+
|
364
|
+
def __repr__(self):
|
365
|
+
"""
|
366
|
+
TESTS::
|
367
|
+
|
368
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
369
|
+
sage: p = GraphPaths(G, 4)
|
370
|
+
sage: repr(p)
|
371
|
+
'Paths in Multi-digraph on 5 vertices starting at 4'
|
372
|
+
"""
|
373
|
+
return "Paths in %s starting at %s" % (repr(self.graph), self.source)
|
374
|
+
|
375
|
+
def list(self):
|
376
|
+
"""
|
377
|
+
EXAMPLES::
|
378
|
+
|
379
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
380
|
+
sage: p = GraphPaths(G, 4)
|
381
|
+
sage: p.list()
|
382
|
+
[[4], [4, 5], [4, 5]]
|
383
|
+
"""
|
384
|
+
return self.outgoing_paths(self.source)
|
385
|
+
|
386
|
+
|
387
|
+
class GraphPaths_st(Parent, GraphPaths_common):
|
388
|
+
"""
|
389
|
+
EXAMPLES::
|
390
|
+
|
391
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
392
|
+
sage: GraphPaths(G,1,2).cardinality()
|
393
|
+
2
|
394
|
+
sage: GraphPaths(G,1,3).cardinality()
|
395
|
+
3
|
396
|
+
sage: GraphPaths(G,1,4).cardinality()
|
397
|
+
5
|
398
|
+
sage: GraphPaths(G,1,5).cardinality()
|
399
|
+
10
|
400
|
+
sage: GraphPaths(G,2,3).cardinality()
|
401
|
+
1
|
402
|
+
sage: GraphPaths(G,2,4).cardinality()
|
403
|
+
2
|
404
|
+
sage: GraphPaths(G,2,5).cardinality()
|
405
|
+
4
|
406
|
+
sage: GraphPaths(G,3,4).cardinality()
|
407
|
+
1
|
408
|
+
sage: GraphPaths(G,3,5).cardinality()
|
409
|
+
2
|
410
|
+
sage: GraphPaths(G,4,5).cardinality()
|
411
|
+
2
|
412
|
+
"""
|
413
|
+
|
414
|
+
def __init__(self, g, source, target):
|
415
|
+
"""
|
416
|
+
TESTS::
|
417
|
+
|
418
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
419
|
+
sage: p = GraphPaths(G,1,2)
|
420
|
+
sage: p == loads(dumps(p))
|
421
|
+
True
|
422
|
+
"""
|
423
|
+
self.graph = g
|
424
|
+
self.source = source
|
425
|
+
self.target = target
|
426
|
+
Parent.__init__(self, category=FiniteEnumeratedSets())
|
427
|
+
|
428
|
+
def __repr__(self):
|
429
|
+
"""
|
430
|
+
TESTS::
|
431
|
+
|
432
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
433
|
+
sage: p = GraphPaths(G,1,2)
|
434
|
+
sage: repr(p)
|
435
|
+
'Paths in Multi-digraph on 5 vertices starting at 1 and ending at 2'
|
436
|
+
"""
|
437
|
+
return "Paths in %s starting at %s and ending at %s" % (repr(self.graph), self.source, self.target)
|
438
|
+
|
439
|
+
def list(self):
|
440
|
+
"""
|
441
|
+
EXAMPLES::
|
442
|
+
|
443
|
+
sage: G = DiGraph({1:[2,2,3], 2:[3,4], 3:[4], 4:[5,5]}, multiedges=True)
|
444
|
+
sage: p = GraphPaths(G,1,2)
|
445
|
+
sage: p.list()
|
446
|
+
[[1, 2], [1, 2]]
|
447
|
+
"""
|
448
|
+
return self.paths_from_source_to_target(self.source, self.target)
|