aGrUM 2.3.2
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-2025 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-2025 *
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#pragma once
41
42
48
49#ifndef DOXYGEN_SHOULD_SKIP_THIS
50
51# include <agrum/agrum.h>
52
54
55namespace gum {
56
57
59 template < typename TABLE >
60 ScheduleDeletion< TABLE >::ScheduleDeletion(const ScheduleMultiDim< TABLE >& table) :
62 _arg_(const_cast< ScheduleMultiDim< TABLE >* >(&table)) {
63 // save the arg into _args_ (no need to update _results_)
64 _args_ << _arg_;
65
66 // for debugging purposes
67 GUM_CONSTRUCTOR(ScheduleDeletion);
68 }
69
71 template < typename TABLE >
72 ScheduleDeletion< TABLE >::ScheduleDeletion(const ScheduleDeletion< TABLE >& from) :
73 ScheduleOperator(from), _arg_(from._arg_), _is_executed_(from._is_executed_) {
74 // save the arg into _args_ (no need to update _results_)
75 _args_ << _arg_;
76
77 // for debugging purposes
78 GUM_CONS_CPY(ScheduleDeletion);
79 }
80
82 template < typename TABLE >
83 ScheduleDeletion< TABLE >::ScheduleDeletion(ScheduleDeletion< TABLE >&& from) :
84 ScheduleOperator(std::move(from)), _arg_(from._arg_), _is_executed_(from._is_executed_) {
85 // save the arg into _args_ (no need to update _results_)
86 _args_ = std::move(from._args_);
87
88 // for debugging purposes
89 GUM_CONS_MOV(ScheduleDeletion);
90 }
91
93 template < typename TABLE >
94 INLINE ScheduleDeletion< TABLE >* ScheduleDeletion< TABLE >::clone() const {
95 return new ScheduleDeletion< TABLE >(*this);
96 }
97
99 template < typename TABLE >
100 ScheduleDeletion< TABLE >::~ScheduleDeletion() {
101 // for debugging purposes
102 GUM_DESTRUCTOR(ScheduleDeletion);
103 }
104
106 template < typename TABLE >
107 ScheduleDeletion< TABLE >&
108 ScheduleDeletion< TABLE >::operator=(const ScheduleDeletion< TABLE >& from) {
109 _arg_ = from._arg_;
110 _args_.clear();
111 _args_ << _arg_;
112 _is_executed_ = from._is_executed_;
113 ScheduleOperator::operator=(from);
114 return *this;
115 }
116
118 template < typename TABLE >
119 ScheduleDeletion< TABLE >&
120 ScheduleDeletion< TABLE >::operator=(ScheduleDeletion< TABLE >&& from) {
121 _arg_ = from._arg_;
122 _args_ = std::move(from._args_);
123 _is_executed_ = from._is_executed_;
124 ScheduleOperator::operator=(std::move(from));
125 return *this;
126 }
127
129 template < typename TABLE >
130 INLINE bool ScheduleDeletion< TABLE >::operator==(const ScheduleDeletion< TABLE >& op) const {
131 return (*_arg_ == *op._arg_);
132 }
133
135 template < typename TABLE >
136 bool ScheduleDeletion< TABLE >::operator==(const ScheduleOperator& op) const {
137 try {
138 const ScheduleDeletion< TABLE >& real_op
139 = dynamic_cast< const ScheduleDeletion< TABLE >& >(op);
140 return ScheduleDeletion< TABLE >::operator==(real_op);
141 } catch (std::bad_cast&) { return false; }
142 }
143
145 template < typename TABLE >
146 INLINE bool ScheduleDeletion< TABLE >::operator!=(const ScheduleDeletion< TABLE >& op) const {
147 return !ScheduleDeletion< TABLE >::operator==(op);
148 }
149
151 template < typename TABLE >
152 INLINE bool ScheduleDeletion< TABLE >::operator!=(const ScheduleOperator& op) const {
153 return !ScheduleDeletion< TABLE >::operator==(op);
154 }
155
157 template < typename TABLE >
158 INLINE bool
159 ScheduleDeletion< TABLE >::hasSimilarArguments(const ScheduleDeletion< TABLE >& op) const {
160 return _arg_->hasSameVariables(*op._arg_);
161 }
162
164 template < typename TABLE >
165 bool ScheduleDeletion< TABLE >::hasSimilarArguments(const ScheduleOperator& op) const {
166 try {
167 const ScheduleDeletion< TABLE >& real_op
168 = dynamic_cast< const ScheduleDeletion< TABLE >& >(op);
169 return ScheduleDeletion< TABLE >::hasSimilarArguments(real_op);
170 } catch (std::bad_cast&) { return false; }
171 }
172
174 template < typename TABLE >
175 INLINE bool
176 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 INLINE 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 INLINE const ScheduleMultiDim< TABLE >& ScheduleDeletion< TABLE >::arg() const {
209 return *_arg_;
210 }
211
213 template < typename TABLE >
214 INLINE const Sequence< const IScheduleMultiDim* >& ScheduleDeletion< TABLE >::args() const {
215 return _args_;
216 }
217
219 template < typename TABLE >
220 INLINE 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 INLINE bool ScheduleDeletion< TABLE >::isExecuted() const {
254 return _is_executed_;
255 }
256
258 template < typename TABLE >
259 INLINE 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 INLINE double ScheduleDeletion< TABLE >::nbOperations() const {
274 return 1.0;
275 }
276
278 template < typename TABLE >
279 INLINE 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:72
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