aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
actionSet.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
41
49
50// =========================================================================
51#ifndef GUM_ACTION_SET_H
52#define GUM_ACTION_SET_H
53// =========================================================================
54#include <thread>
55// =========================================================================
58// =========================================================================
60// =========================================================================
61#include <agrum/FMDP/fmdp.h>
62
63// =========================================================================
64
65namespace gum {
66
75 template < typename GUM_SCALAR >
77 // ###########################################################################
79 // ###########################################################################
81
82 const GUM_SCALAR& operator()(const GUM_SCALAR& x, const GUM_SCALAR& y) const {
83 if (x > y) { return x; }
84 if (x < y) { return y; }
85
86 _temp_ = x;
87 _temp_ += y;
88 return _temp_;
89 }
90
91 private:
92 mutable GUM_SCALAR _temp_;
93 };
94
105 class ActionSet {
106 public:
107 // ###########################################################################
109 // ###########################################################################
111
112 // ============================================================================
114 // ============================================================================
116 GUM_CONSTRUCTOR(ActionSet);
118 }
119
120 ActionSet(const ActionSet& src) {
121 GUM_CONSTRUCTOR(ActionSet);
123 for (auto idi = src.beginSafe(); idi != src.endSafe(); ++idi)
124 _actionSeq_->insert(*idi);
125 }
126
129 for (auto idi = src.beginSafe(); idi != src.endSafe(); ++idi)
130 _actionSeq_->insert(*idi);
131 return *this;
132 }
133
134 // ============================================================================
136 // ============================================================================
138 GUM_DESTRUCTOR(ActionSet);
139 delete _actionSeq_;
140 }
141
142 // ============================================================================
144 // ============================================================================
145 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
146
147 void operator delete(void* p) {
149 }
150
152
153 // ###########################################################################
155 // ###########################################################################
157
158 // ============================================================================
160 // ============================================================================
161 SequenceIteratorSafe< Idx > beginSafe() const { return _actionSeq_->beginSafe(); }
162
163 // ============================================================================
165 // ============================================================================
166 SequenceIteratorSafe< Idx > endSafe() const { return _actionSeq_->endSafe(); }
167
169
170 // ###########################################################################
172 // ###########################################################################
174
175 // ============================================================================
177 // ============================================================================
178 ActionSet& operator+=(const Idx& elem) {
179 _actionSeq_->insert(elem);
180 return *this;
181 }
182
183 // ============================================================================
185 // ============================================================================
187 for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
188 if (!_actionSeq_->exists(*iter)) _actionSeq_->insert(*iter);
189 return *this;
190 }
191
192 // ============================================================================
194 // ============================================================================
196 for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
197 if (_actionSeq_->exists(*iter)) _actionSeq_->erase(*iter);
198 return *this;
199 }
200
201 // ============================================================================
203 // ============================================================================
204 const Idx& operator[](const Idx i) const { return _actionSeq_->atPos(i); }
205
206 // ============================================================================
208 // ============================================================================
209 bool operator==(const ActionSet& compared) const {
210 for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
211 if (!_actionSeq_->exists(*iter)) return false;
212 for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
213 if (!compared.exists(*iter)) return false;
214 return true;
215 }
216
217 bool operator!=(const ActionSet& compared) const { return !(*this == compared); }
218
220
221 // ============================================================================
223 // ============================================================================
224 Size size() const { return _actionSeq_->size(); }
225
226 bool exists(const Idx& elem) const { return _actionSeq_->exists(elem); }
227
228 private:
231
232 friend std::ostream& operator<<(std::ostream& streamy, const ActionSet& objy) {
233 streamy << objy._actionSeq_->toString();
234 return streamy;
235 }
236 };
237} // namespace gum
238#endif // GUM_ACTION_SET_H
Headers of the ITerminalNodePolicy.
ActionSet & operator+=(const Idx &elem)
Ajout d'un élément.
Definition actionSet.h:178
ActionSet(const ActionSet &src)
Constructor.
Definition actionSet.h:120
bool operator!=(const ActionSet &compared) const
Ajout d'un élément.
Definition actionSet.h:217
ActionSet()
Constructor.
Definition actionSet.h:115
SequenceIteratorSafe< Idx > endSafe() const
Iterator end.
Definition actionSet.h:166
friend std::ostream & operator<<(std::ostream &streamy, const ActionSet &objy)
Definition actionSet.h:232
bool exists(const Idx &elem) const
Definition actionSet.h:226
ActionSet & operator+=(const ActionSet &src)
Use to insert the content of another set inside this one.
Definition actionSet.h:186
~ActionSet()
Destructor.
Definition actionSet.h:137
SequenceIteratorSafe< Idx > beginSafe() const
Iterator beginning.
Definition actionSet.h:161
ActionSet & operator-=(const ActionSet &src)
Use to insert the content of another set inside this one.
Definition actionSet.h:195
bool operator==(const ActionSet &compared) const
Compares two ActionSet to check if they are equals.
Definition actionSet.h:209
ActionSet & operator=(const ActionSet &src)
Constructor.
Definition actionSet.h:127
Sequence< Idx > * _actionSeq_
The very bone of the ActionSet.
Definition actionSet.h:230
const Idx & operator[](const Idx i) const
Gives the ith element.
Definition actionSet.h:204
Size size() const
Gives the size.
Definition actionSet.h:224
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Class for implementation of factored markov decision process.
This files contains several function objects that are not (yet) defined in the STL.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
aGrUM's inline/outline selection
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
<agrum/FMDP/planning/actionSet.h>
Definition actionSet.h:76
const GUM_SCALAR & operator()(const GUM_SCALAR &x, const GUM_SCALAR &y) const
Definition actionSet.h:82