aGrUM 2.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-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
51
52// =========================================================================
53#include <algorithm>
54#include <queue>
55#include <utility>
56#include <vector>
57// =========================================================================
59
61// =========================================================================
65// =========================================================================
66
68#define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
69
70namespace gum {
71
72
73 /* **************************************************************************************************
74 * **/
75 /* ** **/
76 /* ** Constructors / Destructors **/
77 /* ** **/
78 /* **************************************************************************************************
79 * **/
80
81 // ===========================================================================
82 // Default constructor
83 // ===========================================================================
84 template < typename GUM_SCALAR >
88
89 // ===========================================================================
90 // Default destructor
91 // ===========================================================================
92 template < typename GUM_SCALAR >
96
97 /* **************************************************************************************************
98 * **/
99 /* ** **/
100 /* ** Graph Function Operations Methods **/
101 /* ** **/
102 /* **************************************************************************************************
103 * **/
104
105
106 // ==========================================================================
112 // ==========================================================================
113 template < typename GUM_SCALAR >
116 Idx actionId,
117 const FMDP< GUM_SCALAR >* fmdp,
118 const gum::VariableSet& elVarSeq) {
119 // ******************************************************************************
120 // Initialisation :
121 // Creating a copy of last Vfunction to deduce from the new Qaction
122 // And finding the first var to eleminate (the one at the end)
125 = Vold->variablesSequence().beginSafe();
126 varIter != Vold->variablesSequence().endSafe();
127 ++varIter) {
128 pxi.insert(*varIter,
129 RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(*varIter))));
130 }
131
133 Vold,
134 pxi); //, Vold->variablesSequence(), (GUM_SCALAR) 0.0 );
135 return tr.compute();
136 }
137
138 // ==========================================================================
140 // ==========================================================================
141 template < typename GUM_SCALAR >
151
152 // ==========================================================================
154 // ==========================================================================
155 template < typename GUM_SCALAR >
165
166 // ==========================================================================
167 // ==========================================================================
168 template < typename GUM_SCALAR >
178
179 // ==========================================================================
182 // ==========================================================================
183 template < typename GUM_SCALAR >
196
197 // ==========================================================================
202 // ==========================================================================
203 template < typename GUM_SCALAR >
213
214 // ==========================================================================
219 // ==========================================================================
220 template < typename GUM_SCALAR >
230
231
232} // 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:1594
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)
Class implementingting a function graph.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Safe iterators for Sequence.
Definition sequence.h:1134
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
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 f2 or f1).
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 > * 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 > * maximize(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
TreeOperatorStrategy()
Default constructor.
~TreeOperatorStrategy()
Default destructor.
virtual MultiDimFunctionGraph< GUM_SCALAR > * subtract(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=0)
Subtract current f1 from old f1 to see if threshold is reached or not.
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)
ArgMaximizes between f2 and f1.
Class used to perform Decision Tree Operation in the FMDP Framework.
MultiDimFunctionGraph< GUM_SCALAR, 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_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
#define RECAST(x)
Definition fmdp_tpl.h:57
Size Idx
Type for indexes.
Definition types.h:79
Header files of gum::Instantiation.
Useful macros for maths.
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.