aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
treeOperatorStrategy_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/TreeOperatorStrategy.h
25  * classes.
26  *
27  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
28  * GONZALES(@AMU)
29  */
30 
31 // =========================================================================
32 #include <algorithm>
33 #include <queue>
34 #include <utility>
35 #include <vector>
36 // =========================================================================
37 #include <agrum/tools/core/math/math_utils.h>
38 #include <agrum/tools/multidim/instantiation.h>
39 // =========================================================================
40 #include <agrum/FMDP/planning/treeOperatorStrategy.h>
41 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/treeOperator.h>
42 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/treeRegress.h>
43 // =========================================================================
44 
45 /// For shorter line and hence more comprehensive code only
46 #define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
47 
48 namespace gum {
49 
50 
51  /* **************************************************************************************************
52  * **/
53  /* ** **/
54  /* ** Constructors / Destructors **/
55  /* ** **/
56  /* **************************************************************************************************
57  * **/
58 
59  // ===========================================================================
60  // Default constructor
61  // ===========================================================================
62  template < typename GUM_SCALAR >
63  INLINE TreeOperatorStrategy< GUM_SCALAR >::TreeOperatorStrategy() {
65  }
66 
67  // ===========================================================================
68  // Default destructor
69  // ===========================================================================
70  template < typename GUM_SCALAR >
73  }
74 
75 
76  /* **************************************************************************************************
77  * **/
78  /* ** **/
79  /* ** Graph Function Operations Methods **/
80  /* ** **/
81  /* **************************************************************************************************
82  * **/
83 
84 
85  // ==========================================================================
86  /// Performs a multiplication/projection on given qAction
87  /// @param qAction : the computed Q(s,a)
88  /// @param pxip : the transition probabilities for the xip variable
89  /// @param xip : the variable we eliminate on the projection
90  /// @warning given qAction is deleted, return the new one
91  // ==========================================================================
92  template < typename GUM_SCALAR >
95  Idx actionId,
96  const FMDP< GUM_SCALAR >* fmdp,
97  const Set< const DiscreteVariable* >& elVarSeq) {
98  // ******************************************************************************
99  // Initialisation :
100  // Creating a copy of last Vfunction to deduce from the new Qaction
101  // And finding the first var to eleminate (the one at the end)
102  Bijection< const DiscreteVariable*,
104  pxi;
108  ++varIter) {
109  pxi.insert(
110  *varIter,
112  }
113 
115  Vold,
116  pxi); //, Vold->variablesSequence(), (GUM_SCALAR) 0.0 );
117  return tr.compute();
118  }
119 
120  // ==========================================================================
121  /// @warning given f1 and f2 are deleted, returns the new one
122  // ==========================================================================
123  template < typename GUM_SCALAR >
128  Idx del) {
131  this->deleteFunctionGraph_(f1, f2, del);
132  return ret;
133  }
134 
135  // ==========================================================================
136  /// @warning given f1 and f2 are deleted, returns the new one
137  // ==========================================================================
138  template < typename GUM_SCALAR >
143  Idx del) {
146  this->deleteFunctionGraph_(f1, f2, del);
147  return ret;
148  }
149 
150  // ==========================================================================
151  // ==========================================================================
152  template < typename GUM_SCALAR >
157  Idx del) {
160  this->deleteFunctionGraph_(f1, f2, del);
161  return ret;
162  }
163 
164 
165  // ==========================================================================
166  /// ArgMaximizes between f2 and f1
167  /// @warning given f1 and f2 are deleted, returns the new one
168  // ==========================================================================
169  template < typename GUM_SCALAR >
176  Idx del) {
180  argmaxope(f1, f2);
182  ret
183  = argmaxope.compute();
184  this->deleteFunctionGraph_(f1, f2, del);
185  return ret;
186  }
187 
188  // ==========================================================================
189  /// Adds reward to given function( whether a f2 or f1)
190  /// @param reward : R(s) or R(s,a)
191  /// @param function : either V(s) or Q(s,a)
192  /// @warning given function is deleted, returns the new one
193  // ==========================================================================
194  template < typename GUM_SCALAR >
198  Idx del) {
201  this->deleteFunctionGraph_(f1, f2, del);
202  return ret;
203  }
204 
205  // ==========================================================================
206  /// Subtract current f1 from old f1 to see if threshold is
207  /// reached or not
208  /// @param old and new VFuntion
209  /// @warning this time, nothing is deleted
210  // ==========================================================================
211  template < typename GUM_SCALAR >
216  Idx del) {
219  this->deleteFunctionGraph_(f1, f2, del);
220  return ret;
221  }
222 
223 
224 } // end of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
#define RECAST(x)
Definition: fmdp_tpl.h:36