aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
mddOperatorStrategy_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Template implementation of FMDP/planning/MDDOperatorStrategy.h classes.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 
30 // =========================================================================
31 #include <algorithm>
32 #include <queue>
33 #include <thread>
34 #include <utility>
35 #include <vector>
36 // =========================================================================
37 #include <agrum/tools/core/math/math_utils.h>
38 #include <agrum/tools/core/functors.h>
39 // =========================================================================
40 #include <agrum/tools/multidim/potential.h>
41 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/multiDimFunctionGraphOperator.h>
42 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/regress.h>
43 // =========================================================================
44 #include <agrum/FMDP/planning/mddOperatorStrategy.h>
45 // =========================================================================
46 
47 /// For shorter line and hence more comprehensive code only
48 #define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
49 
50 namespace gum {
51 
52 
53  /* **************************************************************************************************
54  * **/
55  /* ** **/
56  /* ** Constructors / Destructors **/
57  /* ** **/
58  /* **************************************************************************************************
59  * **/
60 
61  // ===========================================================================
62  // Default constructor
63  // ===========================================================================
64  template < typename GUM_SCALAR >
65  INLINE MDDOperatorStrategy< GUM_SCALAR >::MDDOperatorStrategy() {
67  }
68 
69  // ===========================================================================
70  // Default destructor
71  // ===========================================================================
72  template < typename GUM_SCALAR >
75  }
76 
77 
78  /* **************************************************************************************************
79  * **/
80  /* ** **/
81  /* ** Graph Function Operations Methods **/
82  /* ** **/
83  /* **************************************************************************************************
84  * **/
85 
86  // ==========================================================================
87  /// Performs a multiplication/projection on given qAction
88  /// @param qAction : the computed Q(s,a)
89  /// @param pxip : the transition probabilities for the xip variable
90  /// @param xip : the variable we eliminate on the projection
91  /// @warning given qAction is deleted, return the new one
92  // ==========================================================================
93  template < typename GUM_SCALAR >
96  Idx actionId,
97  const FMDP< GUM_SCALAR >* fmdp,
98  const Set< const DiscreteVariable* >& elVarSeq) {
101  qAction->copy(*Vold);
102 
103  const DiscreteVariable* xip = this->lastVar_(qAction);
104 
105  while (this->shouldEleminateVar_(xip, fmdp)) {
109  pxi,
110  &elVarSeq,
111  xip,
112  (GUM_SCALAR)0);
114  delete qAction;
115  qAction = temp;
116  xip = this->lastVar_(qAction);
117  }
118 
119  return qAction;
120  }
121 
122  // ==========================================================================
123  // ==========================================================================
124  template < typename GUM_SCALAR >
128  Idx del) {
131  this->deleteFunctionGraph_(f1, f2, del);
132  return ret;
133  }
134 
135  // ==========================================================================
136  // ==========================================================================
137  template < typename GUM_SCALAR >
141  Idx del) {
144  this->deleteFunctionGraph_(f1, f2, del);
145  return ret;
146  }
147 
148  // ==========================================================================
149  // ==========================================================================
150  template < typename GUM_SCALAR >
154  Idx del) {
157  this->deleteFunctionGraph_(f1, f2, del);
158  return ret;
159  }
160 
161 
162  // ==========================================================================
163  // ==========================================================================
164  template < typename GUM_SCALAR >
171  Idx del) {
175  argmaxope(f1, f2);
177  ret
178  = argmaxope.compute();
179  this->deleteFunctionGraph_(f1, f2, del);
180  return ret;
181  }
182 
183  // ==========================================================================
184  /// Adds reward to given function( whether a qAction or vFunction)
185  /// @param reward : R(s) or R(s,a)
186  /// @param function : either V(s) or Q(s,a)
187  /// @warning given function is deleted, returns the new one
188  // ==========================================================================
189  template < typename GUM_SCALAR >
193  Idx del) {
195  this->deleteFunctionGraph_(f1, f2, del);
196  return ret;
197  }
198 
199  // ==========================================================================
200  /// Subtract current VFunction from old VFunction to see if threshold is
201  /// reached or not
202  /// @param old and new VFuntion
203  /// @warning this time, nothing is deleted
204  // ==========================================================================
205  template < typename GUM_SCALAR >
209  Idx del) {
212  this->deleteFunctionGraph_(f1, f2, del);
213  return ret;
214  }
215 
216 
217 } // end of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
#define RECAST(x)
Definition: fmdp_tpl.h:36