22#ifndef LIBSEMIGROUPS_WORD_GRAPH_HPP_
23#define LIBSEMIGROUPS_WORD_GRAPH_HPP_
35#include <unordered_set>
40#include "constants.hpp"
43#include "exception.hpp"
49#include "detail/containers.hpp"
50#include "detail/int-range.hpp"
51#include "detail/stl.hpp"
52#include "detail/uf.hpp"
54#ifdef LIBSEMIGROUPS_EIGEN_ENABLED
55#include "detail/eigen.hpp"
81 template <
typename Node>
84 "the template parameter Node must be an integral type!");
87 "the template parameter Node must be an unsigned integral type!");
90 friend class WordGraph;
106#ifdef LIBSEMIGROUPS_EIGEN_ENABLED
109 = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>;
117 typename detail::IntRange<Node>::const_iterator;
121 typename detail::IntRange<Node>::const_reverse_iterator;
125 typename detail::DynamicArray2<Node>::const_iterator;
170 WordGraph(WordGraph
const&);
181 template <
typename OtherNode>
182 WordGraph(WordGraph<OtherNode>
const& that);
204 template <
typename OtherNode>
205 WordGraph&
init(WordGraph<OtherNode>
const& that);
208 WordGraph(WordGraph&&);
357 _dynamic_array_2.set(s, a, t);
465 _dynamic_array_2.swap(m, a, n, a);
502 [[nodiscard]]
bool operator==(WordGraph
const& that)
const {
503 return _dynamic_array_2 == that._dynamic_array_2;
522 [[nodiscard]]
bool operator!=(WordGraph
const& that)
const {
542 [[nodiscard]]
bool operator<(WordGraph
const& that)
const {
543 return _dynamic_array_2 < that._dynamic_array_2;
562 [[nodiscard]]
bool operator<=(WordGraph
const& that)
const {
563 return _dynamic_array_2 <= that._dynamic_array_2;
582 [[nodiscard]]
bool operator>(WordGraph
const& that)
const {
583 return _dynamic_array_2 > that._dynamic_array_2;
602 [[nodiscard]]
bool operator>=(WordGraph
const& that)
const {
603 return _dynamic_array_2 > that._dynamic_array_2;
667 return _dynamic_array_2.get(s, a);
752#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
754 _num_active_nodes = val;
758 [[nodiscard]]
size_type inline number_of_active_nodes() const noexcept {
759 return _num_active_nodes;
909 return _dynamic_array_2.cbegin_row(source);
957 return _dynamic_array_2.cbegin_row(source) + _degree;
969 [[nodiscard]]
auto nodes() const noexcept {
983 [[nodiscard]]
auto labels() const noexcept {
984 return rx::seq<label_type>() | rx::take(
out_degree());
1004 [[nodiscard]] rx::iterator_range<const_iterator_targets>
1022 [[nodiscard]] rx::iterator_range<const_iterator_targets>
1118 template <
typename Iterator,
1119 typename = std::enable_if_t<detail::IsIterator<Iterator>::value>>
1143 template <
typename Iterator,
1144 typename = std::enable_if_t<detail::IsIterator<Iterator>::value>>
1178#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1189 return permute_nodes_no_checks(p, q, p.
size());
1195 template <
typename S>
1196 void apply_row_permutation(S
const& p) {
1197 _dynamic_array_2.apply_row_permutation(p);
1209 mutable detail::DynamicArray2<Node> _dynamic_array_2;
1250 template <
typename Node,
typename Iterator>
1270 template <
typename Node>
1291 template <
typename Node>
1304 template <
typename Node>
1333 template <
typename Node>
1363 template <
typename Node>
1400 template <
typename Node1,
typename Node2,
typename Iterator>
1435 template <
typename Node1,
typename Node2>
1439 static_assert(
sizeof(Node2) <=
sizeof(Node1));
1469 template <
typename Node1,
typename Node2,
typename Iterator>
1473 Iterator last)
noexcept;
1501 template <
typename Node1,
typename Node2>
1505 static_assert(
sizeof(Node2) <=
sizeof(Node1));
1542 template <
typename Node>
1590 template <
typename Node1,
typename Node2>
1623 template <
typename Node1,
typename Node2>
1667 template <
typename Node,
1672 Iterator1 first_node,
1673 Iterator2 last_node,
1674 Iterator3 first_rule,
1675 Iterator3 last_rule);
1723 std::enable_if_t<!std::is_same_v<std::decay_t<Iterator3>,
word_type>>>
1725 Iterator1 first_node,
1726 Iterator2 last_node,
1727 Iterator3 first_rule,
1728 Iterator3 last_rule);
1761 template <
typename Node,
typename Iterator1,
typename Iterator2>
1763 Iterator1 first_node,
1764 Iterator2 last_node,
1803 template <
typename Node,
typename Iterator1,
typename Iterator2>
1805 Iterator1 first_node,
1806 Iterator2 last_node,
1841 template <
typename Node,
typename Iterator1,
typename Iterator2>
1843 Iterator1 first_node,
1844 Iterator2 last_node);
1875 template <
typename Node,
typename Iterator1,
typename Iterator2>
1877 Iterator1 first_node,
1878 Iterator2 last_node);
1897 template <
typename Node>
1899 return wg.number_of_edges() == wg.number_of_nodes() * wg.out_degree();
1923 template <
typename Node>
1975 template <
typename Node1,
typename Node2>
2011 template <
typename Node1,
typename Node2>
2049 template <
typename Node>
2078 template <
typename Node1,
typename Node2,
typename Iterator>
2083 Iterator last)
noexcept;
2109 template <
typename Node1,
typename Node2,
typename Iterator>
2137 template <
typename Node1,
typename Node2>
2164 template <
typename Node1,
typename Node2>
2197 template <
typename Node1,
typename Node2>
2201 template <
typename Node1,
typename Node2>
2226 template <
typename Node1,
typename Node2>
2230 template <
typename Node1,
typename Node2>
2254 template <
typename Node1,
typename Node2>
2255 [[nodiscard]]
size_t
2278 template <
typename Node1,
typename Node2>
2279 [[nodiscard]]
size_t
2306 template <
typename Node>
2331 template <
typename Node1,
typename Node2>
2354 template <
typename Node1,
typename Node2>
2377 template <
typename Node1,
typename Node2>
2400 template <
typename Node1,
typename Node2>
2427 template <
typename Graph>
2454 template <
typename Graph>
2473 template <
typename Node>
2490 template <
typename Node>
2514 template <
typename Node,
typename Iterator>
2531 template <
typename Node>
2547 template <
typename Node>
2566 template <
typename Node,
typename Iterator>
2584 template <
typename Node1,
typename Node2>
2603 template <
typename Node,
typename Iterator1,
typename Iterator2>
2631 template <
typename Node>
2660 template <
typename Node1,
typename Node2>
2668 template <
typename T>
2671 template <
typename Node>
2686 template <
typename T>
2687 static constexpr bool IsWordGraph = detail::IsWordGraphHelper<T>::value;
2708 template <
typename Node>
2751 template <
typename Return>
2752 [[nodiscard]] std::enable_if_t<IsWordGraph<Return>, Return>
2761 template <
typename Return>
2762 [[nodiscard]] std::enable_if_t<IsWordGraph<Return>, Return>
2767 template <
typename Sub
class>
2768 class JoinerMeeterCommon {
2770 template <
typename Node1,
typename Node2>
2777 template <
typename Node>
2784 template <
typename Node>
2788 return call_no_checks(
2789 xy, x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2792 template <
typename Node,
typename... Args>
2793 [[nodiscard]]
auto call_no_checks(WordGraph<Node>
const& x,
2795 -> std::enable_if_t<
sizeof...(Args) % 2 == 1, WordGraph<Node>> {
2800 static_cast<Subclass&
>(*this).call_no_checks(
2809 template <
typename Node>
2810 void operator()(WordGraph<Node>& xy,
2811 WordGraph<Node>
const& x,
2813 WordGraph<Node>
const& y,
2815 throw_if_bad_args(x, xroot, y, yroot);
2816 call_no_checks(xy, x, xroot, y, yroot);
2819 template <
typename Node>
2820 void operator()(WordGraph<Node>& xy,
2821 WordGraph<Node>
const& x,
2822 WordGraph<Node>
const& y) {
2823 return operator()(xy, x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2826 template <
typename Node,
typename... Args>
2827 [[nodiscard]]
auto operator()(WordGraph<Node>
const& x, Args&&... args)
2828 -> std::enable_if_t<
sizeof...(Args) % 2 == 1, WordGraph<Node>> {
2837 template <
typename Node1,
typename Node2>
2838 bool is_subrelation_no_checks(WordGraph<Node1>
const& x,
2840 WordGraph<Node1>
const& y,
2843 template <
typename Node>
2844 bool is_subrelation_no_checks(WordGraph<Node>
const& x,
2845 WordGraph<Node>
const& y) {
2846 return is_subrelation_no_checks(
2847 x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2854 template <
typename Node1,
typename Node2>
2855 bool is_subrelation(WordGraph<Node1>
const& x,
2857 WordGraph<Node1>
const& y,
2859 throw_if_bad_args(x, xroot, y, yroot);
2860 return is_subrelation_no_checks(x, xroot, y, yroot);
2863 template <
typename Node>
2864 bool is_subrelation(WordGraph<Node>
const& x, WordGraph<Node>
const& y) {
2865 return is_subrelation(x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2885 class Joiner :
public detail::JoinerMeeterCommon<Joiner> {
2891 template <
typename Node>
2893 size_t xnum_nodes_reachable_from_root,
2898 template <
typename Node>
2900 size_t xnum_nodes_reachable_from_root,
2903 size_t ynum_nodes_reachable_from_root,
2962 template <
typename Node>
2965 size_t xnum_nodes_reachable_from_root,
2968 size_t ynum_nodes_reachable_from_root,
3005 template <
typename Node1,
typename Node2>
3008 size_t xnum_nodes_reachable_from_root,
3011 size_t ynum_nodes_reachable_from_root,
3013#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
3037 template <
typename Node>
3063 template <
typename Node>
3087 template <
typename Node,
typename... Args>
3115 template <
typename Node>
3143 template <
typename Node>
3165 template <
typename Node,
typename... Args>
3198 template <
typename Node1,
typename Node2>
3226 template <
typename Node>
3262 template <
typename Node1,
typename Node2>
3292 template <
typename Node>
3297 using detail::JoinerMeeterCommon<
Joiner>::operator();
3316 class Meeter :
public detail::JoinerMeeterCommon<Meeter> {
3354 template <
typename Node>
3357 size_t xnum_nodes_reachable_from_root,
3360 size_t ynum_nodes_reachable_from_root,
3366 template <
typename Node1,
typename Node2>
3369 size_t xnum_nodes_reachable_from_root,
3372 size_t ynum_nodes_reachable_from_root,
3375#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
3378 template <
typename Node>
3387 template <
typename Node>
3411 template <
typename Node,
typename... Args>
3416 template <
typename Node>
3425 template <
typename Node>
3447 template <
typename Node,
typename... Args>
3452 template <
typename Node1,
typename Node2>
3460 template <
typename Node>
3466 template <
typename Node1,
typename Node2>
3474 template <
typename Node>
3478 using detail::JoinerMeeterCommon<
Meeter>::operator();
3498 template <
typename Node>
3516 return "<Meeter of word graphs>";
3534 return "<Joiner of word graphs>";
3556 template <
typename Node>
3563#include "word-graph.tpp"
A representation of a graph in the DOT language of Graphviz.
Definition dot.hpp:115
Class representing a collection of spanning trees of a word graph.
Definition forest.hpp:42
Class for taking joins of word graphs.
Definition word-graph.hpp:2885
bool is_subrelation_no_checks(WordGraph< Node > const &x, WordGraph< Node > const &y)
Check if the language accepted by one word graph is contained in that defined by another word graph.
auto call_no_checks(WordGraph< Node > const &x, Args &&... args)
Returns a word graph containing the join/meet of two given word graphs.
auto operator()(WordGraph< Node > const &x, Args &&... args)
Returns a word graph containing the join/meet of two given word graphs.
Joiner(Joiner const &)
Default copy constructor.
void call_no_checks(WordGraph< Node > &xy, WordGraph< Node > const &x, Node xroot, WordGraph< Node > const &y, Node yroot)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
bool is_subrelation(WordGraph< Node1 > const &x, Node2 xroot, WordGraph< Node1 > const &y, Node2 yroot)
Check if the language accepted by one word graph is contained in that defined by another word graph.
Joiner(Joiner &&)
Default move constructor.
bool is_subrelation_no_checks(WordGraph< Node1 > const &x, Node2 xroot, WordGraph< Node1 > const &y, Node2 yroot)
Check if the language accepted by one word graph is contained in that defined by another word graph.
Joiner()
Default constructor.
Joiner & operator=(Joiner const &)
Default copy assignment operator.
void call_no_checks(WordGraph< Node > &xy, WordGraph< Node > const &x, WordGraph< Node > const &y)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
Joiner & operator=(Joiner &&)
Default move assignment operator.
bool is_subrelation(WordGraph< Node > const &x, WordGraph< Node > const &y)
Check if the language accepted by one word graph is contained in that defined by another word graph.
void operator()(WordGraph< Node > &xy, WordGraph< Node > const &x, WordGraph< Node > const &y)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
void call_no_checks(WordGraph< Node > &xy, WordGraph< Node > const &x, size_t xnum_nodes_reachable_from_root, Node xroot, WordGraph< Node > const &y, size_t ynum_nodes_reachable_from_root, Node yroot)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
bool is_subrelation_no_checks(WordGraph< Node1 > const &x, size_t xnum_nodes_reachable_from_root, Node2 xroot, WordGraph< Node1 > const &y, size_t ynum_nodes_reachable_from_root, Node2 yroot)
Check if the language accepted by one word graph is contained in that accepted by another word graph.
void operator()(WordGraph< Node > &xy, WordGraph< Node > const &x, Node xroot, WordGraph< Node > const &y, Node yroot)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
Class for taking meets of word graphs.
Definition word-graph.hpp:3316
bool is_subrelation_no_checks(WordGraph< Node > const &x, WordGraph< Node > const &y)
Check if the language accepted by one word graph is contained in that defined by another word graph.
auto call_no_checks(WordGraph< Node > const &x, Args &&... args)
Returns a word graph containing the join/meet of two given word graphs.
auto operator()(WordGraph< Node > const &x, Args &&... args)
Returns a word graph containing the join/meet of two given word graphs.
void call_no_checks(WordGraph< Node > &xy, WordGraph< Node > const &x, Node xroot, WordGraph< Node > const &y, Node yroot)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
bool is_subrelation(WordGraph< Node1 > const &x, Node2 xroot, WordGraph< Node1 > const &y, Node2 yroot)
Check if the language accepted by one word graph is contained in that defined by another word graph.
bool is_subrelation_no_checks(WordGraph< Node1 > const &x, Node2 xroot, WordGraph< Node1 > const &y, Node2 yroot)
Check if the language accepted by one word graph is contained in that defined by another word graph.
Meeter & operator=(Meeter const &)
Default copy assignment operator.
void call_no_checks(WordGraph< Node > &xy, WordGraph< Node > const &x, WordGraph< Node > const &y)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
Meeter()
Default constructor.
Meeter & operator=(Meeter &&)
Default move assignment operator.
bool is_subrelation(WordGraph< Node > const &x, WordGraph< Node > const &y)
Check if the language accepted by one word graph is contained in that defined by another word graph.
void operator()(WordGraph< Node > &xy, WordGraph< Node > const &x, WordGraph< Node > const &y)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
Meeter(Meeter &&)
Default move constructor.
void call_no_checks(WordGraph< Node > &xy, WordGraph< Node > const &x, size_t xnum_nodes_reachable_from_root, Node xroot, WordGraph< Node > const &y, size_t ynum_nodes_reachable_from_root, Node yroot)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
Meeter(Meeter const &)
Default copy constructor.
bool is_subrelation_no_checks(WordGraph< Node1 > const &x, size_t xnum_nodes_reachable_from_root, Node2 xroot, WordGraph< Node1 > const &y, size_t ynum_nodes_reachable_from_root, Node2 yroot)
Check if the language accepted by one word graph is contained in that accepted by another word graph.
void operator()(WordGraph< Node > &xy, WordGraph< Node > const &x, Node xroot, WordGraph< Node > const &y, Node yroot)
Replace the contents of a word graph with the join/meet of two given word graphs with respect to give...
Class for representing word graphs.
Definition word-graph.hpp:82
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > adjacency_matrix_type
Definition word-graph.hpp:108
bool operator<(WordGraph const &that) const
Check if a word graph is less than another.
Definition word-graph.hpp:541
element_index_type node_type
Definition word-graph.hpp:98
auto nodes() const noexcept
Returns a range object containing all nodes in a word graph.
Definition word-graph.hpp:968
auto labels_and_targets(node_type source) const
Returns a range object containing pairs consisting of edge labels and target nodes.
const_iterator_nodes cend_nodes() const noexcept
Returns a random access iterator pointing one-past-the-last node of the word graph.
Definition word-graph.hpp:859
WordGraph & disjoint_union_inplace(WordGraph< Node > const &that)
Unites a word graph in-place.
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.
WordGraph & remove_label(label_type a)
Removes a given label from the word graph.
WordGraph & swap_targets(node_type m, node_type n, label_type a)
Swaps the edge with specified label from one node with another.
size_type number_of_edges() const
Returns the number of edges.
bool operator>(WordGraph const &that) const
Check if a word graph is greater than another.
Definition word-graph.hpp:581
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 ...
Definition word-graph.hpp:907
element_index_type label_type
Definition word-graph.hpp:101
bool operator<=(WordGraph const &that) const
Check if a word graph is less than or equal to another.
Definition word-graph.hpp:561
auto labels_and_targets_no_checks(node_type source) const noexcept
Returns a range object containing pairs consisting of edge labels and target nodes.
Definition word-graph.hpp:1042
WordGraph & induced_subgraph(node_type first, node_type last)
Modify in-place to contain the subgraph induced by a range of nodes.
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.
Definition word-graph.hpp:1004
WordGraph & remove_all_targets()
Remove all of the edges in the word graph.
Definition word-graph.hpp:438
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 ...
WordGraph & disjoint_union_inplace_no_checks(WordGraph< Node > const &that)
Unites a word graph in-place.
WordGraph & remove_target(node_type s, label_type a)
Remove an edge from a node with a given label.
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.
Definition word-graph.hpp:463
bool operator>=(WordGraph const &that) const
Check if a word graph is greater than or equal to another.
Definition word-graph.hpp:601
bool operator!=(WordGraph const &that) const
Check if two word graphs are inequal.
Definition word-graph.hpp:521
auto labels() const noexcept
Returns a range object containing all labels of edges in a word graph.
Definition word-graph.hpp:982
WordGraph & reserve(size_type m, size_type n)
Ensures that the word graph has capacity for a given number of nodes, and out-degree.
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() -...
Definition word-graph.hpp:955
size_type out_degree() const noexcept
Definition word-graph.hpp:823
const_iterator_nodes cbegin_nodes() const noexcept
Returns a random access iterator pointing at the first node of the word graph.
Definition word-graph.hpp:841
bool operator==(WordGraph const &that) const
Check if two word graphs are equal.
Definition word-graph.hpp:501
typename detail::DynamicArray2< element_index_type >::const_iterator const_iterator_targets
Definition word-graph.hpp:123
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.
WordGraph & operator=(WordGraph const &)
Default copy assignment constructor.
WordGraph & target(node_type s, label_type a, node_type t)
Add an edge from one node to another with a given label.
WordGraph & add_nodes(size_type nr)
Add a number of new nodes.
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.
Definition word-graph.hpp:355
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() -...
WordGraph & init(size_type m=0, size_type n=0)
Re-initialize the word graph to have m nodes and out-degree n.
WordGraph & remove_target_no_checks(node_type s, label_type a)
Remove an edge from a node with a given label.
Definition word-graph.hpp:377
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.
typename detail::IntRange< element_index_type >::const_reverse_iterator const_reverse_iterator_nodes
Definition word-graph.hpp:119
WordGraph & remove_label_no_checks(label_type a)
Removes a given label from the word graph.
WordGraph & add_to_out_degree(size_type nr)
Add to the out-degree of every node.
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.
size_t hash_value() const
Returns a hash value.
Definition word-graph.hpp:616
size_type number_of_nodes() const noexcept
Definition word-graph.hpp:747
typename detail::IntRange< element_index_type >::const_iterator const_iterator_nodes
Definition word-graph.hpp:115
std::size_t size_type
Definition word-graph.hpp:104
WordGraph & induced_subgraph_no_checks(node_type first, node_type last)
Modify in-place to contain the subgraph induced by a range of nodes.
size_type number_of_edges_no_checks(node_type s) const
Returns the number of edges with given source node.
std::string to_human_readable_repr(AhoCorasick const &ac)
Return a string representation.
std::ostringstream & operator<<(std::ostringstream &os, BMat8 const &x)
Insertion operator.
Undefined const UNDEFINED
Value for something undefined.
std::conditional_t< R==0||C==0, DynamicIntMat< Scalar >, StaticIntMat< R, C, Scalar > > IntMat
Alias template for integer matrices.
Definition matrix.hpp:4287
enable_if_is_same< Return, Blocks > make(Container const &cont)
Check the arguments, construct a Blocks object, and check it.
Definition bipart.hpp:798
Order
The possible orderings of words and strings.
Definition order.hpp:48
@ shortlex
Definition order.hpp:54
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101
std::string to_input_string(WordGraph< Node > const &wg, std::string const &prefix="", std::string const &braces="{}", std::string const &suffix="")
Return a string that can be used to recreate a word graph.
static constexpr bool IsWordGraph
Helper variable template.
Definition word-graph.hpp:2687
Namespace containing helper functions for the WordGraph class.
Definition word-graph.hpp:1221
auto adjacency_matrix(WordGraph< Node > const &wg)
Returns the adjacency matrix of a word graph.
void spanning_tree_no_checks(WordGraph< Node1 > const &wg, Node2 root, Forest &f)
Replace the contents of a Forest by a spanning tree of the nodes reachable from a given node in a wor...
void throw_if_any_target_out_of_bounds(WordGraph< Node > const &wg)
Throws if the target of any edge is out of bounds.
void throw_if_node_out_of_bounds(WordGraph< Node1 > const &wg, Node2 n)
Throws if a node is out of bounds.
std::pair< Node1, Iterator > last_node_on_path(WordGraph< Node1 > const &wg, Node2 source, Iterator first, Iterator last)
Returns the last node on the path labelled by a word and an iterator to the position in the word reac...
bool is_strictly_cyclic(WordGraph< Node > const &wg)
Check if every node is reachable from some node.
std::unordered_set< Node1 > nodes_reachable_from(WordGraph< Node1 > const &wg, Node2 source)
Returns the std::unordered_set of nodes reachable from a given node in a word graph.
bool is_connected(WordGraph< Node > const &wg)
Check if a word graph is connected.
bool equal_to_no_checks(WordGraph< Node > const &x, WordGraph< Node > const &y, Node first, Node last)
Compares two word graphs on a range of nodes.
bool equal_to(WordGraph< Node > const &x, WordGraph< Node > const &y, Node first, Node last)
Compares two word graphs on a range of nodes.
size_t number_of_nodes_reachable_from(WordGraph< Node1 > const &wg, Node2 source)
Returns the number of nodes reachable from a given node in a word graph.
Definition word-graph.hpp:2256
bool is_reachable(WordGraph< Node1 > const &wg, Node2 source, Node2 target)
Check if there is a path from one node to another.
bool is_compatible(WordGraph< Node > const &wg, Iterator1 first_node, Iterator2 last_node, Iterator3 first_rule, Iterator3 last_rule)
Check if a word graph is compatible with some relations at a range of nodes.
std::vector< Node > topological_sort(WordGraph< Node > const &wg)
Returns the nodes of the word graph in topological order (see below) if possible.
bool is_complete(WordGraph< Node > const &wg, Iterator1 first_node, Iterator2 last_node)
Check if every node in a range has exactly WordGraph::out_degree out-edges.
std::pair< Node1, Iterator > last_node_on_path_no_checks(WordGraph< Node1 > const &wg, Node2 source, Iterator first, Iterator last) noexcept
Returns the last node on the path labelled by a word and an iterator to the position in the word reac...
std::unordered_set< Node1 > nodes_reachable_from_no_checks(WordGraph< Node1 > const &wg, Node2 source)
Returns the std::unordered_set of nodes reachable from a given node in a word graph.
WordGraph< Node > random_acyclic(size_t number_of_nodes, size_t out_degree, std::mt19937 mt=std::mt19937(std::random_device()()))
Construct a random connected acyclic word graph with given number of nodes, and out-degree.
void throw_if_label_out_of_bounds(WordGraph< Node > const &wg, typename WordGraph< Node >::label_type a)
Throws if a label is out of bounds.
void add_cycle(WordGraph< Node > &wg, size_t N)
Adds a cycle consisting of N new nodes.
Definition word-graph.hpp:1271
bool is_compatible_no_checks(WordGraph< Node > const &wg, Iterator1 first_node, Iterator2 last_node, Iterator3 first_rule, Iterator3 last_rule)
Check if a word graph is compatible with some relations at a range of nodes.
bool is_reachable_no_checks(WordGraph< Node1 > const &wg, Node2 source, Node2 target)
Check if there is a path from one node to another.
bool standardize(Graph &wg, Forest &f, Order val)
Standardizes a word graph in-place.
size_t number_of_nodes_reachable_from_no_checks(WordGraph< Node1 > const &wg, Node2 source)
Returns the number of nodes reachable from a given node in a word graph.
Definition word-graph.hpp:2280
bool is_complete_no_checks(WordGraph< Node > const &wg, Iterator1 first_node, Iterator2 last_node)
Check if every node in a range has exactly WordGraph::out_degree out-edges.
Node1 follow_path_no_checks(WordGraph< Node1 > const &wg, Node2 from, Iterator first, Iterator last) noexcept
Follow the path from a specified node labelled by a word.
bool is_standardized(WordGraph< Node > const &wg, Order val=Order::shortlex)
Check if a word graph is standardized.
bool is_acyclic(WordGraph< Node > const &wg)
Check if a word graph is acyclic.
void spanning_tree(WordGraph< Node1 > const &wg, Node2 root, Forest &f)
Replace the contents of a Forest by a spanning tree of the nodes reachable from a given node in a wor...
Node1 follow_path(WordGraph< Node1 > const &wg, Node2 source, Iterator first, Iterator last)
Find the node that a path starting at a given node leads to (if any).
void add_cycle_no_checks(WordGraph< Node > &wg, Iterator first, Iterator last)
Adds a cycle involving the specified range of nodes to a word graph.
Dot dot(WordGraph< Node > const &wg)
Returns a Dot object representing a word graph.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44