aGrUM  0.16.0
actionSet.h
Go to the documentation of this file.
1 
30 // =========================================================================
31 #ifndef GUM_ACTION_SET_H
32 #define GUM_ACTION_SET_H
33 // =========================================================================
34 #include <thread>
35 // =========================================================================
36 #include <agrum/core/argMaxSet.h>
37 #include <agrum/core/functors.h>
38 #include <agrum/core/inline.h>
40 // =========================================================================
43 // =========================================================================
44 #include <agrum/FMDP/fmdp.h>
45 // =========================================================================
46 
47 namespace gum {
48 
57  template < typename GUM_SCALAR >
59  // ###########################################################################
61  // ###########################################################################
63 
64  const GUM_SCALAR& operator()(const GUM_SCALAR& x, const GUM_SCALAR& y) const {
65  if (x > y) { return x; }
66  if (x < y) { return y; }
67 
68  __temp = x;
69  __temp += y;
70  return __temp;
71  }
72 
73  private:
74  mutable GUM_SCALAR __temp;
75  };
76 
77 
88  class ActionSet {
89  public:
90  // ###########################################################################
92  // ###########################################################################
94 
95  // ============================================================================
97  // ============================================================================
99  GUM_CONSTRUCTOR(ActionSet);
100  __actionSeq = new Sequence< Idx >();
101  }
102 
103  ActionSet(const ActionSet& src) {
104  GUM_CONSTRUCTOR(ActionSet);
105  __actionSeq = new Sequence< Idx >();
106  for (auto idi = src.beginSafe(); idi != src.endSafe(); ++idi)
107  __actionSeq->insert(*idi);
108  }
109 
111  __actionSeq = new Sequence< Idx >();
112  for (auto idi = src.beginSafe(); idi != src.endSafe(); ++idi)
113  __actionSeq->insert(*idi);
114  return *this;
115  }
116 
117  // ============================================================================
119  // ============================================================================
121  GUM_DESTRUCTOR(ActionSet);
122  delete __actionSeq;
123  }
124 
125  // ============================================================================
127  // ============================================================================
128  void* operator new(size_t s) {
130  }
131  void operator delete(void* p) {
133  }
134 
136 
137  // ###########################################################################
139  // ###########################################################################
141 
142  // ============================================================================
144  // ============================================================================
146  return __actionSeq->beginSafe();
147  }
148 
149  // ============================================================================
151  // ============================================================================
152  SequenceIteratorSafe< Idx > endSafe() const { return __actionSeq->endSafe(); }
153 
155 
156  // ###########################################################################
158  // ###########################################################################
160 
161  // ============================================================================
163  // ============================================================================
164  ActionSet& operator+=(const Idx& elem) {
165  __actionSeq->insert(elem);
166  return *this;
167  }
168 
169  // ============================================================================
171  // ============================================================================
173  for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
174  if (!__actionSeq->exists(*iter)) __actionSeq->insert(*iter);
175  return *this;
176  }
177 
178  // ============================================================================
180  // ============================================================================
182  for (auto iter = src.beginSafe(); iter != src.endSafe(); ++iter)
183  if (__actionSeq->exists(*iter)) __actionSeq->erase(*iter);
184  return *this;
185  }
186 
187  // ============================================================================
189  // ============================================================================
190  const Idx& operator[](const Idx i) const { return __actionSeq->atPos(i); }
191 
192  // ============================================================================
194  // ============================================================================
195  bool operator==(const ActionSet& compared) const {
196  for (auto iter = compared.beginSafe(); iter != compared.endSafe(); ++iter)
197  if (!__actionSeq->exists(*iter)) return false;
198  for (auto iter = this->beginSafe(); iter != this->endSafe(); ++iter)
199  if (!compared.exists(*iter)) return false;
200  return true;
201  }
202  bool operator!=(const ActionSet& compared) const {
203  return !(*this == compared);
204  }
205 
207 
208  // ============================================================================
210  // ============================================================================
211  Size size() const { return __actionSeq->size(); }
212 
213  bool exists(const Idx& elem) const { return __actionSeq->exists(elem); }
214 
215  private:
218 
219  friend std::ostream& operator<<(std::ostream& streamy, const ActionSet& objy) {
220  streamy << objy.__actionSeq->toString();
221  return streamy;
222  }
223  };
224 } // namespace gum
225 #endif // GUM_ACTION_SET_H
const GUM_SCALAR & operator()(const GUM_SCALAR &x, const GUM_SCALAR &y) const
Definition: actionSet.h:64
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool operator==(const ActionSet &compared) const
Compares two ActionSet to check if they are equals.
Definition: actionSet.h:195
Size size() const
Gives the size.
Definition: actionSet.h:211
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
A class to store the optimal actions.
Definition: actionSet.h:88
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
ActionSet(const ActionSet &src)
Constructor.
Definition: actionSet.h:103
friend std::ostream & operator<<(std::ostream &streamy, const ActionSet &objy)
Definition: actionSet.h:219
~ActionSet()
Destructor.
Definition: actionSet.h:120
std::string toString() const
Displays the content of the sequence.
Definition: sequence_tpl.h:574
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool exists(const Idx &elem) const
Definition: actionSet.h:213
SequenceIteratorSafe< Idx > endSafe() const
Iterator end.
Definition: actionSet.h:152
Sequence< Idx > * __actionSeq
The very bone of the ActionSet.
Definition: actionSet.h:217
ActionSet & operator=(const ActionSet &src)
Constructor.
Definition: actionSet.h:110
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
ActionSet & operator+=(const ActionSet &src)
Use to insert the content of another set inside this one.
Definition: actionSet.h:172
ActionSet()
Constructor.
Definition: actionSet.h:98
ActionSet & operator-=(const ActionSet &src)
Use to insert the content of another set inside this one.
Definition: actionSet.h:181
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
SequenceIteratorSafe< Idx > beginSafe() const
Iterator beginning.
Definition: actionSet.h:145
ActionSet & operator+=(const Idx &elem)
Ajout d&#39;un élément.
Definition: actionSet.h:164
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:202
const Idx & operator[](const Idx i) const
Gives the ith element.
Definition: actionSet.h:190
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size Idx
Type for indexes.
Definition: types.h:53
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:48
<agrum/FMDP/planning/actionSet.h>
Definition: actionSet.h:58
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408