51#ifndef DOXYGEN_SHOULD_SKIP_THIS
58 template <
typename STRUCT_CONSTRAINT >
60 STRUCT_CONSTRAINT& constraint) : constraint_(&constraint) {
61 GUM_CONSTRUCTOR(GraphChangesGenerator4K2);
65 template <
typename STRUCT_CONSTRAINT >
66 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::GraphChangesGenerator4K2(
67 const GraphChangesGenerator4K2& from) :
68 graph_(from.graph_), constraint_(from.constraint_), order_(from.order_),
69 legal_changes_(from.legal_changes_), _max_threads_number_(from._max_threads_number_) {
70 GUM_CONS_CPY(GraphChangesGenerator4K2);
74 template <
typename STRUCT_CONSTRAINT >
75 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::GraphChangesGenerator4K2(
76 GraphChangesGenerator4K2&& from) :
77 graph_(
std::move(from.graph_)), constraint_(from.constraint_),
78 order_(
std::move(from.order_)), legal_changes_(
std::move(from.legal_changes_)),
79 _max_threads_number_(from._max_threads_number_) {
80 GUM_CONS_MOV(GraphChangesGenerator4K2);
84 template <
typename STRUCT_CONSTRAINT >
85 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::~GraphChangesGenerator4K2() {
86 GUM_DESTRUCTOR(GraphChangesGenerator4K2);
90 template <
typename STRUCT_CONSTRAINT >
91 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >&
92 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::operator=(
93 const GraphChangesGenerator4K2< STRUCT_CONSTRAINT >& from) {
96 constraint_ = from.constraint_;
98 legal_changes_ = from.legal_changes_;
99 _max_threads_number_ = from._max_threads_number_;
105 template <
typename STRUCT_CONSTRAINT >
106 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >&
107 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::operator=(
108 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >&& from) {
110 graph_ = std::move(from.graph_);
111 constraint_ = std::move(from.constraint_);
112 order_ = std::move(from.order_);
113 legal_changes_ = std::move(from.legal_changes_);
114 _max_threads_number_ = from._max_threads_number_;
120 template <
typename STRUCT_CONSTRAINT >
121 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::createChanges_() {
122 legal_changes_.clear();
125 const Size nb_threads = _max_threads_number_;
126 std::vector< Set< GraphChange > > legal_changes(nb_threads);
129 auto threadedLegalSet = [
this, &legal_changes](
const std::size_t this_thread,
130 const std::size_t nb_threads) ->
void {
131 for (Idx i = 0, j = 0; j < this->order_.size(); i = (i + 1) % nb_threads, ++j) {
132 if (i == this_thread) {
133 for (Idx k = j + 1; k < this->order_.size(); ++k) {
135 ArcAddition arc_add(order_[j], order_[k]);
136 if (!this->constraint_->isAlwaysInvalid(arc_add)) {
137 legal_changes[this_thread].insert(std::move(arc_add));
145 ThreadExecutor::execute(nb_threads, threadedLegalSet);
149 for (
const auto& changes: legal_changes) {
150 for (
const auto& change: changes) {
151 legal_changes_.insert(std::move(change));
157 template <
typename STRUCT_CONSTRAINT >
158 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setGraph(
const DiGraph& graph) {
165 for (
auto node = order_.beginSafe(); node != order_.endSafe(); ++node) {
166 if (!graph.exists(*node)) { order_.erase(node); }
168 for (
const auto node: graph) {
169 if (!order_.exists(node)) { order_.insert(node); }
177 template <
typename STRUCT_CONSTRAINT >
178 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setOrder(
const Sequence< NodeId >& order) {
183 template <
typename STRUCT_CONSTRAINT >
184 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setOrder(
185 const std::vector< NodeId >& order) {
187 for (
const auto node: order) {
193 template <
typename STRUCT_CONSTRAINT >
194 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::clearChanges() noexcept {
195 legal_changes_.clear();
199 template <
typename STRUCT_CONSTRAINT >
200 typename GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::iterator
201 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::begin()
const {
202 return legal_changes_.cbegin();
206 template <
typename STRUCT_CONSTRAINT >
207 const typename GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::iterator&
208 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::end()
const {
209 return legal_changes_.cend();
213 template <
typename STRUCT_CONSTRAINT >
214 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const ArcAddition& change) {}
217 template <
typename STRUCT_CONSTRAINT >
218 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const ArcDeletion& change) {}
221 template <
typename STRUCT_CONSTRAINT >
222 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const ArcReversal& change) {}
225 template <
typename STRUCT_CONSTRAINT >
226 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const GraphChange& change) {}
229 template <
typename STRUCT_CONSTRAINT >
230 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::notifyGetCompleted() {
231 if (legal_changes_.size()) legal_changes_.clear();
235 template <
typename STRUCT_CONSTRAINT >
236 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setMaxNbThreads(Size nb)
noexcept {
238 _max_threads_number_ = nb;
242 template <
typename STRUCT_CONSTRAINT >
243 STRUCT_CONSTRAINT& GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::constraint() const noexcept {
GraphChangesGenerator4K2(STRUCT_CONSTRAINT &constraint)
default constructor
The basic class for computing the set of digraph changes allowed by the user to be executed by the le...
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities
unsigned int getNumberOfThreads()
returns the max number of threads used by default when entering the next parallel region