aGrUM 3.1.1
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 <queue>
56#include <utility>
57#include <vector>
58// =========================================================================
60
62// =========================================================================
66// =========================================================================
67
69#define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_ELEMENT >* >(x)
70
71namespace gum {
72
73
74 /* **************************************************************************************************
75 * **/
76 /* ** **/
77 /* ** Constructors / Destructors **/
78 /* ** **/
79 /* **************************************************************************************************
80 * **/
81
82 // ===========================================================================
83 // Default constructor
84 // ===========================================================================
85 template < typename GUM_ELEMENT >
89
90 // ===========================================================================
91 // Default destructor
92 // ===========================================================================
93 template < typename GUM_ELEMENT >
97
98 /* **************************************************************************************************
99 * **/
100 /* ** **/
101 /* ** Graph Function Operations Methods **/
102 /* ** **/
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)
126 = Vold->variablesSequence().beginSafe();
127 varIter != Vold->variablesSequence().endSafe();
128 ++varIter) {
129 pxi.insert(*varIter,
130 RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(*varIter))));
131 }
132
134 Vold,
135 pxi); //, Vold->variablesSequence(), (GUM_ELEMENT) 0.0 );
136 return tr.compute();
137 }
138
139 // ==========================================================================
141 // ==========================================================================
142 template < typename GUM_ELEMENT >
152
153 // ==========================================================================
155 // ==========================================================================
156 template < typename GUM_ELEMENT >
166
167 // ==========================================================================
168 // ==========================================================================
169 template < typename GUM_ELEMENT >
179
180 // ==========================================================================
183 // ==========================================================================
184 template < typename GUM_ELEMENT >
197
198 // ==========================================================================
203 // ==========================================================================
204 template < typename GUM_ELEMENT >
214
215 // ==========================================================================
220 // ==========================================================================
221 template < typename GUM_ELEMENT >
231
232 template < typename GUM_ELEMENT >
237
238 template < typename GUM_ELEMENT >
244
245 template < typename GUM_ELEMENT >
250
251} // 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
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)
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.