aGrUM  0.14.2
actionSet.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 // =========================================================================
28 #ifndef GUM_ACTION_SET_H
29 #define GUM_ACTION_SET_H
30 // =========================================================================
31 #include <thread>
32 // =========================================================================
33 #include <agrum/core/argMaxSet.h>
34 #include <agrum/core/functors.h>
35 #include <agrum/core/inline.h>
37 // =========================================================================
40 // =========================================================================
41 #include <agrum/FMDP/fmdp.h>
42 // =========================================================================
43 
44 namespace gum {
45 
54  template < typename GUM_SCALAR >
56  // ###########################################################################
58  // ###########################################################################
60 
61  const GUM_SCALAR& operator()(const GUM_SCALAR& x, const GUM_SCALAR& y) const {
62  if (x > y) { return x; }
63  if (x < y) { return y; }
64 
65  __temp = x;
66  __temp += y;
67  return __temp;
68  }
69 
70  private:
71  mutable GUM_SCALAR __temp;
72  };
73 
74 
85  class ActionSet {
86  public:
87  // ###########################################################################
89  // ###########################################################################
91 
92  // ============================================================================
94  // ============================================================================
96  GUM_CONSTRUCTOR(ActionSet);
97  __actionSeq = new Sequence< Idx >();
98  }
99 
100  ActionSet(const ActionSet& src) {
101  GUM_CONSTRUCTOR(ActionSet);
102  __actionSeq = new Sequence< Idx >();
103  for (auto idi = src.beginSafe(); idi != src.endSafe(); ++idi)
104  __actionSeq->insert(*idi);
105  }
106 
108  __actionSeq = new Sequence< Idx >();
109  for (auto idi = src.beginSafe(); idi != src.endSafe(); ++idi)
110  __actionSeq->insert(*idi);
111  return *this;
112  }
113 
114  // ============================================================================
116  // ============================================================================
118  GUM_DESTRUCTOR(ActionSet);
119  delete __actionSeq;
120  }
121 
122  // ============================================================================
124  // ============================================================================
125  void* operator new(size_t s) {
127  }
128  void operator delete(void* p) {
130  }
131 
133 
134  // ###########################################################################
136  // ###########################################################################
138 
139  // ============================================================================
141  // ============================================================================
143  return __actionSeq->beginSafe();
144  }
145 
146  // ============================================================================
148  // ============================================================================
149  SequenceIteratorSafe< Idx > endSafe() const { return __actionSeq->endSafe(); }
150 
152 
153  // ###########################################################################
155  // ###########################################################################
157 
158  // ============================================================================
160  // ============================================================================
161  ActionSet& operator+=(const Idx& elem) {
162  __actionSeq->insert(elem);
163  return *this;
164  }
165 
166  // ============================================================================
168  // ============================================================================
170  for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
171  if (!__actionSeq->exists(*iter)) __actionSeq->insert(*iter);
172  return *this;
173  }
174 
175  // ============================================================================
177  // ============================================================================
179  for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
180  if (__actionSeq->exists(*iter)) __actionSeq->erase(*iter);
181  return *this;
182  }
183 
184  // ============================================================================
186  // ============================================================================
187  const Idx& operator[](const Idx i) const { return __actionSeq->atPos(i); }
188 
189  // ============================================================================
191  // ============================================================================
192  bool operator==(const ActionSet& compared) const {
193  for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
194  if (!__actionSeq->exists(*iter)) return false;
195  for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
196  if (!compared.exists(*iter)) return false;
197  return true;
198  }
199  bool operator!=(const ActionSet& compared) const {
200  return !(*this == compared);
201  }
202 
204 
205  // ============================================================================
207  // ============================================================================
208  Size size() const { return __actionSeq->size(); }
209 
210  bool exists(const Idx& elem) const { return __actionSeq->exists(elem); }
211 
212  private:
215 
216  friend std::ostream& operator<<(std::ostream& streamy, const ActionSet& objy) {
217  streamy << objy.__actionSeq->toString();
218  return streamy;
219  }
220  };
221 } // namespace gum
222 #endif // GUM_ACTION_SET_H
const GUM_SCALAR & operator()(const GUM_SCALAR &x, const GUM_SCALAR &y) const
Definition: actionSet.h:61
Headers of the ITerminalNodePolicy.
bool operator==(const ActionSet &compared) const
Compares two ActionSet to check if they are equals.
Definition: actionSet.h:192
Size size() const
Gives the size.
Definition: actionSet.h:208
Headers of gum::SmallObjectAllocator.
A class to store the optimal actions.
Definition: actionSet.h:85
aGrUM&#39;s inline/outline selection
ActionSet(const ActionSet &src)
Constructor.
Definition: actionSet.h:100
friend std::ostream & operator<<(std::ostream &streamy, const ActionSet &objy)
Definition: actionSet.h:216
~ActionSet()
Destructor.
Definition: actionSet.h:117
std::string toString() const
Displays the content of the sequence.
Definition: sequence_tpl.h:571
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
This files contains several function objects that are not (yet) defined in the STL.
bool exists(const Idx &elem) const
Definition: actionSet.h:210
SequenceIteratorSafe< Idx > endSafe() const
Iterator end.
Definition: actionSet.h:149
Sequence< Idx > * __actionSeq
The very bone of the ActionSet.
Definition: actionSet.h:214
ActionSet & operator=(const ActionSet &src)
Constructor.
Definition: actionSet.h:107
Class for implementation of factored markov decision process.
ActionSet & operator+=(const ActionSet &src)
Use to insert the content of another set inside this one.
Definition: actionSet.h:169
ActionSet()
Constructor.
Definition: actionSet.h:95
ActionSet & operator-=(const ActionSet &src)
Use to insert the content of another set inside this one.
Definition: actionSet.h:178
Headers of MultiDimFunctionGraph.
SequenceIteratorSafe< Idx > beginSafe() const
Iterator beginning.
Definition: actionSet.h:142
ActionSet & operator+=(const Idx &elem)
Ajout d&#39;un élément.
Definition: actionSet.h:161
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
bool operator!=(const ActionSet &compared) const
Ajout d&#39;un élément.
Definition: actionSet.h:199
const Idx & operator[](const Idx i) const
Gives the ith element.
Definition: actionSet.h:187
This files contains several function objects that are not (yet) defined in the STL.
Size Idx
Type for indexes.
Definition: types.h:50
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
<agrum/FMDP/planning/actionSet.h>
Definition: actionSet.h:55
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:405