Paths helpers
This page contains the documentation for the paths subpackage, that
contains helper functions for the Paths class.
Contents
Overloaded function. |
|
Overloaded function. |
Full API
This page contains the documentation for the paths subpackage, that
contains helper functions for the Paths class.
- paths.number_of_paths(*args, **kwargs)
Overloaded function.
- paths.number_of_paths(wg: WordGraph, source: int) int | PositiveInfinity
Returns the number of paths from a source node.
This function returns the number of paths in the word graph wg starting at source.
- Parameters:
- Returns:
The number of paths.
- Return type:
- Raises:
LibsemigroupsError – if source is not a node of the word graph wg.
- Complexity:
At worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph.
Note
If
libsemigroupsis compiled with the flag--enable-eigen, then this function makes use of the Eigen library for linear algebra (see [GJ+10]).Warning
If the number of paths exceeds
2 ** 64, then return value of this function will not be correct.
- paths.number_of_paths(wg: WordGraph, source: int, min: int, max: int | PositiveInfinity, lgrthm: paths.algorithm = paths.algorithm.automatic) int | PositiveInfinity
Returns the number of paths starting at a given node with length in a given range.
This function returns the number of paths starting at a given node with length in a given range.
- Parameters:
wg (WordGraph) – the word graph.
source (int) – the source node.
min (int) – the minimum length of paths to count.
max (int | PositiveInfinity) – the maximum length of paths to count.
lgrthm (paths.algorithm) – the algorithm to use (defaults to
paths.algorithm.automatic).
- Returns:
The number of paths.
- Return type:
- Complexity:
The complexity depends on the value of lgrthm as follows:
paths.algorithm.dfs: \(O(r)\) where \(r\) is the number of paths in the word graph starting at sourcepaths.algorithm.matrix: at worst \(O(n ^ 3 k)\) where \(n\) is the number of nodes and \(k\) equals max.paths.algorithm.acyclic: at worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph (only valid if the subgraph induced by the nodes reachable from source is acyclic)paths.algorithm.trivial: at worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph (only valid in some circumstances)paths.algorithm.automatic: attempts to select the fastest algorithm of the preceding algorithms and then applies that.
Note
If
libsemigroupsis compiled with the flag--enable-eigen, then this function makes use of the Eigen library for linear algebra (see [GJ+10]).Warning
If the number of paths exceeds
2 ** 64, then return value of this function will not be correct.Warning
If lgrthm is
paths.algorithm.automatic, then it is not always the case that the fastest algorithm is used.
- paths.number_of_paths(wg: WordGraph, source: int, target: int, min: int, max: int | PositiveInfinity, lgrthm: paths.algorithm = paths.algorithm.automatic) int | PositiveInfinity
Returns the number of paths starting at the node source and ending at node target with length in a given range.
This function returns the number of paths starting at the node source and ending at node target with length in a given range.
- Parameters:
wg (WordGraph) – the word graph.
source (int) – the source node.
target (int) – the target node.
min (int) – the minimum length of paths to count.
max (int | PositiveInfinity) – the maximum length of paths to count.
lgrthm (paths.algorithm) – the algorithm to use (defaults to
paths.algorithm.automatic).
- Returns:
The number of paths.
- Return type:
- Complexity:
The complexity depends on the value of lgrthm as follows:
paths.algorithm.dfs: \(O(r)\) where \(r\) is the number of paths in the word graph starting at sourcepaths.algorithm.matrix: at worst \(O(n ^ 3 k)\) where \(n\) is the number of nodes and \(k\) equals max.paths.algorithm.acyclic: at worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph (only valid if the subgraph induced by the nodes reachable from source is acyclic)paths.algorithm.trivial: at worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph (only valid in some circumstances)paths.algorithm.automatic: attempts to select the fastest algorithm of the preceding algorithms and then applies that.
Note
If
libsemigroupsis compiled with the flag--enable-eigen, then this function makes use of the Eigen library for linear algebra (see [GJ+10]).Warning
If the number of paths exceeds
2 ** 64, then return value of this function will not be correct.Warning
If lgrthm is
paths.algorithm.automatic, then it is not always the case that the fastest algorithm is used.
- paths.number_of_paths_algorithm(*args, **kwargs)
Overloaded function.
- paths.number_of_paths_algorithm(wg: WordGraph, source: int) paths.algorithm
Returns the
paths.algorithmused bynumber_of_paths.This function returns the algorithm that would be used by a call to
number_of_pathswith the same arguments.- Parameters:
- Returns:
The algorithm.
- Return type:
- Complexity:
Constant.
- paths.number_of_paths_algorithm(wg: WordGraph, source: int, min: int, max: int | PositiveInfinity) paths.algorithm
Returns the
paths.algorithmused bynumber_of_paths.This function returns the algorithm used by
number_of_pathsto compute the number of paths originating at the given source node with length in the range[min, max).- Parameters:
wg (WordGraph) – the word graph.
source (int) – the source node.
min (int) – the minimum length of paths to count.
max (int | PositiveInfinity) – the maximum length of paths to count.
- Returns:
The algorithm.
- Return type:
- Complexity:
At worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph.
- paths.number_of_paths_algorithm(wg: WordGraph, source: int, target: int, min: int, max: int | PositiveInfinity) paths.algorithm
Returns the
paths.algorithmused bynumber_of_paths.This function returns the algorithm used by
number_of_pathsto compute the number of paths originating at the given source node and ending at the given target node with length in the range[min, max).- Parameters:
- Returns:
The algorithm.
- Return type:
- Complexity:
At worst \(O(nm)\) where \(n\) is the number of nodes and \(m\) is the out-degree of the word graph.