aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
mddOperatorStrategy_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
50
51// =========================================================================
52#include <algorithm>
53#include <queue>
54#include <thread>
55#include <utility>
56#include <vector>
57// =========================================================================
59
61// =========================================================================
65// =========================================================================
67// =========================================================================
68
70#define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
71
72namespace gum {
73
74
75 /* **************************************************************************************************
76 * **/
77 /* ** **/
78 /* ** Constructors / Destructors **/
79 /* ** **/
80 /* **************************************************************************************************
81 * **/
82
83 // ===========================================================================
84 // Default constructor
85 // ===========================================================================
86 template < typename GUM_SCALAR >
90
91 // ===========================================================================
92 // Default destructor
93 // ===========================================================================
94 template < typename GUM_SCALAR >
98
99 /* **************************************************************************************************
100 * **/
101 /* ** **/
102 /* ** Graph Function Operations Methods **/
103 /* ** **/
104 /* **************************************************************************************************
105 * **/
106
107 // ==========================================================================
113 // ==========================================================================
114 template < typename GUM_SCALAR >
117 Idx actionId,
118 const FMDP< GUM_SCALAR >* fmdp,
119 const gum::VariableSet& elVarSeq) {
122 qAction->copy(*Vold);
123
124 const DiscreteVariable* xip = this->lastVar_(qAction);
125
126 while (this->shouldEleminateVar_(xip, fmdp)) {
128 = RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(xip)));
130 pxi,
131 &elVarSeq,
132 xip,
133 (GUM_SCALAR)0);
135 delete qAction;
136 qAction = temp;
137 xip = this->lastVar_(qAction);
138 }
139
140 return qAction;
141 }
142
143 // ==========================================================================
144 // ==========================================================================
145 template < typename GUM_SCALAR >
149 Idx del) {
150 MultiDimFunctionGraph< GUM_SCALAR >* ret = maximize2MultiDimFunctionGraphs(f1, f2);
151 this->deleteFunctionGraph_(f1, f2, del);
152 return ret;
153 }
154
155 // ==========================================================================
156 // ==========================================================================
157 template < typename GUM_SCALAR >
161 Idx del) {
162 MultiDimFunctionGraph< GUM_SCALAR >* ret = minimize2MultiDimFunctionGraphs(f1, f2);
163 this->deleteFunctionGraph_(f1, f2, del);
164 return ret;
165 }
166
167 // ==========================================================================
168 // ==========================================================================
169 template < typename GUM_SCALAR >
178
179 // ==========================================================================
180 // ==========================================================================
181 template < typename GUM_SCALAR >
196
197 // ==========================================================================
202 // ==========================================================================
203 template < typename GUM_SCALAR >
212
213 // ==========================================================================
218 // ==========================================================================
219 template < typename GUM_SCALAR >
228
229
230} // end of namespace gum
Class to handle efficiently argMaxSet.
Definition argMaxSet.h:78
Base class for discrete random variable.
This class is used to implement factored decision process.
Definition fmdp.h:73
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:225
INLINE const Bijection< const DiscreteVariable *, const DiscreteVariable * > & mapMainPrime() const
Returns the map binding main variables and prime variables.
Definition fmdp.h:131
INLINE void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
INLINE const DiscreteVariable * lastVar_(const MultiDimFunctionGraph< GUM_SCALAR > *function)
Returns the last var in the var order for given graph function Called by the evalQaction.
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)
INLINE bool shouldEleminateVar_(const DiscreteVariable *v, const FMDP< GUM_SCALAR > *fmdp)
Indicates if whether or not given var is to be eliminated. Called by the evalQaction.
MDDOperatorStrategy()
Default constructor.
MultiDimFunctionGraph< GUM_SCALAR > * regress(const MultiDimFunctionGraph< GUM_SCALAR > *Vold, Idx actionId, const FMDP< GUM_SCALAR > *fmdp, const gum::VariableSet &elVarSeq)
Computes Qaction for given actionid.
virtual MultiDimFunctionGraph< GUM_SCALAR > * maximize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
~MDDOperatorStrategy()
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 qAction or vFunction).
virtual MultiDimFunctionGraph< GUM_SCALAR > * multiply(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
virtual MultiDimFunctionGraph< GUM_SCALAR > * minimize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
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.
Class used to perform Function Graph Operations.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Class implementingting a function graph.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
Class used to perform Function Graph Operations in the FMDP Framework.
Definition regress.h:69
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
#define RECAST(x)
Definition fmdp_tpl.h:57
This files contains several function objects that are not (yet) defined in the STL.
Size Idx
Type for indexes.
Definition types.h:79
MultiDimFunctionGraph< T > * multiply2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for multiplying two multiDimArrays
MultiDimFunctionGraph< T > * subtract2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for subtracting two multiDimArrays
MultiDimFunctionGraph< T > * add2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for summing two multiDimArrays
Useful macros for maths.
Headers of the MDDOperatorStrategy planer class.
Class used to compute the operation between two decision diagrams.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
Class used to compute the operation between two decision diagrams.
<agrum/FMDP/planning/actionSet.h>
Definition actionSet.h:76
Header of the Tensor class.