49#ifndef DOXYGEN_SHOULD_SKIP_THIS
56 template <
typename STRUCT_CONSTRAINT >
58 STRUCT_CONSTRAINT& constraint) : constraint_(&constraint) {
59 GUM_CONSTRUCTOR(GraphChangesGenerator4DiGraph);
63 template <
typename STRUCT_CONSTRAINT >
64 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::GraphChangesGenerator4DiGraph(
65 const GraphChangesGenerator4DiGraph& from) :
66 graph_(from.graph_), constraint_(from.constraint_), legal_changes_(from.legal_changes_),
67 _max_threads_number_(from._max_threads_number_) {
68 GUM_CONS_CPY(GraphChangesGenerator4DiGraph);
72 template <
typename STRUCT_CONSTRAINT >
73 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::GraphChangesGenerator4DiGraph(
74 GraphChangesGenerator4DiGraph&& from) :
75 graph_(
std::move(from.graph_)), constraint_(from.constraint_),
76 legal_changes_(
std::move(from.legal_changes_)),
77 _max_threads_number_(from._max_threads_number_) {
78 GUM_CONS_MOV(GraphChangesGenerator4DiGraph);
82 template <
typename STRUCT_CONSTRAINT >
83 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::~GraphChangesGenerator4DiGraph() {
84 GUM_DESTRUCTOR(GraphChangesGenerator4DiGraph);
88 template <
typename STRUCT_CONSTRAINT >
89 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >&
90 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::operator=(
91 const GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >& from) {
94 constraint_ = from.constraint_;
95 legal_changes_ = from.legal_changes_;
96 _max_threads_number_ = from._max_threads_number_;
102 template <
typename STRUCT_CONSTRAINT >
103 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >&
104 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::operator=(
105 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >&& from) {
107 graph_ = std::move(from.graph_);
108 constraint_ = std::move(from.constraint_);
109 legal_changes_ = std::move(from.legal_changes_);
110 _max_threads_number_ = from._max_threads_number_;
116 template <
typename STRUCT_CONSTRAINT >
117 void GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::createChanges_() {
118 legal_changes_.clear();
122 const Size nb_threads = _max_threads_number_;
123 std::vector< Set< GraphChange > > legal_changes(nb_threads);
126 auto threadedLegalSet = [
this, &legal_changes](
const std::size_t this_thread,
127 const std::size_t nb_threads) ->
void {
129 for (
const auto node1: this->graph_) {
130 if (i == this_thread) {
131 for (
const auto node2: this->graph_) {
132 if (node1 != node2) {
134 ArcAddition arc_add(node1, node2);
135 if (!this->constraint_->isAlwaysInvalid(arc_add)) {
136 legal_changes[this_thread].insert(std::move(arc_add));
140 ArcDeletion arc_del(node1, node2);
141 if (!this->constraint_->isAlwaysInvalid(arc_del)) {
142 legal_changes[this_thread].insert(std::move(arc_del));
146 ArcReversal arc_rev(node1, node2);
147 if (!this->constraint_->isAlwaysInvalid(arc_rev)) {
148 legal_changes[this_thread].insert(std::move(arc_rev));
159 ThreadExecutor::execute(nb_threads, threadedLegalSet);
164 for (
const auto& changes: legal_changes) {
165 for (
const auto& change: changes) {
166 legal_changes_.insert(std::move(change));
172 template <
typename STRUCT_CONSTRAINT >
173 INLINE
void GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::setGraph(
const DiGraph& graph) {
182 template <
typename STRUCT_CONSTRAINT >
183 INLINE
void GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::clearChanges() noexcept {
184 legal_changes_.clear();
188 template <
typename STRUCT_CONSTRAINT >
189 INLINE
typename GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::iterator
190 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::begin()
const {
191 return legal_changes_.cbegin();
195 template <
typename STRUCT_CONSTRAINT >
196 INLINE
const typename GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::iterator&
197 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::end()
const {
198 return legal_changes_.cend();
202 template <
typename STRUCT_CONSTRAINT >
204 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::modifyGraph(
const ArcAddition& change) {
208 template <
typename STRUCT_CONSTRAINT >
210 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::modifyGraph(
const ArcDeletion& change) {
214 template <
typename STRUCT_CONSTRAINT >
216 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::modifyGraph(
const ArcReversal& change) {
220 template <
typename STRUCT_CONSTRAINT >
222 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::modifyGraph(
const GraphChange& change) {
226 template <
typename STRUCT_CONSTRAINT >
227 INLINE
void GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::notifyGetCompleted() {
228 if (legal_changes_.size()) legal_changes_.clear();
232 template <
typename STRUCT_CONSTRAINT >
234 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::setMaxNbThreads(Size nb)
noexcept {
236 _max_threads_number_ = nb;
240 template <
typename STRUCT_CONSTRAINT >
241 INLINE STRUCT_CONSTRAINT&
242 GraphChangesGenerator4DiGraph< STRUCT_CONSTRAINT >::constraint() const noexcept {
GraphChangesGenerator4DiGraph(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