51#ifndef DOXYGEN_SHOULD_SKIP_THIS
59 namespace ScheduleStorageMethod {
62 template <
typename TABLE >
63 void Execution< TABLE, TABLE*, Set >::execute(TABLE& table, Set< TABLE* >& container) {
64 container.insert(&table);
68 template <
typename TABLE >
69 void Execution< TABLE, TABLE, std::vector >::execute(TABLE& table,
70 std::vector< TABLE >& container) {
71 container.push_back(std::move(table));
77 template <
typename TABLE,
template <
typename... >
class CONTAINER >
79 CONTAINER< TABLE >& container) :
80 ScheduleOperator(ScheduleOperatorType::STORE_MULTIDIM, true, false), _container_(&container) {
86 _arg_ =
dynamic_cast< ScheduleMultiDim< SCHED_TABLE >*
>(
87 const_cast< IScheduleMultiDim*
>(&table));
88 }
catch (std::bad_cast&) {
90 "The ScheduleMultiDim cannot be stored in the container "
91 "because their types are incompatible.");
98 GUM_CONSTRUCTOR(ScheduleStorage);
102 template <
typename TABLE,
template <
typename... >
class CONTAINER >
104 const ScheduleStorage< TABLE, CONTAINER >& from) :
106 _is_executed_(from._is_executed_) {
111 GUM_CONS_CPY(ScheduleStorage);
115 template <
typename TABLE,
template <
typename... >
class CONTAINER >
117 ScheduleOperator(std::move(from)), _arg_(from._arg_), _container_(from._container_),
118 _is_executed_(from._is_executed_) {
123 GUM_CONS_MOV(ScheduleStorage);
127 template <
typename TABLE,
template <
typename... >
class CONTAINER >
133 template <
typename TABLE,
template <
typename... >
class CONTAINER >
136 GUM_DESTRUCTOR(ScheduleStorage);
140 template <
typename TABLE,
template <
typename... >
class CONTAINER >
147 _container_ = from._container_;
148 _is_executed_ = from._is_executed_;
155 template <
typename TABLE,
template <
typename... >
class CONTAINER >
162 _container_ = from._container_;
163 _is_executed_ = from._is_executed_;
170 template <
typename TABLE,
template <
typename... >
class CONTAINER >
172 const ScheduleStorage< TABLE, CONTAINER >& op) const {
173 return (_container_ == op._container_) && (*_arg_ == *op._arg_);
177 template <
typename TABLE,
template <
typename... >
class CONTAINER >
178 bool
ScheduleStorage< TABLE, CONTAINER >::operator==(const ScheduleOperator& op) const {
180 const ScheduleStorage< TABLE, CONTAINER >& real_op
181 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
182 return ScheduleStorage< TABLE, CONTAINER >::operator==(real_op);
183 }
catch (std::bad_cast&) {
return false; }
187 template <
typename TABLE,
template <
typename... >
class CONTAINER >
189 const ScheduleStorage< TABLE, CONTAINER >& op) const {
190 return !ScheduleStorage< TABLE, CONTAINER >::operator==(op);
194 template <
typename TABLE,
template <
typename... >
class CONTAINER >
195 bool
ScheduleStorage< TABLE, CONTAINER >::operator!=(const ScheduleOperator& op) const {
196 return !ScheduleStorage< TABLE, CONTAINER >::operator==(op);
200 template <
typename TABLE,
template <
typename... >
class CONTAINER >
202 const ScheduleStorage< TABLE, CONTAINER >& op) const {
203 return _arg_->hasSameVariables(*op._arg_);
207 template <
typename TABLE,
template <
typename... >
class CONTAINER >
208 bool
ScheduleStorage< TABLE, CONTAINER >::hasSimilarArguments(const ScheduleOperator& op) const {
210 const ScheduleStorage< TABLE, CONTAINER >& real_op
211 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
212 return ScheduleStorage< TABLE, CONTAINER >::hasSimilarArguments(real_op);
213 }
catch (std::bad_cast&) {
return false; }
217 template <
typename TABLE,
template <
typename... >
class CONTAINER >
219 const ScheduleStorage< TABLE, CONTAINER >& op) const {
220 return (_container_ == op._container_) && _arg_->hasSameVariables(*op._arg_)
221 && _arg_->hasSameContent(*op._arg_);
225 template <
typename TABLE,
template <
typename... >
class CONTAINER >
226 bool
ScheduleStorage< TABLE, CONTAINER >::hasSameArguments(const ScheduleOperator& op) const {
228 const ScheduleStorage< TABLE, CONTAINER >& real_op
229 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
230 return ScheduleStorage< TABLE, CONTAINER >::hasSameArguments(real_op);
231 }
catch (std::bad_cast&) {
return false; }
235 template <
typename TABLE,
template <
typename... >
class CONTAINER >
237 const ScheduleStorage< TABLE, CONTAINER >& op) const {
242 template <
typename TABLE,
template <
typename... >
class CONTAINER >
243 bool
ScheduleStorage< TABLE, CONTAINER >::isSameOperator(const ScheduleOperator& op) const {
245 const ScheduleStorage< TABLE, CONTAINER >& real_op
246 =
dynamic_cast< const ScheduleStorage< TABLE, CONTAINER >&
>(op);
247 return ScheduleStorage< TABLE, CONTAINER >::isSameOperator(real_op);
248 }
catch (std::bad_cast&) {
return false; }
252 template <
typename TABLE,
template <
typename... >
class CONTAINER >
259 template <
typename TABLE,
template <
typename... >
class CONTAINER >
265 template <
typename TABLE,
template <
typename... >
class CONTAINER >
271 template <
typename TABLE,
template <
typename... >
class CONTAINER >
273 if (_arg_->isAbstract()) {
275 "It is impossible to store an abstract ScheduleMultiDim"
276 "into a container.");
283 if (std::is_same< SCHED_TABLE, TABLE >::value) {
285 if (_arg_->containsMultiDim()) {
288 ScheduleStorageMethod::Execution< SCHED_TABLE, TABLE, CONTAINER >::execute(
289 const_cast< SCHED_TABLE&
>(_arg_->multiDim()),
295 SCHED_TABLE table = _arg_->multiDim();
296 ScheduleStorageMethod::Execution< SCHED_TABLE, TABLE, CONTAINER >::execute(table,
306 if (_arg_->containsMultiDim()) {
307 table =
new SCHED_TABLE(std::move(
const_cast< SCHED_TABLE&
>(_arg_->multiDim())));
309 table =
new SCHED_TABLE(
const_cast< SCHED_TABLE&
>(_arg_->multiDim()));
312 ScheduleStorageMethod::Execution< SCHED_TABLE, TABLE, CONTAINER >::execute(*table,
317 _arg_->makeAbstract();
318 _is_executed_ =
true;
322 template <
typename TABLE,
template <
typename... >
class CONTAINER >
324 return _is_executed_;
328 template <
typename TABLE,
template <
typename... >
class CONTAINER >
330 GUM_ERROR(OperationNotAllowed,
"ScheduleStorage cannot be undone.");
334 template <
typename TABLE,
template <
typename... >
class CONTAINER >
336 const Sequence< const IScheduleMultiDim* >& new_args) {
339 if (new_args.size() !=
Size(1)) {
341 "Method ScheduleStorage::updateArgs expects 1 new "
342 <<
"argument, but " << new_args.size() <<
" were passed.");
344 ScheduleMultiDim< SCHED_TABLE >* arg;
346 arg =
dynamic_cast< ScheduleMultiDim< SCHED_TABLE >*
>(
347 const_cast< IScheduleMultiDim*
>(new_args[0]));
348 }
catch (std::bad_cast&) {
350 "The type of the argument passed to "
351 <<
"ScheduleStorage::updateArgs does not match what "
352 <<
"the ScheduleOperator expects");
356 _arg_ = (ScheduleMultiDim< SCHED_TABLE >*)arg;
359 _is_executed_ =
false;
364 template <
typename TABLE,
template <
typename... >
class CONTAINER >
370 template <
typename TABLE,
template <
typename... >
class CONTAINER >
371 std::pair< double, double >
ScheduleStorage< TABLE, CONTAINER >::memoryUsage() const {
372 const double size_table = double(_arg_->domainSize()) * _arg_->sizeOfContent() +
sizeof(TABLE);
373 return {-size_table, -size_table};
377 template <
typename TABLE,
template <
typename... >
class CONTAINER >
379 return "store ( " + _arg_->
toString() +
" )";
The Table-agnostic base class of scheduleMultiDim.
a Wrapper for multi-dimensional tables used for scheduling inferences
the base class for "low-level" operators used to schedule inferences
ScheduleOperator & operator=(const ScheduleOperator &from)
copy operator
Class for storing multidimensional tables into containers (sets, etc.).
ScheduleStorage< TABLE, CONTAINER > * clone() const final
virtual copy constructor
std::string toString() const final
displays the content of the operator
const Sequence< const IScheduleMultiDim * > & args() const final
returns the sequence of arguments passed to the operator
ScheduleStorage< TABLE, CONTAINER > & operator=(const ScheduleStorage< TABLE, CONTAINER > &)
copy operator
const Sequence< const IScheduleMultiDim * > & results() const final
returns the sequence of ScheduleMultidim output by the operator
The generic class for storing (ordered) sequences of objects.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities
Class for storing multidimensional tables in scheduling inferences.