aGrUM  0.14.2
treeOperatorStrategy_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 // =========================================================================
29 #include <algorithm>
30 #include <queue>
31 #include <utility>
32 #include <vector>
33 // =========================================================================
34 #include <agrum/core/math/math.h>
36 // =========================================================================
40 // =========================================================================
41 
43 #define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
44 
45 namespace gum {
46 
47 
48  /* **************************************************************************************************
49  * **/
50  /* ** **/
51  /* ** Constructors / Destructors **/
52  /* ** **/
53  /* **************************************************************************************************
54  * **/
55 
56  // ===========================================================================
57  // Default constructor
58  // ===========================================================================
59  template < typename GUM_SCALAR >
61  GUM_CONSTRUCTOR(TreeOperatorStrategy);
62  }
63 
64  // ===========================================================================
65  // Default destructor
66  // ===========================================================================
67  template < typename GUM_SCALAR >
69  GUM_DESTRUCTOR(TreeOperatorStrategy);
70  }
71 
72 
73  /* **************************************************************************************************
74  * **/
75  /* ** **/
76  /* ** Graph Function Operations Methods **/
77  /* ** **/
78  /* **************************************************************************************************
79  * **/
80 
81 
82  // ==========================================================================
88  // ==========================================================================
89  template < typename GUM_SCALAR >
92  Idx actionId,
93  const FMDP< GUM_SCALAR >* fmdp,
94  const Set< const DiscreteVariable* >& elVarSeq) {
95  // ******************************************************************************
96  // Initialisation :
97  // Creating a copy of last Vfunction to deduce from the new Qaction
98  // And finding the first var to eleminate (the one at the end)
101  pxi;
103  Vold->variablesSequence().beginSafe();
104  varIter != Vold->variablesSequence().endSafe();
105  ++varIter) {
106  pxi.insert(
107  *varIter,
108  RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(*varIter))));
109  }
110 
112  Vold, pxi); //, Vold->variablesSequence(), (GUM_SCALAR) 0.0 );
113  return tr.compute();
114  }
115 
116  // ==========================================================================
118  // ==========================================================================
119  template < typename GUM_SCALAR >
124  Idx del) {
127  this->_deleteFunctionGraph(f1, f2, del);
128  return ret;
129  }
130 
131  // ==========================================================================
133  // ==========================================================================
134  template < typename GUM_SCALAR >
139  Idx del) {
142  this->_deleteFunctionGraph(f1, f2, del);
143  return ret;
144  }
145 
146  // ==========================================================================
147  // ==========================================================================
148  template < typename GUM_SCALAR >
153  Idx del) {
156  this->_deleteFunctionGraph(f1, f2, del);
157  return ret;
158  }
159 
160 
161  // ==========================================================================
164  // ==========================================================================
165  template < typename GUM_SCALAR >
169  SetTerminalNodePolicy >* f1,
171  SetTerminalNodePolicy >* f2,
172  Idx del) {
176  argmaxope(f1, f2);
178  ret = argmaxope.compute();
179  this->_deleteFunctionGraph(f1, f2, del);
180  return ret;
181  }
182 
183  // ==========================================================================
188  // ==========================================================================
189  template < typename GUM_SCALAR >
193  Idx del) {
196  this->_deleteFunctionGraph(f1, f2, del);
197  return ret;
198  }
199 
200  // ==========================================================================
205  // ==========================================================================
206  template < typename GUM_SCALAR >
211  Idx del) {
214  this->_deleteFunctionGraph(f1, f2, del);
215  return ret;
216  }
217 
218 
219 } // end of namespace gum
Useful macros for maths.
virtual MultiDimFunctionGraph< GUM_SCALAR > * minimize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
Safe iterators for Sequence.
Definition: sequence.h:1203
~TreeOperatorStrategy()
Default destructor.
virtual MultiDimFunctionGraph< GUM_SCALAR > * add(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=1)
Adds reward to given function( whether a f2 or f1)
Class used to perform Decision Tree Regression in the FMDP Framework.
Definition: treeRegress.h:52
Class used to compute the operation between two decision diagrams.
INLINE const Bijection< const DiscreteVariable *, const DiscreteVariable *> & mapMainPrime() const
Returns the map binding main variables and prime variables.
Definition: fmdp.h:114
This class is used to implement factored decision process.
Definition: fmdp.h:54
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Class used to perform Decision Tree Operation in the FMDP Framework.
Definition: treeOperator.h:50
Class to handle efficiently argMaxSet.
Definition: argMaxSet.h:55
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
MultiDimFunctionGraph< GUM_SCALAR > * regress(const MultiDimFunctionGraph< GUM_SCALAR > *Vold, Idx actionId, const FMDP< GUM_SCALAR > *fmdp, const Set< const DiscreteVariable * > &elVarSeq)
Computes Qaction for given actionid.
const MultiDimImplementation< GUM_SCALAR > * transition(Idx actionId, const DiscreteVariable *v) const
Returns transition associated to given in parameter variable and the given action.
Definition: fmdp_tpl.h:224
<agrum/FMDP/planning/treeOperatorStrategy.h>
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
virtual MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * argmaximize(const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *f1, const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *f2, Idx del=3)
ArgMaximizes between f2 and f1.
Class used to compute the operation between two decision diagrams.
virtual MultiDimFunctionGraph< GUM_SCALAR > * multiply(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Header files of gum::Instantiation.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
TreeOperatorStrategy()
Default constructor.
virtual MultiDimFunctionGraph< GUM_SCALAR > * subtract(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=0)
Subtract current f1 from old f1 to see if threshold is reached or not.
Headers of the TreeOperatorStrategy planer class.
#define RECAST(x)
For shorter line and hence more comprehensive code only.
virtual MultiDimFunctionGraph< GUM_SCALAR > * maximize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
Size Idx
Type for indexes.
Definition: types.h:50
<agrum/FMDP/planning/actionSet.h>
Definition: actionSet.h:55