aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
treeOperatorStrategy_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
52
53// =========================================================================
54#include <algorithm>
55#include <memory>
56#include <queue>
57#include <utility>
58#include <vector>
59// =========================================================================
61
63// =========================================================================
67// =========================================================================
68
70#define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_ELEMENT >* >(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_ELEMENT >
90
91 // ===========================================================================
92 // Default destructor
93 // ===========================================================================
94 template < typename GUM_ELEMENT >
98
99 /* **************************************************************************************************
100 * **/
101 /* ** **/
102 /* ** Graph Function Operations Methods **/
103 /* ** **/
104 /* **************************************************************************************************
105 * **/
106
107 // ==========================================================================
113 // ==========================================================================
114 template < typename GUM_ELEMENT >
117 Idx actionId,
118 const FMDP< GUM_ELEMENT >* fmdp,
119 const gum::VariableSet& elVarSeq) {
120 // ******************************************************************************
121 // Initialisation :
122 // Creating a copy of last Vfunction to deduce from the new Qaction
123 // And finding the first var to eleminate (the one at the end)
125 // the transitions of the frame variables (without transition: they keep their values)
126 std::vector< std::unique_ptr< MultiDimFunctionGraph< GUM_ELEMENT > > > frames;
128 = Vold->variablesSequence().beginSafe();
129 varIter != Vold->variablesSequence().endSafe();
130 ++varIter) {
131 const DiscreteVariable* xi = fmdp->mapMainPrime().first(*varIter);
133 = RECAST(fmdp->transition(actionId, xi));
134 if (transition == nullptr) {
135 frames.emplace_back(this->frameTransition_(xi, *varIter));
136 transition = frames.back().get();
137 }
138 pxi.insert(*varIter, transition);
139 }
140
142 Vold,
143 pxi); //, Vold->variablesSequence(), (GUM_ELEMENT) 0.0 );
144 return tr.compute();
145 }
146
147 // ==========================================================================
149 // ==========================================================================
150 template < typename GUM_ELEMENT >
160
161 // ==========================================================================
163 // ==========================================================================
164 template < typename GUM_ELEMENT >
174
175 // ==========================================================================
176 // ==========================================================================
177 template < typename GUM_ELEMENT >
187
188 // ==========================================================================
191 // ==========================================================================
192 template < typename GUM_ELEMENT >
205
206 // ==========================================================================
211 // ==========================================================================
212 template < typename GUM_ELEMENT >
222
223 // ==========================================================================
228 // ==========================================================================
229 template < typename GUM_ELEMENT >
239
240 template < typename GUM_ELEMENT >
245
246 template < typename GUM_ELEMENT >
252
253 template < typename GUM_ELEMENT >
258
259} // end of namespace gum
Class to handle efficiently argMaxSet.
Definition argMaxSet.h:78
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1640
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)
MultiDimFunctionGraph< GUM_ELEMENT > * frameTransition_(const DiscreteVariable *x, const DiscreteVariable *xp)
Returns a new function graph P(x'|x) = [x' == x].
Class implementingting a function graph.
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Safe iterators for Sequence.
Definition sequence.h:1148
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
MultiDimFunctionGraph< GUM_ELEMENT > * maximize(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 f2 or f1).
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.
~TreeOperatorStrategy() override
Default destructor.
MultiDimFunctionGraph< GUM_ELEMENT > * subtract(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=0) override
Subtract current f1 from old f1 to see if threshold is reached or not.
MultiDimFunctionGraph< GUM_ELEMENT > * minimize(const MultiDimFunctionGraph< GUM_ELEMENT > *f1, const MultiDimFunctionGraph< GUM_ELEMENT > *f2, Idx del=3) override
TreeOperatorStrategy()
Default constructor.
MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > * getArgMaxFunctionInstance() override
MultiDimFunctionGraph< GUM_ELEMENT > * multiply(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
ArgMaximizes between f2 and f1.
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * getAggregatorInstance() override
MultiDimFunctionGraph< GUM_ELEMENT, ExactTerminalNodePolicy > * getFunctionInstance() override
Class used to perform Decision Tree Operation in the FMDP Framework.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Class used to perform Decision Tree Regression in the FMDP Framework.
Definition treeRegress.h:71
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Size Idx
Type for indexes.
Definition types.h:79
Header files of gum::Instantiation.
Useful macros for maths.
#define RECAST(x)
For shorter line and hence more comprehensive code only.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
<agrum/FMDP/planning/actionSet.h>
Definition actionSet.h:76
Headers of the TreeOperatorStrategy planer class.
Class used to compute the operation between two decision diagrams.
Class used to compute the operation between two decision diagrams.