24#ifndef LIBSEMIGROUPS_PATHS_HPP_
25#define LIBSEMIGROUPS_PATHS_HPP_
38#include "constants.hpp"
40#include "exception.hpp"
44#include "word-graph.hpp"
45#include "word-range.hpp"
47#include "detail/containers.hpp"
48#include "detail/path-iterators.hpp"
118 template <
typename Node1,
typename Node2>
124 return detail::const_pilo_iterator<Node1>(&wg,
source,
min,
max);
138 template <
typename Node>
140 return detail::const_pilo_iterator<Node>(&wg, 0, 0, 0);
189 template <
typename Node1,
typename Node2>
195 return detail::const_pislo_iterator<Node1>(&wg,
source,
min,
max);
209 template <
typename Node>
211 return detail::const_pislo_iterator<Node>(&wg,
UNDEFINED, 0, 0);
255 template <
typename Node1,
typename Node2>
279 template <
typename Node>
281 return detail::const_pstilo_iterator<Node>(&wg, 0, 0, 0, 0);
327 template <
typename Node1,
typename Node2>
353 template <
typename Node>
355 return detail::const_pstislo_iterator<Node>(
372 template <
typename Node1,
typename Node2>
397 template <
typename Node1,
typename Node2>
422 template <
typename Node1,
typename Node2>
473 template <
typename Node1,
typename Node2>
504 template <
typename Node1,
typename Node2>
553 template <
typename Node1,
typename Node2>
600 template <
typename Node>
621 using const_iterator = std::variant<detail::const_pstislo_iterator<Node>,
622 detail::const_pstilo_iterator<Node>,
623 detail::const_pislo_iterator<Node>,
624 detail::const_pilo_iterator<Node>>;
633 mutable const_iterator _current;
634 mutable const_iterator _end;
635 mutable bool _current_valid;
637 bool set_iterator_no_checks()
const;
739 set_iterator_no_checks();
741 [](
auto& it) ->
auto const& {
return *it; }, _current);
754 std::visit([](
auto& it) { ++it; }, _current);
768 if (!set_iterator_no_checks()) {
771 return _current == _end;
800 [[nodiscard]] uint64_t
count()
const {
804 static constexpr bool is_finite =
true;
805 static constexpr bool is_idempotent =
true;
958 return min(
this, val);
987 return max(
this, val);
1015 return order(
this, val);
1041 return *_word_graph;
1045 template <
typename Sub
class>
1047 _current_valid &= (src == _source);
1052 template <
typename Sub
class>
1054 _current_valid &= (trgt == _target);
1059 template <
typename Sub
class>
1061 _current_valid &= (
min == _min);
1066 template <
typename Sub
class>
1068 _current_valid &= (
max == _max);
1073 template <
typename Sub
class>
1081 template <
typename Node>
1088 template <
typename Node>
1103 template <
typename Node>
auto cbegin_pstilo(WordGraph< Node1 > const &wg, Node2 source, Node2 target, size_t min=0, size_t max=POSITIVE_INFINITY)
Definition paths.hpp:256
Paths(WordGraph< Node > &&) -> Paths< Node >
void next()
Advance to the next path in the range.
Definition paths.hpp:751
typename WordGraph< uint32_t >::size_type size_type
Definition paths.hpp:613
uint32_t node_type
Definition paths.hpp:608
size_type min() const noexcept
Get the minimum length of path in the range.
Definition paths.hpp:970
word_type const & output_type
Definition paths.hpp:618
Paths(WordGraph< Node > const &) -> Paths< Node >
auto cend_pstilo(WordGraph< Node > const &wg)
Definition paths.hpp:280
Paths(Paths const &)
Default copy constructor.
WordGraph< Node > const & word_graph() const noexcept
The underlying WordGraph.
Definition paths.hpp:1040
Paths(Paths &&)
Default move constructor.
auto cend_pilo(WordGraph< Node > const &wg)
Definition paths.hpp:139
Paths & min(size_type val) noexcept
Definition paths.hpp:957
paths::algorithm number_of_paths_algorithm(WordGraph< Node1 > const &wg, Node2 source) noexcept
Definition paths.hpp:374
std::string to_human_readable_repr(Paths< Node > const &p)
Return a human readable representation of a Paths object.
Paths(WordGraph< Node > const &wg)
Construct from a WordGraph.
Definition paths.hpp:689
auto cbegin_pislo(WordGraph< Node1 > const &wg, Node2 source, size_t min=0, size_t max=POSITIVE_INFINITY)
Definition paths.hpp:190
auto cend_pstislo(WordGraph< Node > const &wg)
Definition paths.hpp:354
Paths & max(size_type val) noexcept
Definition paths.hpp:986
Paths & operator=(Paths const &)
Default copy assignment operator.
node_type source() const noexcept
Get the current source node of every path in the range.
Definition paths.hpp:866
uint64_t number_of_paths(WordGraph< Node1 > const &wg, Node2 source)
node_type current_target() const
Get the current target node of the path labelled by get.
size_type max() const noexcept
Get the maximum length of path in the range.
Definition paths.hpp:999
bool at_end() const
Check if the range is exhausted.
Definition paths.hpp:767
Paths & source(node_type n)
Definition paths.hpp:852
void throw_if_source_undefined() const
Throw an exception if the source node has not been defined (using source).
Paths & operator=(Paths &&)
Default move assignment operator.
uint64_t number_of_paths(WordGraph< Node1 > const &wg, Node2 source, size_t min, size_t max, paths::algorithm lgrthm=paths::algorithm::automatic)
output_type get() const
Get the current path in the range.
Definition paths.hpp:738
Paths & target_no_checks(node_type n) noexcept
Set the target node of every path in the range.
Definition paths.hpp:890
uint64_t count() const
Get the size of the range.
Definition paths.hpp:800
node_type target() const noexcept
Get the current target node of every path in the range.
Definition paths.hpp:927
paths::algorithm number_of_paths_algorithm(WordGraph< Node1 > const &wg, Node2 source, size_t min, size_t max)
Order order() const noexcept
Get the order of the paths in the range.
Definition paths.hpp:1027
auto cbegin_pilo(WordGraph< Node1 > const &wg, Node2 source, size_t min=0, size_t max=POSITIVE_INFINITY)
Returns an iterator for pilo (Path And Node In Lex Order).
Definition paths.hpp:119
Paths & target(node_type n)
Definition paths.hpp:911
paths::algorithm number_of_paths_algorithm(WordGraph< Node1 > const &wg, Node2 source, Node2 target, size_t min, size_t max)
auto cend_pislo(WordGraph< Node > const &wg)
Definition paths.hpp:210
auto cbegin_pstislo(WordGraph< Node1 > const &wg, Node2 source, Node2 target, size_t min=0, size_t max=POSITIVE_INFINITY)
Definition paths.hpp:328
uint64_t number_of_paths(WordGraph< Node1 > const &wg, Node2 source, Node2 target, size_t min, size_t max, paths::algorithm lgrthm=paths::algorithm::automatic)
Paths & order(Order val)
Set the order of the paths in the range.
Definition paths.hpp:1014
uint64_t size_hint() const
Get the size of the range.
Paths & init(WordGraph< Node > const &wg)
Reinitialize a Paths object.
Definition paths.hpp:709
Paths & source_no_checks(node_type n) noexcept
Set the source node of every path in the range.
Definition paths.hpp:831
Class for representing word graphs.
Definition word-graph.hpp:82
std::size_t size_type
Unsigned integer type.
Definition word-graph.hpp:104
Undefined const UNDEFINED
Value for something undefined.
PositiveInfinity const POSITIVE_INFINITY
Value for positive infinity.
Order
The possible orderings of words and strings.
Definition order.hpp:48
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101
Namespace containing helper functions for the Paths class.
Definition paths.hpp:56
algorithm
An enum for specifying the algorithm to the functions number_of_paths().
Definition paths.hpp:58
@ trivial
Try to utilise some corner cases.
Definition paths.hpp:66
@ matrix
Use the adjacency matrix and matrix multiplication.
Definition paths.hpp:62
@ automatic
Definition paths.hpp:69
@ dfs
Use a depth-first-search.
Definition paths.hpp:60
@ acyclic
Use a dynamic programming approach for acyclic word graphs.
Definition paths.hpp:64
void throw_if_node_out_of_bounds(WordGraph< Node1 > const &wg, Node2 n)
Throws if a node is out of bounds.
bool is_reachable(WordGraph< Node1 > const &wg, Node2 source, Node2 target)
Check if there is a path from one node to another.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44