aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
51
52// =========================================================================
53#include <algorithm>
54#include <queue>
55#include <thread>
56#include <utility>
57#include <vector>
58// =========================================================================
60
62// =========================================================================
66// =========================================================================
68// =========================================================================
69
71#define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_ELEMENT >* >(x)
72
73namespace gum {
74
75
76 /* **************************************************************************************************
77 * **/
78 /* ** **/
79 /* ** Constructors / Destructors **/
80 /* ** **/
81 /* **************************************************************************************************
82 * **/
83
84 // ===========================================================================
85 // Default constructor
86 // ===========================================================================
87 template < typename GUM_ELEMENT >
91
92 // ===========================================================================
93 // Default destructor
94 // ===========================================================================
95 template < typename GUM_ELEMENT >
99
100 /* **************************************************************************************************
101 * **/
102 /* ** **/
103 /* ** Graph Function Operations Methods **/
104 /* ** **/
105 /* **************************************************************************************************
106 * **/
107
108 // ==========================================================================
114 // ==========================================================================
115 template < typename GUM_ELEMENT >
118 Idx actionId,
119 const FMDP< GUM_ELEMENT >* fmdp,
120 const gum::VariableSet& elVarSeq) {
123 qAction->copy(*Vold);
124
125 const DiscreteVariable* xip = this->lastVar_(qAction);
126
127 while (this->shouldEleminateVar_(xip, fmdp)) {
129 = RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(xip)));
131 pxi,
132 &elVarSeq,
133 xip,
134 (GUM_ELEMENT)0);
136 delete qAction;
137 qAction = temp;
138 xip = this->lastVar_(qAction);
139 }
140
141 return qAction;
142 }
143
144 // ==========================================================================
145 // ==========================================================================
146 template < typename GUM_ELEMENT >
150 Idx del) {
151 MultiDimFunctionGraph< GUM_ELEMENT >* ret = maximize2MultiDimFunctionGraphs(f1, f2);
152 this->deleteFunctionGraph_(f1, f2, del);
153 return ret;
154 }
155
156 // ==========================================================================
157 // ==========================================================================
158 template < typename GUM_ELEMENT >
162 Idx del) {
163 MultiDimFunctionGraph< GUM_ELEMENT >* ret = minimize2MultiDimFunctionGraphs(f1, f2);
164 this->deleteFunctionGraph_(f1, f2, del);
165 return ret;
166 }
167
168 // ==========================================================================
169 // ==========================================================================
170 template < typename GUM_ELEMENT >
179
180 // ==========================================================================
181 // ==========================================================================
182 template < typename GUM_ELEMENT >
197
198 // ==========================================================================
203 // ==========================================================================
204 template < typename GUM_ELEMENT >
213
214 // ==========================================================================
219 // ==========================================================================
220 template < typename GUM_ELEMENT >
229
230 template < typename GUM_ELEMENT >
232 const FMDP< GUM_ELEMENT >* fmdp) {
233 return v == nullptr ? false : fmdp->mapMainPrime().existsSecond(v);
234 }
235
236 template < typename GUM_ELEMENT >
238 const MultiDimFunctionGraph< GUM_ELEMENT >* function) {
239 return function->variablesSequence().size() == 0
240 ? nullptr
241 : function->variablesSequence().atPos(function->variablesSequence().size() - 1);
242 }
243
244 template < typename GUM_ELEMENT >
249
250 template < typename GUM_ELEMENT >
256
257 template < typename GUM_ELEMENT >
263
264} // end of namespace gum
A class to store the optimal actions.
Definition actionSet.h:98
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:75
const Bijection< const DiscreteVariable *, const DiscreteVariable * > & mapMainPrime() const
Returns the map binding main variables and prime variables.
Definition fmdp_tpl.h:409
const MultiDimImplementation< GUM_ELEMENT > * transition(Idx actionId, const DiscreteVariable *v) const
Returns transition associated to given in parameter variable and the given action.
Definition fmdp_tpl.h:226
void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del)
~MDDOperatorStrategy() override
Default destructor.
MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > * getArgMaxFunctionInstance() override
const DiscreteVariable * lastVar_(const MultiDimFunctionGraph< GUM_ELEMENT > *function)
Returns the last var in the var order for given graph function Called by the evalQaction.
bool shouldEleminateVar_(const DiscreteVariable *v, const FMDP< GUM_ELEMENT > *fmdp)
Indicates if whether or not given var is to be eliminated. Called by the evalQaction.
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * getAggregatorInstance() override
MultiDimFunctionGraph< GUM_ELEMENT > * regress(const MultiDimFunctionGraph< GUM_ELEMENT > *Vold, Idx actionId, const FMDP< GUM_ELEMENT > *fmdp, const gum::VariableSet &elVarSeq) override
Computes Qaction for given actionid.
MultiDimFunctionGraph< GUM_ELEMENT > * minimize(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=3) override
MultiDimFunctionGraph< GUM_ELEMENT > * maximize(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=3) override
MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > * argmaximize(const MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > *f1, const MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > *f2, Idx del=3) override
MultiDimFunctionGraph< GUM_ELEMENT > * subtract(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=0) override
Subtract current VFunction from old VFunction to see if threshold is reached or not.
MultiDimFunctionGraph< GUM_ELEMENT > * multiply(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=3) override
MultiDimFunctionGraph< GUM_ELEMENT > * add(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=1) override
Adds reward to given function( whether a qAction or vFunction).
MultiDimFunctionGraph< GUM_ELEMENT, ExactTerminalNodePolicy > * getFunctionInstance() override
MDDOperatorStrategy()
Default constructor.
Class used to perform Function Graph Operations.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Class implementingting a function graph.
void copy(const MultiDimContainer< GUM_ELEMENT > &src) override
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Class used to perform Function Graph Operations in the FMDP Framework.
Definition regress.h:69
MultiDimFunctionGraph< GUM_ELEMENT, 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.
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.
#define RECAST(x)
For shorter line and hence more comprehensive code only.
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.