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_::presentation;
270 using FelschGraph_::target_no_checks;
271 using NodeManagedGraph_::NodeManagedGraph;
280 void process_definitions();
282 template <
bool RegDefs>
283 void push_definition_hlt(node_type
const& c,
287 template <
typename Iterator>
288 size_t make_compatible(ToddCoxeterImpl* tc,
295 void report_lookahead_stop_early(ToddCoxeterImpl* tc,
297 size_t killed_last_interval);
306 std::vector<std::unique_ptr<Settings>> _settings_stack;
308 bool _ticker_running;
312 using word_graph_type = Graph;
319 ToddCoxeterImpl& init();
321 ToddCoxeterImpl(ToddCoxeterImpl
const& that);
322 ToddCoxeterImpl(ToddCoxeterImpl&&);
323 ToddCoxeterImpl& operator=(ToddCoxeterImpl
const&);
324 ToddCoxeterImpl& operator=(ToddCoxeterImpl&&);
336 template <
typename Node>
338 : ToddCoxeterImpl() {
339 LIBSEMIGROUPS_ASSERT(!_settings_stack.empty());
343 template <
typename Node>
358#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
362 template <
typename Node>
365 WordGraph<Node>
const& wg) {
370 template <
typename Node>
373 WordGraph<Node>
const& wg);
376 template <
typename Iterator1,
typename Iterator2>
377 void throw_if_letter_not_in_alphabet(Iterator1 first,
378 Iterator2 last)
const {
379 internal_presentation().throw_if_letter_not_in_alphabet(first, last);
386 template <
typename Iterator1,
390 ToddCoxeterImpl& add_generating_pair_no_checks(Iterator1 first1,
394 return detail::CongruenceCommon::add_internal_generating_pair_no_checks<
395 ToddCoxeterImpl>(first1, last1, first2, last2);
398 template <
typename Iterator1,
402 ToddCoxeterImpl& add_generating_pair(Iterator1 first1,
406 return detail::CongruenceCommon::add_generating_pair<ToddCoxeterImpl>(
407 first1, last1, first2, last2);
433 template <
typename Iterator1,
437 tril currently_contains_no_checks(Iterator1 first1,
440 Iterator4 last2)
const;
442 template <
typename Iterator1,
446 tril currently_contains(Iterator1 first1,
449 Iterator4 last2)
const {
450 return detail::CongruenceCommon::currently_contains<ToddCoxeterImpl>(
451 first1, last1, first2, last2);
454 template <
typename Iterator1,
458 bool contains_no_checks(Iterator1 first1,
463 template <
typename Iterator1,
467 bool contains(Iterator1 first1,
476 template <
typename OutputIterator,
477 typename InputIterator1,
478 typename InputIterator2>
479 OutputIterator reduce_no_run_no_checks(OutputIterator d_first,
480 InputIterator1 first,
481 InputIterator2 last)
const;
483 template <
typename OutputIterator,
484 typename InputIterator1,
485 typename InputIterator2>
486 OutputIterator reduce_no_run(OutputIterator d_first,
487 InputIterator1 first,
488 InputIterator2 last)
const {
489 return detail::CongruenceCommon::reduce_no_run<ToddCoxeterImpl>(
490 d_first, first, last);
493 template <
typename OutputIterator,
494 typename InputIterator1,
495 typename InputIterator2>
496 OutputIterator reduce_no_checks(OutputIterator d_first,
497 InputIterator1 first,
498 InputIterator2 last) {
499 return detail::CongruenceCommon::reduce_no_checks<ToddCoxeterImpl>(
500 d_first, first, last);
503 template <
typename OutputIterator,
504 typename InputIterator1,
505 typename InputIterator2>
506 OutputIterator reduce(OutputIterator d_first,
507 InputIterator1 first,
508 InputIterator2 last) {
509 return detail::CongruenceCommon::reduce<ToddCoxeterImpl>(
510 d_first, first, last);
517#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
519 template <
typename Time>
522 _word_graph.report_every(val);
546 ToddCoxeterImpl&
def_max(
size_t val)
noexcept;
557 [[nodiscard]]
size_t def_max() const noexcept;
638 [[nodiscard]]
size_t f_defs() const noexcept;
1067 ToddCoxeterImpl&
save(
bool val) noexcept;
1079 [[nodiscard]]
bool save() const noexcept;
1142#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1174 using FelschGraphSettings_::def_version;
1175 using FelschGraphSettings_::settings;
1182#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1184 internal_presentation() const noexcept {
1185 return _word_graph.presentation();
1189 [[nodiscard]] uint64_t number_of_nodes_active() const noexcept {
1190 return _word_graph.number_of_nodes_active();
1345 return _standardized;
1484 template <
typename Iterator1,
typename Iterator2>
1486 Iterator2 last)
const;
1513 template <
typename Iterator1,
typename Iterator2>
1515 throw_if_letter_not_in_alphabet(first, last);
1544 template <
typename Iterator1,
typename Iterator2>
1572 template <
typename Iterator1,
typename Iterator2>
1574 throw_if_letter_not_in_alphabet(first, last);
1630 template <
typename OutputIterator>
1632 index_type i)
const;
1659 template <
typename OutputIterator>
1661 index_type i)
const;
1686 template <
typename Iterator>
1717 template <
typename Iterator>
1718 Iterator
word_of(Iterator d_first, index_type i) {
1731 void really_run_impl();
1733 void run_impl()
override;
1735 bool finished_impl()
const override {
1743 void copy_settings_into_graph();
1747 Settings& tc_settings();
1748 Settings
const& tc_settings()
const;
1750 void reset_settings_stack();
1757 void finalise_run();
1762 void R_over_C_style();
1770 void report_after_lookahead(
size_t old_lookahead_next,
1771 size_t number_killed_in_lookahead,
1772 std::chrono::high_resolution_clock::time_point
1773 lookahead_start_time)
const;
1774 void report_after_run()
const;
1775 void report_before_lookahead()
const;
1776 void report_before_run()
const;
1777 void report_presentation()
const;
1778 void report_strategy()
const;
1784 static constexpr bool StopEarly =
true;
1785 static constexpr bool DoNotStopEarly =
false;
1787 size_t hlt_lookahead(
bool stop_early);
1788 size_t felsch_lookahead();
1795#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:227
std::chrono::nanoseconds nanoseconds
Alias for std::chrono::nanoseconds.
Definition runner.hpp:102
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
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:1285
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:1230
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:1344
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:1687
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:1718
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:1514
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:1573
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
tril
Enum to indicate true, false or not currently knowable.
Definition types.hpp:54
congruence_kind
Enum to indicate the sided-ness of a congruence.
Definition types.hpp:67
Namespace for everything in the libsemigroups library.
Definition action.hpp:44