28#ifndef LIBSEMIGROUPS_DETAIL_TODD_COXETER_IMPL_HPP_
29#define LIBSEMIGROUPS_DETAIL_TODD_COXETER_IMPL_HPP_
41#include "libsemigroups/constants.hpp"
42#include "libsemigroups/debug.hpp"
43#include "libsemigroups/forest.hpp"
44#include "libsemigroups/order.hpp"
45#include "libsemigroups/presentation.hpp"
46#include "libsemigroups/ranges.hpp"
47#include "libsemigroups/runner.hpp"
48#include "libsemigroups/to-presentation.hpp"
49#include "libsemigroups/types.hpp"
50#include "libsemigroups/word-graph.hpp"
52#include "cong-common-class.hpp"
53#include "felsch-graph.hpp"
54#include "node-managed-graph.hpp"
55#include "node-manager.hpp"
56#include "word-graph-with-sources.hpp"
158 class ToddCoxeterImpl
159 :
public detail::CongruenceCommon,
160 public detail::FelschGraphSettings<ToddCoxeterImpl> {
161 using FelschGraphSettings_ = FelschGraphSettings<ToddCoxeterImpl>;
168 struct options :
public FelschGraphSettings_::options {
169 enum class strategy { hlt, felsch, CR, R_over_C, Cr, Rc };
171 enum class lookahead_extent { full, partial };
173 enum class lookahead_style { hlt, felsch };
175 enum class def_policy : uint8_t {
176 no_stack_if_no_space,
179 discard_all_if_no_space,
185 using index_type = node_type;
197 friend class SettingsGuard;
200 using Definition = std::pair<node_type, label_type>;
204 std::vector<Definition> _definitions;
205 ToddCoxeterImpl
const* _tc;
208 Definitions() : _any_skipped(false), _definitions(), _tc(nullptr) {}
211 Definitions(Definitions
const&) =
default;
212 Definitions(Definitions&&) =
default;
213 Definitions& operator=(Definitions
const& that) =
default;
214 Definitions& operator=(Definitions&&) =
default;
217 void init(ToddCoxeterImpl
const* tc) {
218 _any_skipped =
false;
219 _definitions.clear();
223 void emplace_back(node_type c, label_type x);
225 [[nodiscard]]
bool any_skipped() const noexcept {
229 [[nodiscard]]
bool empty() const noexcept {
230 return _definitions.empty();
233 void pop(Definition& d) {
235 _definitions.pop_back();
239 _definitions.clear();
243 bool is_active_node(node_type n)
const noexcept {
244 return _tc->current_word_graph().is_active_node(n);
248 class Graph :
public detail::NodeManagedGraph<
249 detail::FelschGraph<word_type, uint32_t, Definitions>> {
251 = detail::FelschGraph<word_type, uint32_t, Definitions>;
252 using NodeManagedGraph_ = NodeManagedGraph<FelschGraph_>;
255 using node_type =
typename NodeManagedGraph_::node_type;
258 Graph(Graph
const&) =
default;
259 Graph(Graph&&) =
default;
260 Graph& operator=(Graph
const&) =
default;
261 Graph& operator=(Graph&&) =
default;
264 Graph& operator=(WordGraph<node_type>
const& wg) {
265 NodeManagedGraph_::operator=(wg);
269 using FelschGraph_::target_no_checks;
270 using NodeManagedGraph_::NodeManagedGraph;
277 void process_definitions();
279 template <
bool RegDefs>
280 void push_definition_hlt(node_type
const& c,
284 template <
typename Iterator>
285 size_t make_compatible(node_type& current,
289 std::chrono::nanoseconds stop_early_interval,
290 float stop_early_ratio);
299 std::vector<std::unique_ptr<Settings>> _settings_stack;
304 using word_graph_type = Graph;
311 ToddCoxeterImpl& init();
313 ToddCoxeterImpl(ToddCoxeterImpl
const& that);
314 ToddCoxeterImpl(ToddCoxeterImpl&&);
315 ToddCoxeterImpl& operator=(ToddCoxeterImpl
const&);
316 ToddCoxeterImpl& operator=(ToddCoxeterImpl&&);
328 template <
typename Node>
330 : ToddCoxeterImpl() {
331 LIBSEMIGROUPS_ASSERT(!_settings_stack.empty());
335 template <
typename Node>
348#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
352 template <
typename Node>
355 WordGraph<Node>
const& wg) {
360 template <
typename Node>
363 WordGraph<Node>
const& wg);
366 template <
typename Iterator1,
typename Iterator2>
367 void throw_if_letter_not_in_alphabet(Iterator1 first,
368 Iterator2 last)
const {
369 internal_presentation().throw_if_letter_not_in_alphabet(first, last);
376 template <
typename Iterator1,
380 ToddCoxeterImpl& add_generating_pair_no_checks(Iterator1 first1,
384 return detail::CongruenceCommon::add_internal_generating_pair_no_checks<
385 ToddCoxeterImpl>(first1, last1, first2, last2);
388 template <
typename Iterator1,
392 ToddCoxeterImpl& add_generating_pair(Iterator1 first1,
396 return detail::CongruenceCommon::add_generating_pair<ToddCoxeterImpl>(
397 first1, last1, first2, last2);
423 template <
typename Iterator1,
427 tril currently_contains_no_checks(Iterator1 first1,
430 Iterator4 last2)
const;
432 template <
typename Iterator1,
436 tril currently_contains(Iterator1 first1,
439 Iterator4 last2)
const {
440 return detail::CongruenceCommon::currently_contains<ToddCoxeterImpl>(
441 first1, last1, first2, last2);
444 template <
typename Iterator1,
448 bool contains_no_checks(Iterator1 first1,
453 template <
typename Iterator1,
457 bool contains(Iterator1 first1,
466 template <
typename OutputIterator,
467 typename InputIterator1,
468 typename InputIterator2>
469 OutputIterator reduce_no_run_no_checks(OutputIterator d_first,
470 InputIterator1 first,
471 InputIterator2 last)
const;
473 template <
typename OutputIterator,
474 typename InputIterator1,
475 typename InputIterator2>
476 OutputIterator reduce_no_run(OutputIterator d_first,
477 InputIterator1 first,
478 InputIterator2 last)
const {
479 return detail::CongruenceCommon::reduce_no_run<ToddCoxeterImpl>(
480 d_first, first, last);
483 template <
typename OutputIterator,
484 typename InputIterator1,
485 typename InputIterator2>
486 OutputIterator reduce_no_checks(OutputIterator d_first,
487 InputIterator1 first,
488 InputIterator2 last) {
489 return detail::CongruenceCommon::reduce_no_checks<ToddCoxeterImpl>(
490 d_first, first, last);
493 template <
typename OutputIterator,
494 typename InputIterator1,
495 typename InputIterator2>
496 OutputIterator reduce(OutputIterator d_first,
497 InputIterator1 first,
498 InputIterator2 last) {
499 return detail::CongruenceCommon::reduce<ToddCoxeterImpl>(
500 d_first, first, last);
507#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
509 template <
typename T>
512 _word_graph.report_every(val);
533 ToddCoxeterImpl&
def_max(
size_t val)
noexcept;
544 [[nodiscard]]
size_t def_max() const noexcept;
625 [[nodiscard]]
size_t f_defs() const noexcept;
1054 ToddCoxeterImpl&
save(
bool val) noexcept;
1066 [[nodiscard]]
bool save() const noexcept;
1129#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1161 using FelschGraphSettings_::def_version;
1162 using FelschGraphSettings_::settings;
1169#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1171 internal_presentation() const noexcept {
1172 return _word_graph.presentation();
1328 return _standardized;
1467 template <
typename Iterator1,
typename Iterator2>
1469 Iterator2 last)
const;
1496 template <
typename Iterator1,
typename Iterator2>
1498 throw_if_letter_not_in_alphabet(first, last);
1527 template <
typename Iterator1,
typename Iterator2>
1555 template <
typename Iterator1,
typename Iterator2>
1557 throw_if_letter_not_in_alphabet(first, last);
1613 template <
typename OutputIterator>
1615 index_type i)
const;
1642 template <
typename OutputIterator>
1644 index_type i)
const;
1669 template <
typename Iterator>
1700 template <
typename Iterator>
1701 Iterator
word_of(Iterator d_first, index_type i) {
1714 void really_run_impl();
1716 void run_impl()
override;
1718 bool finished_impl()
const override {
1726 void copy_settings_into_graph();
1730 Settings& tc_settings();
1731 Settings
const& tc_settings()
const;
1738 void finalise_run();
1743 void R_over_C_style();
1751 void report_next_lookahead(
size_t old_value)
const;
1752 void report_nodes_killed(int64_t number)
const;
1758 static constexpr bool StopEarly =
true;
1759 static constexpr bool DoNotStopEarly =
false;
1761 size_t hlt_lookahead(
bool stop_early);
1762 size_t felsch_lookahead();
1769#include "todd-coxeter-impl.tpp"
Class representing a collection of spanning trees of a word graph.
Definition forest.hpp:42
For an implementation of presentations for semigroups or monoids.
Definition presentation.hpp:102
nanoseconds report_every() const noexcept
Get the minimum elapsed time between reports.
Definition runner.hpp:222
std::chrono::nanoseconds nanoseconds
Alias for std::chrono::nanoseconds.
Definition runner.hpp:97
void run()
Run until finished.
bool finished() const
Check if run has been run to completion or not.
Node node_type
The type of nodes in a word graph.
Definition word-graph.hpp:98
Node label_type
The type of edge labels in a word graph.
Definition word-graph.hpp:101
Order
The possible orderings of words and strings.
Definition order.hpp:48
Presentation(Presentation< Word > const &) -> Presentation< Word >
Deduction guide.
Forest const & current_spanning_tree() const noexcept
Get the current possible spanning tree of the underlying word graph.
Definition todd-coxeter-impl.hpp:1268
Forest const & spanning_tree()
Get the spanning tree of the underlying word graph.
word_graph_type const & current_word_graph() const noexcept
Get the current word graph.
Definition todd-coxeter-impl.hpp:1213
word_graph_type const & word_graph()
Get the word graph after performing a full congruence enumeration.
bool is_standardized(Order val) const
Check if the word graph is currently standardized with respect to a given order.
Order standardization_order() const noexcept
Get the current standardization order of the underlying word graph.
Definition todd-coxeter-impl.hpp:1327
bool is_standardized() const
Check if the word graph is currently standardized with respect to any order.
OutputIterator current_word_of(OutputIterator d_first, index_type i) const
Insert a current word representing a class with given index into an output iterator.
Iterator word_of_no_checks(Iterator d_first, index_type i)
Insert the word representing a class with given index into an output iterator.
Definition todd-coxeter-impl.hpp:1670
Iterator word_of(Iterator d_first, index_type i)
Insert the word representing a class with given index into an output iterator.
Definition todd-coxeter-impl.hpp:1701
OutputIterator current_word_of_no_checks(OutputIterator d_first, index_type i) const
Insert a current word representing a class with given index into an output iterator.
uint64_t number_of_classes()
Compute the number of classes in the congruence.
void perform_lookahead(bool stop_early)
Perform a lookahead.
void shrink_to_fit()
Shrink the underlying word graph to remove all dead nodes.
bool standardize(Order val)
Standardize the current_word_graph.
options::def_version def_version() const noexcept
Get the current value of the definition version setting.
ToddCoxeterImpl & lookahead_extent(options::lookahead_extent val) noexcept
Set the lookahead extent.
ToddCoxeterImpl & lookahead_growth_factor(float val)
Set the lookahead growth factor.
ToddCoxeterImpl & lookahead_style(options::lookahead_style val) noexcept
Set the style of lookahead.
ToddCoxeterImpl & lookahead_stop_early_ratio(float val)
Set the lookahead stop early ratio.
ToddCoxeterImpl & lookahead_next(size_t val) noexcept
Set the threshold that will trigger a lookahead.
ToddCoxeterImpl & lookahead_min(size_t val) noexcept
Set the minimum value of lookahead_next.
ToddCoxeterImpl & use_relations_in_extra(bool val) noexcept
Set whether or not to perform an HLT-style push of the defining relations at the identity.
size_t def_max() const noexcept
Get the current value of the setting for the maximum number of definitions.
ToddCoxeterImpl & def_version(options::def_version val)
Set the value of the definition version setting.
ToddCoxeterImpl & lookahead_growth_threshold(size_t val) noexcept
Set the lookahead growth threshold.
ToddCoxeterImpl & strategy(options::strategy val) noexcept
Specify the congruence enumeration strategy.
ToddCoxeterImpl & def_max(size_t val) noexcept
Set the maximum number of definitions in the stack.
ToddCoxeterImpl & def_policy(options::def_policy val)
Set the definition policy.
ToddCoxeterImpl & lookahead_stop_early_interval(std::chrono::nanoseconds val) noexcept
Set the lookahead stop early interval.
ToddCoxeterImpl & save(bool val) noexcept
Set whether or not to process definitions during HLT.
ToddCoxeterImpl & f_defs(size_t val)
Set the number of Felsch style definitions in ACE strategies.
ToddCoxeterImpl & lower_bound(size_t val) noexcept
Specify the minimum number of classes that may permit any enumeration early stop.
ToddCoxeterImpl & large_collapse(size_t val) noexcept
Set the size of a large collapse.
ToddCoxeterImpl & hlt_defs(size_t val)
Set the number of HLT style definitions in ACE strategies.
index_type current_index_of(Iterator1 first, Iterator2 last) const
Returns the current index of the class containing a word.
Definition todd-coxeter-impl.hpp:1497
index_type current_index_of_no_checks(Iterator1 first, Iterator2 last) const
Returns the current index of the class containing a word.
index_type index_of_no_checks(Iterator1 first, Iterator2 last)
Returns the index of the class containing a word.
index_type index_of(Iterator1 first, Iterator2 last)
Returns the index of the class containing a word.
Definition todd-coxeter-impl.hpp:1556
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101
tril
Enum to indicate true, false or not currently knowable.
Definition types.hpp:56
congruence_kind
Enum to indicate the sided-ness of a congruence.
Definition types.hpp:69
Namespace for everything in the libsemigroups library.
Definition action.hpp:44