![]() |
libsemigroups
v3.0.0
C++ library for semigroups and monoids
|
Defined in word-graph.hpp
.
Instances of this class represent word graphs. If the word graph has n
nodes, they are represented by the numbers \(\{0, ..., n - 1\}\), and every node has the same number m
of out-edges (edges with source that node and target any other node). The number m
is referred to as the out-degree of the word graph, or any of its nodes.
Node | the type of the nodes in the word graph, must be an unsigned integer type. |
Public Types | |
using | adjacency_matrix_type = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> |
The type of the adjacency matrix. | |
using | const_iterator_nodes |
The type of an iterator pointing to the nodes of a word graph. | |
using | const_iterator_targets |
The type of an iterator pointing to the targets of a node. | |
using | const_reverse_iterator_nodes |
The type of a reverse iterator pointing to the nodes of a word graph. | |
using | label_type = Node |
The type of edge labels in a word graph. | |
using | node_type = Node |
The type of nodes in a word graph. | |
using | size_type = std::size_t |
Unsigned integer type. | |
Public Member Functions | |
WordGraph (size_type m=0, size_type n=0) | |
Construct from number of nodes and out degree. | |
WordGraph (WordGraph &&) | |
Default move constructor. | |
WordGraph (WordGraph const &) | |
Default copy constructor. | |
template<typename OtherNode> | |
WordGraph (WordGraph< OtherNode > const &that) | |
Construct from WordGraph with another node type. | |
WordGraph & | add_nodes (size_type nr) |
Add a number of new nodes. | |
WordGraph & | add_to_out_degree (size_type nr) |
Add to the out-degree of every node. | |
const_iterator_nodes | cbegin_nodes () const noexcept |
Returns a random access iterator pointing at the first node of the word graph. | |
const_iterator_targets | cbegin_targets (node_type source) const |
Returns a random access iterator pointing at the target of the edge with label 0 incident to a given node. | |
const_iterator_targets | cbegin_targets_no_checks (node_type source) const noexcept |
Returns a random access iterator pointing at the target of the edge with label 0 incident to a given node. | |
const_iterator_nodes | cend_nodes () const noexcept |
Returns a random access iterator pointing one-past-the-last node of the word graph. | |
const_iterator_targets | cend_targets (node_type source) const |
Returns a random access iterator pointing one beyond the target of the edge with label out_degree() - 1 incident to a given node. | |
const_iterator_targets | cend_targets_no_checks (node_type source) const noexcept |
Returns a random access iterator pointing one beyond the target of the edge with label out_degree() - 1 incident to a given node. | |
WordGraph & | disjoint_union_inplace (WordGraph< Node > const &that) |
Unites a word graph in-place. | |
WordGraph & | disjoint_union_inplace_no_checks (WordGraph< Node > const &that) |
Unites a word graph in-place. | |
size_t | hash_value () const |
Returns a hash value. | |
template<typename Iterator, typename = std::enable_if_t<detail::IsIterator<Iterator>::value>> | |
WordGraph & | induced_subgraph (Iterator first, Iterator last) |
Modify in-place to contain the subgraph induced by a range of nodes. | |
WordGraph & | induced_subgraph (node_type first, node_type last) |
Modify in-place to contain the subgraph induced by a range of nodes. | |
template<typename Iterator, typename = std::enable_if_t<detail::IsIterator<Iterator>::value>> | |
WordGraph & | induced_subgraph_no_checks (Iterator first, Iterator last) |
Modify in-place to contain the subgraph induced by a range of nodes. | |
WordGraph & | induced_subgraph_no_checks (node_type first, node_type last) |
Modify in-place to contain the subgraph induced by a range of nodes. | |
WordGraph & | init (size_type m=0, size_type n=0) |
Re-initialize the word graph to have m nodes and out-degree n . | |
template<typename OtherNode> | |
WordGraph & | init (WordGraph< OtherNode > const &that) |
Re-initialize the word graph contain a copy of another. | |
auto | labels () const noexcept |
Returns a range object containing all labels of edges in a word graph. | |
auto | labels_and_targets (node_type source) const |
Returns a range object containing pairs consisting of edge labels and target nodes. | |
auto | labels_and_targets_no_checks (node_type source) const noexcept |
Returns a range object containing pairs consisting of edge labels and target nodes. | |
std::pair< label_type, node_type > | next_label_and_target (node_type s, label_type a) const |
Get the next target of an edge incident to a given node that doesn't equal UNDEFINED. | |
std::pair< label_type, node_type > | next_label_and_target_no_checks (node_type s, label_type a) const |
Get the next target of an edge incident to a given node that doesn't equal UNDEFINED. | |
auto | nodes () const noexcept |
Returns a range object containing all nodes in a word graph. | |
size_type | number_of_edges () const |
Returns the number of edges. | |
size_type | number_of_edges (node_type s) const |
Returns the number of edges with given source node. | |
size_type | number_of_edges_no_checks (node_type s) const |
Returns the number of edges with given source node. | |
size_type | number_of_nodes () const noexcept |
Returns the number of nodes. | |
bool | operator!= (WordGraph const &that) const |
Check if two word graphs are inequal. | |
bool | operator< (WordGraph const &that) const |
Check if a word graph is less than another. | |
bool | operator<= (WordGraph const &that) const |
Check if a word graph is less than or equal to another. | |
WordGraph & | operator= (WordGraph &&) |
Default move assignment constructor. | |
WordGraph & | operator= (WordGraph const &) |
Default copy assignment constructor. | |
bool | operator== (WordGraph const &that) const |
Check if two word graphs are equal. | |
bool | operator> (WordGraph const &that) const |
Check if a word graph is greater than another. | |
bool | operator>= (WordGraph const &that) const |
Check if a word graph is greater than or equal to another. | |
size_type | out_degree () const noexcept |
Returns the out-degree. | |
WordGraph & | remove_all_targets () |
Remove all of the edges in the word graph. | |
WordGraph & | remove_label (label_type a) |
Removes a given label from the word graph. | |
WordGraph & | remove_label_no_checks (label_type a) |
Removes a given label from the word graph. | |
WordGraph & | remove_target (node_type s, label_type a) |
Remove an edge from a node with a given label. | |
WordGraph & | remove_target_no_checks (node_type s, label_type a) |
Remove an edge from a node with a given label. | |
WordGraph & | reserve (size_type m, size_type n) |
Ensures that the word graph has capacity for a given number of nodes, and out-degree. | |
WordGraph & | swap_targets (node_type m, node_type n, label_type a) |
Swaps the edge with specified label from one node with another. | |
WordGraph & | swap_targets_no_checks (node_type m, node_type n, label_type a) |
Swaps the edge with specified label from one node with another. | |
WordGraph & | target (node_type s, label_type a, node_type t) |
Add an edge from one node to another with a given label. | |
node_type | target (node_type source, label_type a) const |
Get the target of the edge with given source node and label. | |
node_type | target_no_checks (node_type s, label_type a) const |
Get the target of the edge with given source node and label. | |
WordGraph & | target_no_checks (node_type s, label_type a, node_type t) |
Add an edge from one node to another with a given label. | |
rx::iterator_range< const_iterator_targets > | targets (node_type source) const |
Returns a range object containing all the targets of edges with a given source. | |
rx::iterator_range< const_iterator_targets > | targets_no_checks (node_type source) const noexcept |
Returns a range object containing all the targets of edges with a given source. | |
Static Public Member Functions | |
static WordGraph | random (size_type number_of_nodes, size_type out_degree, std::mt19937 mt=std::mt19937(std::random_device()())) |
Construct a random word graph from number of nodes and out-degree. | |
using const_iterator_nodes |
using const_iterator_targets |
using const_reverse_iterator_nodes |
This function constructs a word graph with m
nodes and where the maximum out-degree of any node is n
. There are no edges in the defined word graph.
m | the number of nodes in the word graph (default: 0). |
n | the out-degree of every node (default: 0). |
m
is the number of nodes, and n
is the out-degree of the word graph. WordGraph | ( | WordGraph< OtherNode > const & | that | ) |
This function can be used to construct a WordGraph<Node> as a copy of a WordGraph<OtherNode> so long as sizeof(OtherNode) <= sizeof(Node)
.
that | the word graph to copy. |
that
will have target static_cast<Node>(UNDEFINED)
in the constructed word graph. This function modifies a word graph in-place so that it has nr
new nodes added.
nr | the number of nodes to add. |
*this
.this
is guaranteed not to be modified (strong exception guarantee).(number_of_nodes() + nr) * out_degree()
.this
, any iterators, pointers or references pointing into this
may be invalidated by a call to this function. This function modifies a word graph in-place so that the out-degree is increased by nr
.
nr | the number of new out-edges for every node. |
*this
.this
is guaranteed not to be modified (strong exception guarantee).m
is the number of nodes, and n
is the new out degree of the word graph.this
, any iterators, pointers or references pointing into this
may be invalidated by a call to this function.
|
inlinenoexcept |
This function returns a random access iterator pointing at the first node on the word graph.
noexcept
and is guaranteed never to throw.
|
nodiscard |
This function returns a random access iterator pointing at the target of the edge with label 0
incident to the source node source
. This target might equal UNDEFINED.
source | the source node in the word graph. |
LibsemigroupsException | if source is out of range (i.e. greater than or equal to number_of_nodes). |
|
inlinenodiscardnoexcept |
This function returns a random access iterator pointing at the target of the edge with label 0
incident to the source node source
. This target might equal UNDEFINED.
source | a node in the word graph. |
noexcept
and is guaranteed never to throw.
|
inlinenodiscardnoexcept |
This function returns a random access iterator pointing one beyond the last node in the word graph.
noexcept
and is guaranteed never to throw.
|
nodiscard |
This function returns a random access iterator pointing one beyond the target of the edge with label out_degree() - 1
incident to the source node source
. This target might equal UNDEFINED.
source | a node in the word graph. |
LibsemigroupsException | if source is out of range (i.e. greater than or equal to number_of_nodes). |
|
inlinenodiscardnoexcept |
This function returns a random access iterator pointing one beyond the target of the edge with label out_degree() - 1
incident to the source node source
. This target might equal UNDEFINED.
source | a node in the word graph. |
noexcept
and is guaranteed never to throw.This function changes a WordGraph object in-place to contain the disjoint union of itself and that
. The node n
of that
is mapped to this->number_of_nodes() + n
.
that | the word graph to unite. |
*this
.LibsemigroupsException | if *this and that do not have the same out-degree. |
WordGraph & disjoint_union_inplace_no_checks | ( | WordGraph< Node > const & | that | ) |
This function changes a WordGraph object in-place to contain the disjoint union of itself and that
. The node n
of that
is mapped to this->number_of_nodes() + n
.
that | the word graph to unite. |
*this
.*this
and that
have equal out degree.
|
inlinenodiscard |
size_t
.WordGraph & induced_subgraph | ( | Iterator | first, |
Iterator | last ) |
This function modifies a WordGraph object in-place to contain its subgraph induced by the range of nodes first
to last
.
Iterator | the type of first and last (should be iterators). |
first | iterator pointing at the first node. |
last | iterator pointing one beyond the last node. |
*this
.LibsemigroupsException | if any value in the range specified by first and last is not a node of the word graph. |
LibsemigroupsException | if any target of any edge with source node in the range specified by first and last does not belong to the same range. |
This function modifies a WordGraph object in-place to contain its subgraph induced by the range of nodes first
to last
.
first | the first node. |
last | one more than the last node. |
*this
.LibsemigroupsException | if first or last is out of range. |
LibsemigroupsException | if any edge with source in the range first to last has target outside the range first to last . |
WordGraph & induced_subgraph_no_checks | ( | Iterator | first, |
Iterator | last ) |
This function modifies a WordGraph object in-place to contain its subgraph induced by the range of nodes first
to last
.
Iterator | the type of first and last (should be iterators). |
first | the first node. |
last | one more than the last node. |
*this
.This function modifies a WordGraph object in-place to contain its subgraph induced by the range of nodes first
to last
.
first | the first node. |
last | one more than the last node. |
*this
.This function puts a word graph into the state that it would have been in if it had just been newly constructed with the same parameters m
and n
.
m | the number of nodes in the word graph. |
n | the out-degree of every node. |
*this
.WordGraph & init | ( | WordGraph< OtherNode > const & | that | ) |
This function puts a word graph into the same state that it would have been in if it had just been newly copy constructed with the same parameter that
.
that | the word graph to copy. |
*this
.m
is the number of nodes, and n
is the out-degree of the word graph.that
will have target static_cast<Node>(UNDEFINED)
in *this
.
|
inlinenodiscardnoexcept |
This function returns a range object containing all the labels of edges in a word graph.
noexcept
and is guaranteed never to throw.
|
nodiscard |
This function returns a range object containing all the edge labels and targets of edges with source source
.
source | the source node. |
LibsemigroupsException | if source is out of bounds. |
|
inlinenodiscardnoexcept |
This function returns a range object containing all the edge labels and targets of edges with source source
.
source | the source node. |
noexcept
and is guaranteed never to throw.source
is a valid node of the word graph (i.e. it is not greater than or equal to number_of_nodes).
|
nodiscard |
This function returns the next target of an edge with label greater than or equal to a
that is incident to the node s
.
If target(s, b)
equals UNDEFINED for every value b
in the range \([a, n)\), where \(n\) is the return value of out_degree() then x.first
and x.second
equal UNDEFINED.
s | the node. |
a | the label. |
x
where:x.first
is adjacent to s
via an edge labelled x.second
; andx.second
is the minimum value in the range \([a, n)\) such that target(s, x.second)
is not equal to UNDEFINED where \(n\) is the return value of out_degree(); If no such value exists, then {UNDEFINED, UNDEFINED}
is returned.LibsemigroupsException | if s does not represent a node in this , or a is not a valid edge label. |
|
nodiscard |
This function returns the next target of an edge with label greater than or equal to a
that is incident to the node s
.
s | the source node. |
a | the label. |
x
where:x.first
is adjacent to s
via an edge labelled x.second
;x.second
is the minimum value in the range \([a, n)\) such that target(s, x.second)
is not equal to UNDEFINED (where \(n\) is the return value of out_degree); and If no such value exists, then {UNDEFINED, UNDEFINED}
is returned.s
represents a node of this
, or that a
is a valid label.
|
inlinenodiscardnoexcept |
This function returns a range object containing all the nodes in a word graph.
noexcept
and is guaranteed never to throw.
|
nodiscard |
This function returns the total number of edges (i.e. values s
and a
such that target(s, a)
is not UNDEFINED) in the word graph.
size_type
.m
is number_of_nodes() and n
is out_degree(). This function returns the number of edges incident to the given source node s
.
s | the node. |
size_type
.LibsemigroupsException | if s is not a node. |
n
is out_degree(). This function returns the number of edges incident to the given source node s
.
s | the node. |
size_type
.n
is out_degree().s
is actually a node in the word graph.
|
inlinenodiscardnoexcept |
This function returns the number of nodes in the word graph.
noexcept
and is guaranteed never to throw.
|
inlinenodiscard |
This function returns true
if *this
and that
are not equal, and false
if they are equal.
that | the word graph for comparison. |
*this
and that
are not equal.
|
inlinenodiscard |
This function returns true
if *this
is less than that
. This operator defines a linear order on word graphs.
that | the word graph for comparison. |
*this
is strictly less than that
.
|
inlinenodiscard |
This function returns true
if *this
is less or equal to that
. This operator defines a linear order on word graphs.
that | the word graph for comparison. |
*this
is less than or equal to that
.
|
inlinenodiscard |
This function returns true
if *this
and that
are equal, and false
if not.
that | the word graph for comparison. |
*this
and that
are equal.
|
inlinenodiscard |
This function returns true
if *this
is greater than that
. This operator defines a linear order on word graphs.
that | the word graph for comparison. |
*this
is strictly greater than that
.
|
inlinenodiscard |
This function returns true
if *this
is greater or equal to that
. This operator defines a linear order on word graphs.
that | the word graph for comparison. |
*this
is greater than or equal to that
.
|
inlinenodiscardnoexcept |
This function returns the number of edge labels in the word graph.
size_type
.noexcept
and is guaranteed never to throw.
|
static |
This function constructs a random word graph with number_of_nodes
nodes and out-degree out_degree
.
number_of_nodes | the number of nodes. |
out_degree | the out-degree of every node. |
mt | a std::mt19937 used as a random source (defaults to: std::mt19937(std::random_device()())). |
LibsemigroupsException | if any of the following hold:
|
m
is the number of nodes, and n
is the out-degree of the word graph.
|
inline |
Set every target of every source with every possible label to UNDEFINED.
*this
.m
is the number of nodes and n
is the out-degree. WordGraph & remove_label | ( | label_type | a | ) |
This function removes the label a
from a WordGraph object in-place. This reduces the out-degree by 1
.
a | the label to remove. |
*this
.LibsemigroupsException | if a is out of range. |
WordGraph & remove_label_no_checks | ( | label_type | a | ) |
This function removes the label a
from a WordGraph object in-place. This reduces the out-degree by 1
.
a | the label to remove. |
*this
.a
is not out of range. WordGraph & remove_target | ( | node_type | s, |
label_type | a ) |
This function removes the edge with source node s
labelled by a
.
s | the source node. |
a | the label of the edge from s . |
*this
.LibsemigroupsException | if s or a is out of range. |
|
inline |
This function removes the edge with source node s
labelled by a
.
s | the source node. |
a | the label of the edge from s . |
*this
.This function ensures that the word graph has capacity for m
nodes and n
labels.
m | the number of nodes. |
n | the out-degree. |
*this
.m
is the number of nodes and n
is the out-degree.this
, any iterators, pointers or references pointing into this
may be invalidated by a call to this function.WordGraph & swap_targets | ( | node_type | m, |
node_type | n, | ||
label_type | a ) |
This function swaps the target of the edge from the node m
labelled a
with the target of the edge from the node n
labelled a
.
m | the first node. |
n | the second node. |
a | the label. |
*this
.LibsemigroupsException | if m , n , or a are out of range. |
|
inline |
This function swaps the target of the edge from the node m
labelled a
with the target of the edge from the node n
labelled a
.
m | the first node. |
n | the second node. |
a | the label. |
*this
.WordGraph & target | ( | node_type | s, |
label_type | a, | ||
node_type | t ) |
If s
and t
are nodes in this
, and a
is in the range [0, out_degree())
, then this function adds an edge from a
to b
labelled a
.
s | the source node. |
a | the label of the edge. |
t | the range node. |
*this
.LibsemigroupsException | if s , a , or t is not valid. If an exception is thrown, this is guaranteed not to be modified (strong exception guarantee). |
|
nodiscard |
This function returns the target of the edge with source node source
and label a
.
source | the node. |
a | the label. |
source
via the edge labelled a
, or UNDEFINED; both are values of type node_type.LibsemigroupsException | if source or a is not valid. |
|
inlinenodiscard |
This function returns the the target of the edge with source node s
and label a
.
s | the node. |
a | the label. |
s
via the edge labelled a
, or UNDEFINED; both are values of type node_type.s
or a
is valid.
|
inline |
This function adds an edge from the node s
to the node t
with label a
.
s | the source node. |
a | the label of the edge from s to t . |
t | the target node. |
*this
.
|
nodiscard |
This function returns a range object containing all the targets of edges with source source
.
source | the source node. |
LibsemigroupsException | if source is out of range (i.e. it is greater than or equal to number_of_nodes) |
|
inlinenodiscardnoexcept |
This function returns a range object containing all the targets of edges with source source
.
source | the source node. |
noexcept
and is guaranteed never to throw.source
is a valid node of the word graph (i.e. it is not greater than or equal to number_of_nodes).