Helper functions for ActionDigraph¶
Overview¶
Defined in action-digraph-helper.hpp.
This page contains the documentation for helper function for the class
libsemigroups::ActionDigraph.
Full API¶
-
template<typename T>
node_type<T> libsemigroups::action_digraph_helper::follow_path(ActionDigraph<T> const &ad, node_type<T> const first, word_type const &path)¶ Find the node that a path starting at a given node leads to.
- Complexity
Linear in the length of
path.
- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to check.
first – the starting node.
path – the path to follow.
- Throws
LibsemigroupsException – if
firstis not a node in the digraph orpathcontains a value that is not an edge-label.- Returns
A value of type ActionDigraph::node_type. If one or more edges in
pathare not defined, then UNDEFINED is returned.
-
template<typename T>
node_type<T> libsemigroups::action_digraph_helper::follow_path_nc(ActionDigraph<T> const &ad, node_type<T> const from, word_type const &path) noexcept¶ Follow the path from a specified node labelled by a word.
This function returns the last node on the path in the action digraph
adstarting at the nodefromlabelled bypathor libsemigroups::UNDEFINED.- Complexity
At worst the length of
path.
Warning
No checks on the arguments of this function are performed.
- Template Parameters
T – the node type of the action digraph
- Parameters
ad – an action digraph
from – the source node
path – the word
- Throws
This – function is
noexceptand is guaranteed never to throw.- Returns
A value of tyep ActionDigraph::node_type.
-
template<typename T, typename S>
node_type<T> libsemigroups::action_digraph_helper::follow_path_nc(ActionDigraph<T> const &ad, node_type<T> const from, S first, S last) noexcept¶ Follow the path from a specified node labelled by a word.
This function returns the last node on the path in the action digraph
adstarting at the nodefromlabelled by \([first, last)\) or libsemigroups::UNDEFINED.- Complexity
At worst the distance from
firsttolast.
Warning
No checks on the arguments of this function are performed.
- Parameters
ad – an action digraph
from – the source node
first – iterator into a word
last – iterator into a word.
- Throws
This – function is
noexceptand is guaranteed never to throw.- Returns
A value of tyep ActionDigraph::node_type.
-
template<typename T, typename S>
std::pair<node_type<T>, S> libsemigroups::action_digraph_helper::last_node_on_path_nc(ActionDigraph<T> const &ad, node_type<T> from, S const &first, S const &last) noexcept¶ Returns the last node on the path labelled by a word and an iterator to the position in the word reached.
- Complexity
At worst the distance from
firsttolast.
Warning
No checks on the arguments of this function are performed.
- Template Parameters
T – the node type of the action digraph
S – the type of the iterators into a word
- Parameters
ad – an action digraph
from – the source node
first – iterator into a word
last – iterator into a word.
- Throws
This – function is
noexceptand is guaranteed never to throw.- Returns
A pair consisting of ActionDigraph::node_type and
S.
-
template<typename T>
bool libsemigroups::action_digraph_helper::is_acyclic(ActionDigraph<T> const &ad)¶ Check if a digraph is acyclic.
A digraph is acyclic if every directed cycle on the digraph is trivial.
- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
\(O(m + n)\) where \(m\) is the number of nodes in the ActionDigraph
adand \(n\) is the number of edges. Note that for ActionDigraph objects the number of edges is always at most \(mk\) where \(k\) is the ActionDigraph::out_degree.
- Example
ActionDigraph<size_t> ad; ad.add_nodes(2); ad.add_to_out_degree(1); ad.add_edge(0, 1, 0); ad.add_edge(1, 0, 0); action_digraph_helper::is_acyclic(ad); // returns false
- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to check.
- Returns
A value of type
bool.
-
template<typename T>
bool libsemigroups::action_digraph_helper::is_acyclic(ActionDigraph<T> const &ad, node_type<T> source)¶ Check if the subdigraph induced by the nodes reachable from a source node is acyclic.
A digraph is acyclic if every directed cycle on the digraph is trivial.
- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
\(O(m + n)\) where \(m\) is the number of nodes in the ActionDigraph
adand \(n\) is the number of edges. Note that for ActionDigraph objects the number of edges is always at most \(mk\) where \(k\) is the ActionDigraph::out_degree.
- Example
ActionDigraph<size_t> ad; ad.add_nodes(4); ad.add_to_out_degree(1); ad.add_edge(0, 1, 0); ad.add_edge(1, 0, 0); ad.add_edge(2, 3, 0); action_digraph_helper::is_acyclic(ad); // returns false action_digraph_helper::is_acyclic(ad, 0); // returns false action_digraph_helper::is_acyclic(ad, 1); // returns false action_digraph_helper::is_acyclic(ad, 2); // returns true action_digraph_helper::is_acyclic(ad, 3); // returns true
- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to check.
source – the source node.
- Returns
A value of type
bool.
-
template<typename T>
bool libsemigroups::action_digraph_helper::is_reachable(ActionDigraph<T> const &ad, node_type<T> const source, node_type<T> const target)¶ Check if there is a path from one node to another.
- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
\(O(m + n)\) where \(m\) is the number of nodes in the ActionDigraph
adand \(n\) is the number of edges. Note that for ActionDigraph objects the number of edges is always at most \(mk\) where \(k\) is the ActionDigraph::out_degree.- Example
ActionDigraph<size_t> ad; ad.add_nodes(4); ad.add_to_out_degree(1); ad.add_edge(0, 1, 0); ad.add_edge(1, 0, 0); ad.add_edge(2, 3, 0); action_digraph_helper::is_reachable(ad, 0, 1); // returns true action_digraph_helper::is_reachable(ad, 1, 0); // returns true action_digraph_helper::is_reachable(ad, 1, 2); // returns false action_digraph_helper::is_reachable(ad, 2, 3); // returns true action_digraph_helper::is_reachable(ad, 3, 2); // returns false
Note
If
sourceandtargetare equal, then, by convention, we considertargetto be reachable fromsource, via the empty path.- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to check.
source – the source node.
target – the source node.
- Returns
A value of type
bool.
-
template<typename T>
detail::topological_sort_type<T> libsemigroups::action_digraph_helper::topological_sort(ActionDigraph<T> const &ad)¶ Returns the nodes of the digraph in topological order (see below) if possible.
If it is not empty, the returned vector has the property that if an edge from a node
npoints to a nodem, thenmoccurs beforenin the vector.- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
\(O(m + n)\) where \(m\) is the number of nodes in the ActionDigraph
adand \(n\) is the number of edges. Note that for ActionDigraph objects the number of edges is always at most \(mk\) where \(k\) is the ActionDigraph::out_degree.
- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to check.
- Returns
A std::vector<ActionDigraph<T>::node_type> that contains the nodes of
adin topological order (if possible) and is otherwise empty.
-
template<typename T>
detail::topological_sort_type<T> libsemigroups::action_digraph_helper::topological_sort(ActionDigraph<T> const &ad, node_type<T> source)¶ Returns the nodes of the digraph reachable from a given node in topological order (see below) if possible.
If it is not empty, the returned vector has the property that if an edge from a node
npoints to a nodem, thenmoccurs beforenin the vector, and the last item in the vector issource.- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
At worst \(O(m + n)\) where \(m\) is the number of nodes in the subdigraph of those nodes reachable from
sourceand \(n\) is the number of edges.
- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to check.
source – the source node.
- Returns
A std::vector<ActionDigraph<T>::node_type> that contains the nodes of
adin topological order (if possible) and is otherwise empty.
-
template<typename T, typename U>
void libsemigroups::action_digraph_helper::add_cycle(ActionDigraph<T> &ad, U first, U last)¶ Adds a cycle involving the specified range of nodes.
- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
\(O(m)\) where \(m\) is the distance between
firstandlast.
Note
The edges added by this function are all labelled
0.- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
U – the type of an iterator pointing to nodes of an ActionDigraph
- Parameters
ad – the ActionDigraph object to add a cycle to.
first – a const iterator to nodes of
adlast – a const iterator to nodes of
ad
- Returns
(None)
-
template<typename T>
void libsemigroups::action_digraph_helper::add_cycle(ActionDigraph<T> &ad, size_t N)¶ Adds a cycle consisting of
Nnew nodes.- Exceptions
This function guarantees not to throw a LibsemigroupsException.
- Complexity
\(O(N)\) where \(N\) is the second parameter.
Note
The edges added by this function are all labelled
0.- Template Parameters
T – the type used as the template parameter for the ActionDigraph.
- Parameters
ad – the ActionDigraph object to add a cycle to.
N – the length of the cycle and number of new nodes to add.
- Returns
(None)