49#ifndef DOXYGEN_SHOULD_SKIP_THIS
56 template <
typename STRUCT_CONSTRAINT >
58 STRUCT_CONSTRAINT& constraint) : constraint_(&constraint) {
59 GUM_CONSTRUCTOR(GraphChangesGenerator4K2);
63 template <
typename STRUCT_CONSTRAINT >
64 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::GraphChangesGenerator4K2(
65 const GraphChangesGenerator4K2& from) :
66 graph_(from.graph_), constraint_(from.constraint_), order_(from.order_),
67 legal_changes_(from.legal_changes_), _max_threads_number_(from._max_threads_number_) {
68 GUM_CONS_CPY(GraphChangesGenerator4K2);
72 template <
typename STRUCT_CONSTRAINT >
73 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::GraphChangesGenerator4K2(
74 GraphChangesGenerator4K2&& from) :
75 graph_(
std::move(from.graph_)), constraint_(from.constraint_),
76 order_(
std::move(from.order_)), legal_changes_(
std::move(from.legal_changes_)),
77 _max_threads_number_(from._max_threads_number_) {
78 GUM_CONS_MOV(GraphChangesGenerator4K2);
82 template <
typename STRUCT_CONSTRAINT >
83 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::~GraphChangesGenerator4K2() {
84 GUM_DESTRUCTOR(GraphChangesGenerator4K2);
88 template <
typename STRUCT_CONSTRAINT >
89 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >&
90 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::operator=(
91 const GraphChangesGenerator4K2< STRUCT_CONSTRAINT >& from) {
94 constraint_ = from.constraint_;
96 legal_changes_ = from.legal_changes_;
97 _max_threads_number_ = from._max_threads_number_;
103 template <
typename STRUCT_CONSTRAINT >
104 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >&
105 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::operator=(
106 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >&& from) {
108 graph_ = std::move(from.graph_);
109 constraint_ = std::move(from.constraint_);
110 order_ = std::move(from.order_);
111 legal_changes_ = std::move(from.legal_changes_);
112 _max_threads_number_ = from._max_threads_number_;
118 template <
typename STRUCT_CONSTRAINT >
119 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::createChanges_() {
120 legal_changes_.clear();
123 const Size nb_threads = _max_threads_number_;
124 std::vector< Set< GraphChange > > legal_changes(nb_threads);
127 auto threadedLegalSet = [
this, &legal_changes](
const std::size_t this_thread,
128 const std::size_t nb_threads) ->
void {
129 for (Idx i = 0, j = 0; j < this->order_.size(); i = (i + 1) % nb_threads, ++j) {
130 if (i == this_thread) {
131 for (Idx k = j + 1; k < this->order_.size(); ++k) {
133 ArcAddition arc_add(order_[j], order_[k]);
134 if (!this->constraint_->isAlwaysInvalid(arc_add)) {
135 legal_changes[this_thread].insert(std::move(arc_add));
143 ThreadExecutor::execute(nb_threads, threadedLegalSet);
147 for (
const auto& changes: legal_changes) {
148 for (
const auto& change: changes) {
149 legal_changes_.insert(std::move(change));
155 template <
typename STRUCT_CONSTRAINT >
156 void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setGraph(
const DiGraph& graph) {
163 for (
auto node = order_.beginSafe(); node != order_.endSafe(); ++node) {
164 if (!graph.exists(*node)) { order_.erase(node); }
166 for (
const auto node: graph) {
167 if (!order_.exists(node)) { order_.insert(node); }
175 template <
typename STRUCT_CONSTRAINT >
177 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setOrder(
const Sequence< NodeId >& order) {
182 template <
typename STRUCT_CONSTRAINT >
183 INLINE
void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setOrder(
184 const std::vector< NodeId >& order) {
186 for (
const auto node: order) {
192 template <
typename STRUCT_CONSTRAINT >
193 INLINE
void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::clearChanges() noexcept {
194 legal_changes_.clear();
198 template <
typename STRUCT_CONSTRAINT >
199 INLINE
typename GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::iterator
200 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::begin()
const {
201 return legal_changes_.cbegin();
205 template <
typename STRUCT_CONSTRAINT >
206 INLINE
const typename GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::iterator&
207 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::end()
const {
208 return legal_changes_.cend();
212 template <
typename STRUCT_CONSTRAINT >
214 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const ArcAddition& change) {}
217 template <
typename STRUCT_CONSTRAINT >
219 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const ArcDeletion& change) {}
222 template <
typename STRUCT_CONSTRAINT >
224 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const ArcReversal& change) {}
227 template <
typename STRUCT_CONSTRAINT >
229 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::modifyGraph(
const GraphChange& change) {}
232 template <
typename STRUCT_CONSTRAINT >
233 INLINE
void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::notifyGetCompleted() {
234 if (legal_changes_.size()) legal_changes_.clear();
238 template <
typename STRUCT_CONSTRAINT >
239 INLINE
void GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::setMaxNbThreads(Size nb)
noexcept {
241 _max_threads_number_ = nb;
245 template <
typename STRUCT_CONSTRAINT >
246 INLINE STRUCT_CONSTRAINT&
247 GraphChangesGenerator4K2< STRUCT_CONSTRAINT >::constraint() const noexcept {
GraphChangesGenerator4K2(STRUCT_CONSTRAINT &constraint)
default constructor
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