aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
treeOperatorStrategy_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/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)
106  ++varIter) {
107  pxi.insert(*varIter,
109  }
110 
112  Vold,
113  pxi); //, Vold->variablesSequence(), (GUM_SCALAR) 0.0 );
114  return tr.compute();
115  }
116 
117  // ==========================================================================
118  /// @warning given f1 and f2 are deleted, returns the new one
119  // ==========================================================================
120  template < typename GUM_SCALAR >
124  Idx del) {
127  this->deleteFunctionGraph_(f1, f2, del);
128  return ret;
129  }
130 
131  // ==========================================================================
132  /// @warning given f1 and f2 are deleted, returns the new one
133  // ==========================================================================
134  template < typename GUM_SCALAR >
138  Idx del) {
141  this->deleteFunctionGraph_(f1, f2, del);
142  return ret;
143  }
144 
145  // ==========================================================================
146  // ==========================================================================
147  template < typename GUM_SCALAR >
151  Idx del) {
154  this->deleteFunctionGraph_(f1, f2, del);
155  return ret;
156  }
157 
158 
159  // ==========================================================================
160  /// ArgMaximizes between f2 and f1
161  /// @warning given f1 and f2 are deleted, returns the new one
162  // ==========================================================================
163  template < typename GUM_SCALAR >
168  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 f2 or f1)
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) {
190  this->deleteFunctionGraph_(f1, f2, del);
191  return ret;
192  }
193 
194  // ==========================================================================
195  /// Subtract current f1 from old f1 to see if threshold is
196  /// reached or not
197  /// @param old and new VFuntion
198  /// @warning this time, nothing is deleted
199  // ==========================================================================
200  template < typename GUM_SCALAR >
204  Idx del) {
207  this->deleteFunctionGraph_(f1, f2, del);
208  return ret;
209  }
210 
211 
212 } // end of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
#define RECAST(x)
Definition: fmdp_tpl.h:36