aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
mddOperatorStrategy_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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) {
130  this->deleteFunctionGraph_(f1, f2, del);
131  return ret;
132  }
133 
134  // ==========================================================================
135  // ==========================================================================
136  template < typename GUM_SCALAR >
140  Idx del) {
142  this->deleteFunctionGraph_(f1, f2, del);
143  return ret;
144  }
145 
146  // ==========================================================================
147  // ==========================================================================
148  template < typename GUM_SCALAR >
152  Idx del) {
154  this->deleteFunctionGraph_(f1, f2, del);
155  return ret;
156  }
157 
158 
159  // ==========================================================================
160  // ==========================================================================
161  template < typename GUM_SCALAR >
166  Idx del) {
170  argmaxope(f1, f2);
172  = argmaxope.compute();
173  this->deleteFunctionGraph_(f1, f2, del);
174  return ret;
175  }
176 
177  // ==========================================================================
178  /// Adds reward to given function( whether a qAction or vFunction)
179  /// @param reward : R(s) or R(s,a)
180  /// @param function : either V(s) or Q(s,a)
181  /// @warning given function is deleted, returns the new one
182  // ==========================================================================
183  template < typename GUM_SCALAR >
187  Idx del) {
189  this->deleteFunctionGraph_(f1, f2, del);
190  return ret;
191  }
192 
193  // ==========================================================================
194  /// Subtract current VFunction from old VFunction to see if threshold is
195  /// reached or not
196  /// @param old and new VFuntion
197  /// @warning this time, nothing is deleted
198  // ==========================================================================
199  template < typename GUM_SCALAR >
203  Idx del) {
205  this->deleteFunctionGraph_(f1, f2, del);
206  return ret;
207  }
208 
209 
210 } // end of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
#define RECAST(x)
Definition: fmdp_tpl.h:36