22#ifndef LIBSEMIGROUPS_WORD_GRAPH_HPP_
23#define LIBSEMIGROUPS_WORD_GRAPH_HPP_
35#include <unordered_set>
40#include "constants.hpp"
43#include "exception.hpp"
45#include "is_specialization_of.hpp"
50#include "detail/containers.hpp"
51#include "detail/int-range.hpp"
52#include "detail/stl.hpp"
53#include "detail/uf.hpp"
55#ifdef LIBSEMIGROUPS_EIGEN_ENABLED
56#include "detail/eigen.hpp"
82 template <
typename Node>
85 "the template parameter Node must be an integral type!");
88 "the template parameter Node must be an unsigned integral type!");
91 friend class WordGraph;
107#ifdef LIBSEMIGROUPS_EIGEN_ENABLED
110 = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>;
118 typename detail::IntRange<Node>::const_iterator;
122 typename detail::IntRange<Node>::const_reverse_iterator;
126 typename detail::DynamicArray2<Node>::const_iterator;
133 mutable detail::DynamicArray2<Node> _dynamic_array_2;
189 WordGraph(WordGraph
const&);
200 template <
typename OtherNode>
201 WordGraph(WordGraph<OtherNode>
const& that);
223 template <
typename OtherNode>
224 WordGraph&
init(WordGraph<OtherNode>
const& that);
227 WordGraph(WordGraph&&);
376 _dynamic_array_2.set(s, a, t);
484 _dynamic_array_2.swap(m, a, n, a);
521 [[nodiscard]]
bool operator==(WordGraph
const& that)
const {
522 return _dynamic_array_2 == that._dynamic_array_2;
541 [[nodiscard]]
bool operator!=(WordGraph
const& that)
const {
561 [[nodiscard]]
bool operator<(WordGraph
const& that)
const {
562 return _dynamic_array_2 < that._dynamic_array_2;
581 [[nodiscard]]
bool operator<=(WordGraph
const& that)
const {
582 return _dynamic_array_2 <= that._dynamic_array_2;
601 [[nodiscard]]
bool operator>(WordGraph
const& that)
const {
602 return _dynamic_array_2 > that._dynamic_array_2;
621 [[nodiscard]]
bool operator>=(WordGraph
const& that)
const {
622 return _dynamic_array_2 > that._dynamic_array_2;
686 return _dynamic_array_2.get(s, a);
771#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
773 _num_active_nodes = val;
777 [[nodiscard]]
size_type inline number_of_active_nodes() const noexcept {
778 return _num_active_nodes;
928 return _dynamic_array_2.cbegin_row(source);
976 return _dynamic_array_2.cbegin_row(source) + _degree;
988 [[nodiscard]]
auto nodes() const noexcept {
1002 [[nodiscard]]
auto labels() const noexcept {
1003 return rx::seq<label_type>() | rx::take(
out_degree());
1023 [[nodiscard]] rx::iterator_range<const_iterator_targets>
1041 [[nodiscard]] rx::iterator_range<const_iterator_targets>
1137 template <
typename Iterator,
1138 typename = std::enable_if_t<detail::IsIterator<Iterator>::value>>
1162 template <
typename Iterator,
1163 typename = std::enable_if_t<detail::IsIterator<Iterator>::value>>
1197#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1208 return permute_nodes_no_checks(p, q, p.
size());
1213 return permute_nodes_no_checks(p, q, p.
size());
1256 template <
typename Node,
typename Iterator>
1276 template <
typename Node>
1297 template <
typename Node>
1310 template <
typename Node>
1339 template <
typename Node>
1369 template <
typename Node>
1406 template <
typename Node1,
typename Node2,
typename Iterator>
1441 template <
typename Node1,
typename Node2>
1445 static_assert(
sizeof(Node2) <=
sizeof(Node1));
1475 template <
typename Node1,
typename Node2,
typename Iterator>
1479 Iterator last)
noexcept;
1507 template <
typename Node1,
typename Node2>
1511 static_assert(
sizeof(Node2) <=
sizeof(Node1));
1548 template <
typename Node>
1596 template <
typename Node1,
typename Node2>
1629 template <
typename Node1,
typename Node2>
1677 template <
typename Node,
1682 Iterator1 first_node,
1683 Iterator2 last_node,
1684 Iterator3 first_rule,
1685 Iterator3 last_rule);
1733 std::enable_if_t<!std::is_same_v<std::decay_t<Iterator3>,
word_type>>>
1735 Iterator1 first_node,
1736 Iterator2 last_node,
1737 Iterator3 first_rule,
1738 Iterator3 last_rule);
1771 template <
typename Node,
typename Iterator1,
typename Iterator2>
1773 Iterator1 first_node,
1774 Iterator2 last_node,
1813 template <
typename Node,
typename Iterator1,
typename Iterator2>
1815 Iterator1 first_node,
1816 Iterator2 last_node,
1851 template <
typename Node,
typename Iterator1,
typename Iterator2>
1853 Iterator1 first_node,
1854 Iterator2 last_node);
1885 template <
typename Node,
typename Iterator1,
typename Iterator2>
1887 Iterator1 first_node,
1888 Iterator2 last_node);
1907 template <
typename Node>
1909 return wg.number_of_edges() == wg.number_of_nodes() * wg.out_degree();
1933 template <
typename Node>
1985 template <
typename Node1,
typename Node2>
2021 template <
typename Node1,
typename Node2>
2059 template <
typename Node>
2088 template <
typename Node1,
typename Node2,
typename Iterator>
2093 Iterator last)
noexcept;
2120 template <
typename Node1,
typename Node2,
typename Iterator>
2148 template <
typename Node1,
typename Node2>
2175 template <
typename Node1,
typename Node2>
2208 template <
typename Node1,
typename Node2>
2232 template <
typename Node1,
typename Node2>
2257 template <
typename Node1,
typename Node2>
2282 template <
typename Node1,
typename Node2>
2306 template <
typename Node1,
typename Node2>
2307 [[nodiscard]]
size_t
2330 template <
typename Node1,
typename Node2>
2331 [[nodiscard]]
size_t
2358 template <
typename Node>
2383 template <
typename Node1,
typename Node2>
2406 template <
typename Node1,
typename Node2>
2429 template <
typename Node1,
typename Node2>
2452 template <
typename Node1,
typename Node2>
2479 template <
typename Graph>
2506 template <
typename Graph>
2525 template <
typename Node>
2542 template <
typename Node>
2566 template <
typename Node,
typename Iterator>
2583 template <
typename Node>
2599 template <
typename Node>
2618 template <
typename Node,
typename Iterator>
2636 template <
typename Node1,
typename Node2>
2655 template <
typename Node,
typename Iterator1,
typename Iterator2>
2683 template <
typename Node>
2712 template <
typename Node1,
typename Node2>
2731 template <
typename Thing>
2754 template <
typename Node>
2798 template <
typename Return>
2799 [[nodiscard]] std::enable_if_t<is_specialization_of_v<Return, WordGraph>,
2810 template <
typename Return>
2811 [[nodiscard]] std::enable_if_t<is_specialization_of_v<Return, WordGraph>,
2817 template <
typename Sub
class>
2818 class JoinerMeeterCommon {
2820 template <
typename Node1,
typename Node2>
2827 template <
typename Node>
2834 template <
typename Node>
2838 return call_no_checks(
2839 xy, x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2842 template <
typename Node,
typename... Args>
2843 [[nodiscard]]
auto call_no_checks(WordGraph<Node>
const& x,
2845 -> std::enable_if_t<
sizeof...(Args) % 2 == 1, WordGraph<Node>> {
2850 static_cast<Subclass&
>(*this).call_no_checks(
2859 template <
typename Node>
2860 void operator()(WordGraph<Node>& xy,
2861 WordGraph<Node>
const& x,
2863 WordGraph<Node>
const& y,
2865 throw_if_bad_args(x, xroot, y, yroot);
2866 call_no_checks(xy, x, xroot, y, yroot);
2869 template <
typename Node>
2870 void operator()(WordGraph<Node>& xy,
2871 WordGraph<Node>
const& x,
2872 WordGraph<Node>
const& y) {
2873 return operator()(xy, x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2876 template <
typename Node,
typename... Args>
2877 [[nodiscard]]
auto operator()(WordGraph<Node>
const& x, Args&&... args)
2878 -> std::enable_if_t<
sizeof...(Args) % 2 == 1, WordGraph<Node>> {
2887 template <
typename Node1,
typename Node2>
2888 bool is_subrelation_no_checks(WordGraph<Node1>
const& x,
2890 WordGraph<Node1>
const& y,
2893 template <
typename Node>
2894 bool is_subrelation_no_checks(WordGraph<Node>
const& x,
2895 WordGraph<Node>
const& y) {
2896 return is_subrelation_no_checks(
2897 x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2904 template <
typename Node1,
typename Node2>
2905 bool is_subrelation(WordGraph<Node1>
const& x,
2907 WordGraph<Node1>
const& y,
2909 throw_if_bad_args(x, xroot, y, yroot);
2910 return is_subrelation_no_checks(x, xroot, y, yroot);
2913 template <
typename Node>
2914 bool is_subrelation(WordGraph<Node>
const& x, WordGraph<Node>
const& y) {
2915 return is_subrelation(x,
static_cast<Node
>(0), y,
static_cast<Node
>(0));
2935 class Joiner :
public detail::JoinerMeeterCommon<Joiner> {
2941 template <
typename Node>
2943 size_t xnum_nodes_reachable_from_root,
2948 template <
typename Node>
2950 size_t xnum_nodes_reachable_from_root,
2953 size_t ynum_nodes_reachable_from_root,
3012 template <
typename Node>
3015 size_t xnum_nodes_reachable_from_root,
3018 size_t ynum_nodes_reachable_from_root,
3055 template <
typename Node1,
typename Node2>
3058 size_t xnum_nodes_reachable_from_root,
3061 size_t ynum_nodes_reachable_from_root,
3063#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
3087 template <
typename Node>
3113 template <
typename Node>
3137 template <
typename Node,
typename... Args>
3165 template <
typename Node>
3193 template <
typename Node>
3215 template <
typename Node,
typename... Args>
3248 template <
typename Node1,
typename Node2>
3276 template <
typename Node>
3312 template <
typename Node1,
typename Node2>
3342 template <
typename Node>
3347 using detail::JoinerMeeterCommon<
Joiner>::operator();
3366 class Meeter :
public detail::JoinerMeeterCommon<Meeter> {
3404 template <
typename Node>
3407 size_t xnum_nodes_reachable_from_root,
3410 size_t ynum_nodes_reachable_from_root,
3416 template <
typename Node1,
typename Node2>
3419 size_t xnum_nodes_reachable_from_root,
3422 size_t ynum_nodes_reachable_from_root,
3425#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
3428 template <
typename Node>
3437 template <
typename Node>
3461 template <
typename Node,
typename... Args>
3466 template <
typename Node>
3475 template <
typename Node>
3497 template <
typename Node,
typename... Args>
3502 template <
typename Node1,
typename Node2>
3510 template <
typename Node>
3516 template <
typename Node1,
typename Node2>
3524 template <
typename Node>
3528 using detail::JoinerMeeterCommon<
Meeter>::operator();
3548 template <
typename Node>
3566 return "<Meeter of word graphs>";
3584 return "<Joiner of word graphs>";
3606 template <
typename Node>
3613#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:2935
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:3366
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:83
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > adjacency_matrix_type
Definition word-graph.hpp:109
bool operator<(WordGraph const &that) const
Check if a word graph is less than another.
Definition word-graph.hpp:560
element_index_type node_type
Definition word-graph.hpp:99
auto nodes() const noexcept
Returns a range object containing all nodes in a word graph.
Definition word-graph.hpp:987
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:878
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:600
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:926
element_index_type label_type
Definition word-graph.hpp:102
bool operator<=(WordGraph const &that) const
Check if a word graph is less than or equal to another.
Definition word-graph.hpp:580
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:1061
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:1023
WordGraph & remove_all_targets()
Remove all of the edges in the word graph.
Definition word-graph.hpp:457
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:482
bool operator>=(WordGraph const &that) const
Check if a word graph is greater than or equal to another.
Definition word-graph.hpp:620
bool operator!=(WordGraph const &that) const
Check if two word graphs are inequal.
Definition word-graph.hpp:540
auto labels() const noexcept
Returns a range object containing all labels of edges in a word graph.
Definition word-graph.hpp:1001
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:974
size_type out_degree() const noexcept
Definition word-graph.hpp:842
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:860
bool operator==(WordGraph const &that) const
Check if two word graphs are equal.
Definition word-graph.hpp:520
typename detail::DynamicArray2< element_index_type >::const_iterator const_iterator_targets
Definition word-graph.hpp:124
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:374
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:396
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:120
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:635
size_type number_of_nodes() const noexcept
Definition word-graph.hpp:766
typename detail::IntRange< element_index_type >::const_iterator const_iterator_nodes
Definition word-graph.hpp:116
std::size_t size_type
Definition word-graph.hpp:105
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(Action< Element, Point, Func, Traits, LeftOrRight > const &action)
Return a human readable representation of an Action object.
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:4296
enable_if_is_same< Return, Blocks > make(Container const &cont)
Check the arguments, construct a Blocks object, and check it.
Definition bipart.hpp:855
std::string to_input_string(Transf< N, Scalar > const &x, std::string_view prefix="", std::string_view braces="{}")
Return a string that can be used to recreate a transformation.
constexpr bool is_specialization_of_v
Helper variable template for is_specialization_of.
Definition is_specialization_of.hpp:83
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:99
Order
The possible orderings of words and strings.
Definition order.hpp:45
@ shortlex
Definition order.hpp:51
static constexpr bool IsWordGraph
Helper variable template.
Definition word-graph.hpp:2733
Namespace containing helper functions for the WordGraph class.
Definition word-graph.hpp:1227
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.
std::unordered_set< Node1 > ancestors_of_no_checks(WordGraph< Node1 > const &wg, Node2 target)
Returns the std::unordered_set of nodes that can reach a given node in a word graph.
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:2308
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.
std::unordered_set< Node1 > ancestors_of(WordGraph< Node1 > const &wg, Node2 target)
Returns the std::unordered_set of nodes that can reach 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:1277
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:2332
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