aGrUM  0.14.2
mddOperatorStrategy_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  ***************************************************************************/
27 // =========================================================================
28 #include <algorithm>
29 #include <queue>
30 #include <thread>
31 #include <utility>
32 #include <vector>
33 // =========================================================================
34 #include <agrum/core/math/math.h>
35 #include <agrum/core/functors.h>
36 // =========================================================================
40 // =========================================================================
42 // =========================================================================
43 
45 #define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
46 
47 namespace gum {
48 
49 
50  /* **************************************************************************************************
51  * **/
52  /* ** **/
53  /* ** Constructors / Destructors **/
54  /* ** **/
55  /* **************************************************************************************************
56  * **/
57 
58  // ===========================================================================
59  // Default constructor
60  // ===========================================================================
61  template < typename GUM_SCALAR >
63  GUM_CONSTRUCTOR(MDDOperatorStrategy);
64  }
65 
66  // ===========================================================================
67  // Default destructor
68  // ===========================================================================
69  template < typename GUM_SCALAR >
71  GUM_DESTRUCTOR(MDDOperatorStrategy);
72  }
73 
74 
75  /* **************************************************************************************************
76  * **/
77  /* ** **/
78  /* ** Graph Function Operations Methods **/
79  /* ** **/
80  /* **************************************************************************************************
81  * **/
82 
83  // ==========================================================================
89  // ==========================================================================
90  template < typename GUM_SCALAR >
93  Idx actionId,
94  const FMDP< GUM_SCALAR >* fmdp,
95  const Set< const DiscreteVariable* >& elVarSeq) {
98  qAction->copy(*Vold);
99 
100  const DiscreteVariable* xip = this->_lastVar(qAction);
101 
102  while (this->_shouldEleminateVar(xip, fmdp)) {
104  RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(xip)));
106  qAction, pxi, &elVarSeq, xip, (GUM_SCALAR)0);
108  delete qAction;
109  qAction = temp;
110  xip = this->_lastVar(qAction);
111  }
112 
113  return qAction;
114  }
115 
116  // ==========================================================================
117  // ==========================================================================
118  template < typename GUM_SCALAR >
122  Idx del) {
124  maximize2MultiDimFunctionGraphs(f1, f2);
125  this->_deleteFunctionGraph(f1, f2, del);
126  return ret;
127  }
128 
129  // ==========================================================================
130  // ==========================================================================
131  template < typename GUM_SCALAR >
135  Idx del) {
137  minimize2MultiDimFunctionGraphs(f1, f2);
138  this->_deleteFunctionGraph(f1, f2, del);
139  return ret;
140  }
141 
142  // ==========================================================================
143  // ==========================================================================
144  template < typename GUM_SCALAR >
148  Idx del) {
151  this->_deleteFunctionGraph(f1, f2, del);
152  return ret;
153  }
154 
155 
156  // ==========================================================================
157  // ==========================================================================
158  template < typename GUM_SCALAR >
162  SetTerminalNodePolicy >* f1,
164  SetTerminalNodePolicy >* f2,
165  Idx del) {
169  argmaxope(f1, f2);
171  ret = argmaxope.compute();
172  this->_deleteFunctionGraph(f1, f2, del);
173  return ret;
174  }
175 
176  // ==========================================================================
181  // ==========================================================================
182  template < typename GUM_SCALAR >
186  Idx del) {
188  this->_deleteFunctionGraph(f1, f2, del);
189  return ret;
190  }
191 
192  // ==========================================================================
197  // ==========================================================================
198  template < typename GUM_SCALAR >
202  Idx del) {
205  this->_deleteFunctionGraph(f1, f2, del);
206  return ret;
207  }
208 
209 
210 } // end of namespace gum
Useful macros for maths.
virtual MultiDimFunctionGraph< GUM_SCALAR > * subtract(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=0)
Subtract current VFunction from old VFunction to see if threshold is reached or not.
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.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Definition: regress_tpl.h:101
MDDOperatorStrategy()
Default constructor.
INLINE const Bijection< const DiscreteVariable *, const DiscreteVariable *> & mapMainPrime() const
Returns the map binding main variables and prime variables.
Definition: fmdp.h:114
MultiDimFunctionGraph< T > * subtract2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for subtracting two multiDimArraysThe function produces a tensorial subtractio...
This class is used to implement factored decision process.
Definition: fmdp.h:54
Base class for discrete random variable.
~MDDOperatorStrategy()
Default destructor.
<agrum/FMDP/planning/mddOperatorStrategy.h>
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
This files contains several function objects that are not (yet) defined in the STL.
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
Header of the Potential class.
#define RECAST(x)
For shorter line and hence more comprehensive code only.
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
MultiDimFunctionGraph< T > * multiply2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for multiplying two multiDimArraysThe function produces a tensorial product of...
virtual MultiDimFunctionGraph< GUM_SCALAR > * multiply(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
virtual MultiDimFunctionGraph< GUM_SCALAR > * maximize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
Class used to compute the operation between two decision diagrams.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
Class used to perform Function Graph Operations.
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
Class used to perform Function Graph Operations in the FMDP Framework.
Definition: regress.h:51
MultiDimFunctionGraph< T > * add2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for summing two multiDimArraysThe function produces a tensorial addition of t1...
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 qAction or vFunction)
Headers of the MDDOperatorStrategy planer class.
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)
Class used to compute the operation between two decision diagrams.
Size Idx
Type for indexes.
Definition: types.h:50
virtual MultiDimFunctionGraph< GUM_SCALAR > * minimize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
<agrum/FMDP/planning/actionSet.h>
Definition: actionSet.h:55
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.