aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
scheduleDeletion_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41#pragma once
42
43
49
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53# include <agrum/agrum.h>
54
56
57namespace gum {
58
59
61 template < typename TABLE >
62 ScheduleDeletion< TABLE >::ScheduleDeletion(const ScheduleMultiDim< TABLE >& table) :
64 _arg_(const_cast< ScheduleMultiDim< TABLE >* >(&table)) {
65 // save the arg into _args_ (no need to update _results_)
66 _args_ << _arg_;
67
68 // for debugging purposes
69 GUM_CONSTRUCTOR(ScheduleDeletion);
70 }
71
73 template < typename TABLE >
74 ScheduleDeletion< TABLE >::ScheduleDeletion(const ScheduleDeletion< TABLE >& from) :
75 ScheduleOperator(from), _arg_(from._arg_), _is_executed_(from._is_executed_) {
76 // save the arg into _args_ (no need to update _results_)
77 _args_ << _arg_;
78
79 // for debugging purposes
80 GUM_CONS_CPY(ScheduleDeletion);
81 }
82
84 template < typename TABLE >
85 ScheduleDeletion< TABLE >::ScheduleDeletion(ScheduleDeletion< TABLE >&& from) :
86 ScheduleOperator(std::move(from)), _arg_(from._arg_), _is_executed_(from._is_executed_) {
87 // save the arg into _args_ (no need to update _results_)
88 _args_ = std::move(from._args_);
89
90 // for debugging purposes
91 GUM_CONS_MOV(ScheduleDeletion);
92 }
93
95 template < typename TABLE >
96 ScheduleDeletion< TABLE >* ScheduleDeletion< TABLE >::clone() const {
97 return new ScheduleDeletion< TABLE >(*this);
98 }
99
101 template < typename TABLE >
102 ScheduleDeletion< TABLE >::~ScheduleDeletion() {
103 // for debugging purposes
104 GUM_DESTRUCTOR(ScheduleDeletion);
105 }
106
108 template < typename TABLE >
109 ScheduleDeletion< TABLE >&
110 ScheduleDeletion< TABLE >::operator=(const ScheduleDeletion< TABLE >& from) {
111 _arg_ = from._arg_;
112 _args_.clear();
113 _args_ << _arg_;
114 _is_executed_ = from._is_executed_;
115 ScheduleOperator::operator=(from);
116 return *this;
117 }
118
120 template < typename TABLE >
121 ScheduleDeletion< TABLE >&
122 ScheduleDeletion< TABLE >::operator=(ScheduleDeletion< TABLE >&& from) {
123 _arg_ = from._arg_;
124 _args_ = std::move(from._args_);
125 _is_executed_ = from._is_executed_;
126 ScheduleOperator::operator=(std::move(from));
127 return *this;
128 }
129
131 template < typename TABLE >
132 bool ScheduleDeletion< TABLE >::operator==(const ScheduleDeletion< TABLE >& op) const {
133 return (*_arg_ == *op._arg_);
134 }
135
137 template < typename TABLE >
138 bool ScheduleDeletion< TABLE >::operator==(const ScheduleOperator& op) const {
139 try {
140 const ScheduleDeletion< TABLE >& real_op
141 = dynamic_cast< const ScheduleDeletion< TABLE >& >(op);
142 return ScheduleDeletion< TABLE >::operator==(real_op);
143 } catch (std::bad_cast&) { return false; }
144 }
145
147 template < typename TABLE >
148 bool ScheduleDeletion< TABLE >::operator!=(const ScheduleDeletion< TABLE >& op) const {
149 return !ScheduleDeletion< TABLE >::operator==(op);
150 }
151
153 template < typename TABLE >
154 bool ScheduleDeletion< TABLE >::operator!=(const ScheduleOperator& op) const {
155 return !ScheduleDeletion< TABLE >::operator==(op);
156 }
157
159 template < typename TABLE >
160 bool ScheduleDeletion< TABLE >::hasSimilarArguments(const ScheduleDeletion< TABLE >& op) const {
161 return _arg_->hasSameVariables(*op._arg_);
162 }
163
165 template < typename TABLE >
166 bool ScheduleDeletion< TABLE >::hasSimilarArguments(const ScheduleOperator& op) const {
167 try {
168 const ScheduleDeletion< TABLE >& real_op
169 = dynamic_cast< const ScheduleDeletion< TABLE >& >(op);
170 return ScheduleDeletion< TABLE >::hasSimilarArguments(real_op);
171 } catch (std::bad_cast&) { return false; }
172 }
173
175 template < typename TABLE >
176 bool ScheduleDeletion< TABLE >::hasSameArguments(const ScheduleDeletion< TABLE >& op) const {
177 return _arg_->hasSameVariables(*op._arg_) && _arg_->hasSameContent(*op._arg_);
178 }
179
181 template < typename TABLE >
182 bool ScheduleDeletion< TABLE >::hasSameArguments(const ScheduleOperator& op) const {
183 try {
184 const ScheduleDeletion< TABLE >& real_op
185 = dynamic_cast< const ScheduleDeletion< TABLE >& >(op);
186 return ScheduleDeletion< TABLE >::hasSameArguments(real_op);
187 } catch (std::bad_cast&) { return false; }
188 }
189
191 template < typename TABLE >
192 bool ScheduleDeletion< TABLE >::isSameOperator(const ScheduleDeletion< TABLE >& op) const {
193 return true;
194 }
195
197 template < typename TABLE >
198 bool ScheduleDeletion< TABLE >::isSameOperator(const ScheduleOperator& op) const {
199 try {
200 const ScheduleDeletion< TABLE >& real_op
201 = dynamic_cast< const ScheduleDeletion< TABLE >& >(op);
202 return ScheduleDeletion< TABLE >::isSameOperator(real_op);
203 } catch (std::bad_cast&) { return false; }
204 }
205
207 template < typename TABLE >
208 const ScheduleMultiDim< TABLE >& ScheduleDeletion< TABLE >::arg() const {
209 return *_arg_;
210 }
211
213 template < typename TABLE >
214 const Sequence< const IScheduleMultiDim* >& ScheduleDeletion< TABLE >::args() const {
215 return _args_;
216 }
217
219 template < typename TABLE >
220 const Sequence< const IScheduleMultiDim* >& ScheduleDeletion< TABLE >::results() const {
221 return _results_;
222 }
223
225 template < typename TABLE >
226 void ScheduleDeletion< TABLE >::updateArgs(const Sequence< const IScheduleMultiDim* >& new_args) {
227 // check that there is exactly one argument in new_args and that its type
228 // is compatible with TABLE
229 if (new_args.size() != Size(1)) {
231 "Method ScheduleDeletion::updateArgs expects 1 new "
232 << "argument, but " << new_args.size() << " were passed.");
233 }
234 const ScheduleMultiDim< TABLE >* arg;
235 try {
236 arg = dynamic_cast< const ScheduleMultiDim< TABLE >* >(new_args[0]);
237 } catch (std::bad_cast&) {
239 "The type of the argument passed to "
240 << "ScheduleDeletion::updateArgs does not match what "
241 << "the ScheduleOperator expects");
242 }
243
244 // save the new argument
245 _arg_ = (ScheduleMultiDim< TABLE >*)arg;
246 _args_.clear();
247 _args_ << _arg_;
248 _is_executed_ = false;
249 }
250
252 template < typename TABLE >
253 bool ScheduleDeletion< TABLE >::isExecuted() const {
254 return _is_executed_;
255 }
256
258 template < typename TABLE >
259 void ScheduleDeletion< TABLE >::execute() {
260 _arg_->makeAbstract();
261 _is_executed_ = true;
262 }
263
265 template < typename TABLE >
266 void ScheduleDeletion< TABLE >::undo() {
267 GUM_ERROR(OperationNotAllowed, "ScheduleDeletion cannot be undone.");
268 }
269
272 template < typename TABLE >
273 double ScheduleDeletion< TABLE >::nbOperations() const {
274 return 1.0;
275 }
276
278 template < typename TABLE >
279 std::pair< double, double > ScheduleDeletion< TABLE >::memoryUsage() const {
280 const double size_table = double(_arg_->domainSize()) * _arg_->sizeOfContent() + sizeof(TABLE);
281 return {-size_table, -size_table};
282 }
283
285 template < typename TABLE >
286 std::string ScheduleDeletion< TABLE >::toString() const {
287 return "delete ( " + _arg_->toString() + " )";
288 }
289
290} // namespace gum
291
292#endif /* DOXYGEN_SHOULD_SKIP_THIS */
Exception : operation not allowed.
a Wrapper for multi-dimensional tables used for scheduling inferences
the base class for "low-level" operators used to schedule inferences
Exception : problem with size.
Exception : wrong type for this operation.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
ScheduleOperatorType
the currently supported types of "low-level" operators
@ DELETE_MULTIDIM
remove from memory a multidimensional table stored in a ScheduleMultiDim
STL namespace.
an operator to force a ScheduleMultiDim to be abstract