26#ifndef LIBSEMIGROUPS_DETAIL_NODE_MANAGED_GRAPH_HPP_
27#define LIBSEMIGROUPS_DETAIL_NODE_MANAGED_GRAPH_HPP_
36#include "libsemigroups/presentation.hpp"
37#include "libsemigroups/runner.hpp"
38#include "libsemigroups/types.hpp"
39#include "libsemigroups/word-graph-helpers.hpp"
40#include "libsemigroups/word-graph.hpp"
42#include "felsch-graph.hpp"
43#include "node-manager.hpp"
46#include "word-graph-with-sources.hpp"
51 template <
typename Node>
52 class NodeManagedGraph :
public WordGraphWithSources<Node>,
53 public NodeManager<Node>,
60 using BaseGraph = WordGraphWithSources<Node>;
61 using node_type =
typename BaseGraph::node_type;
62 using label_type =
typename BaseGraph::label_type;
65 std::is_base_of_v<WordGraphWithSources<node_type>, BaseGraph>,
66 "the template parameter BaseGraph must be derived from "
67 "WordGraphWithSources");
74 using Coincidence = std::pair<node_type, node_type>;
75 using Coincidences = std::stack<Coincidence>;
76 struct CollectCoincidences;
98 NodeManagedGraph& target_no_checks(node_type s,
100 node_type t)
noexcept {
101 _stats.num_edges_active += (t !=
UNDEFINED);
102 WordGraphWithSources<Node>::target_no_checks(s, a, t);
108 using BaseGraph::target_no_checks;
110 using NodeManager<node_type>::cursor;
111 using NodeManager<node_type>::lookahead_cursor;
118 NodeManagedGraph& init();
120 NodeManagedGraph(NodeManagedGraph
const&);
121 NodeManagedGraph(NodeManagedGraph&&);
122 NodeManagedGraph& operator=(NodeManagedGraph
const&);
123 NodeManagedGraph& operator=(NodeManagedGraph&&);
126 template <
typename OtherNode>
127 explicit NodeManagedGraph(WordGraph<OtherNode>
const& wg)
128 : BaseGraph(wg), NodeManager<node_type>() {
130 NodeManager<node_type>::add_active_nodes(
131 WordGraph<node_type>::number_of_nodes() - 1);
132 _stats.num_edges_active += wg.number_of_edges();
135 template <
typename OtherNode>
136 NodeManagedGraph& init(WordGraph<OtherNode>
const& wg) {
140 NodeManager<node_type>::add_active_nodes(
141 WordGraph<node_type>::number_of_nodes() - 1);
142 _stats.num_edges_active += wg.number_of_edges();
146 template <
typename OtherNode>
147 NodeManagedGraph& operator=(WordGraph<OtherNode>
const& wg);
149 NodeManagedGraph& reserve(
size_t n);
155 [[nodiscard]]
bool operator==(WordGraph<node_type>
const& that)
const {
156 return static_cast<WordGraph<node_type> const&
>(*this) == that;
163 NodeManagedGraph& large_collapse(
size_t val)
noexcept {
164 _settings.large_collapse = val;
168 [[nodiscard]]
size_t large_collapse() const noexcept {
169 return _settings.large_collapse;
176 [[nodiscard]] Stats& stats() noexcept {
180 [[nodiscard]] Stats& stats() const noexcept {
184 void stats_check_point()
const;
190 [[nodiscard]] uint64_t number_of_edges_active() const noexcept {
191 return _stats.num_edges_active;
195 [[nodiscard]] uint64_t count_number_of_edges_active() const noexcept;
197 [[nodiscard]]
size_t number_of_coincidences() const noexcept {
198 return _coinc.size();
205 node_type new_node();
207 template <
bool RegisterDefs = false>
208 [[nodiscard]] std::pair<bool, node_type>
209 complete_path(node_type c,
210 word_type::const_iterator first,
211 word_type::const_iterator last)
noexcept;
213 void merge_nodes_no_checks(node_type x, node_type y) {
214 _coinc.emplace(x, y);
218 template <
typename Functor = Noop>
219 bool process_coincidences(Functor&& = Noop{});
221 void standardize(std::vector<node_type>
const& p,
222 std::vector<node_type>
const& q) {
223 auto& c = lookahead_cursor();
227 BaseGraph::permute_nodes_no_checks(
228 p, q, NodeManager<node_type>::number_of_nodes_active());
229 NodeManager<node_type>::compact();
232 void permute_nodes_no_checks(std::vector<node_type>
const& p,
233 std::vector<node_type>
const& q) {
234 BaseGraph::permute_nodes_no_checks(
235 p, q, NodeManager<node_type>::number_of_nodes_active());
236 NodeManager<node_type>::apply_permutation(p);
241 void swap_nodes_no_checks(node_type c, node_type d);
244 namespace node_managed_graph {
245 template <
typename BaseGraph>
246 typename BaseGraph::node_type
247 random_active_node(NodeManagedGraph<BaseGraph>
const& nmg);
254#include "node-managed-graph.tpp"
size_type out_degree() const noexcept
Returns the out-degree.
Definition word-graph.hpp:842
Undefined const UNDEFINED
Value for something undefined.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44