aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimFunctionGraphOperator.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Class used to compute the operation between two decision diagrams
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
28  * GONZALES(@AMU)
29  */
30 
31 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_OPERATOR_H
32 #define GUM_MULTI_DIM_FUNCTION_GRAPH_OPERATOR_H
33 
34 #include <functional>
35 
36 #include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
37 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/o4DGContext.h>
38 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/terminalNodePolicies/ExactTerminalNodePolicy.h>
39 
40 namespace gum {
41 
42  // clang-format off
43  /**
44  * @class MultiDimFunctionGraphOperator
45  * @headerfile multiDimFunctionGraphOperator.h <agrum/tools/multidim/patterns/multiDimFunctionGraphOperator.h>
46  * @ingroup multidim_group
47  *
48  * @brief Class used to perform Function Graph Operations
49  */
50  // clang-format on
51  template < typename GUM_SCALAR,
52  template < typename >
53  class FUNCTOR,
54  template < typename > class TerminalNodePolicy
57  public:
58  // ============================================================================
59  /// @name Constructors / Destructors
60  // ============================================================================
61  /// @{
62 
63  /**
64  * @brief Default constructor.
65  */
67  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* DG1,
68  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* DG2);
69 
70  /**
71  * @brief Default destructor.
72  */
74 
75  /// @}
76  // ============================================================================
77  /// @name Main Method
78  // ============================================================================
79  /// @{
80 
81  /**
82  * @brief Computes and builds the Function Graph that is the result of the
83  * operation.
84  */
86 
87  /// @}
88 
89  Idx nbCall();
90  Idx nbVarRetro();
92 
93  private:
97 
98  /// Computes an order for the final Decision graph that will minimize the
99  /// number of re exploration
100  void establishVarOrder__();
101 
102  /// Heuristic methods to decide which of two retrograde variables should
103  /// come first
105  const DiscreteVariable*,
106  const DiscreteVariable*);
107 
108  /// Establish for each node in both function graph if it has retrograde
109  /// variables beneath it
111  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* dg,
112  HashTable< NodeId, short int* >& dgInstNeed);
113 
114  /// The main recursion function
116 
117  /// One of the two function graphs used for the operation
119 
120  /// The other one
122 
123  /// The resulting function graph
125 
126  /// The total number of variable implied in the operation
128 
129  /// The function to be performed on the leaves
130  const FUNCTOR< GUM_SCALAR > function__;
131 
132  /// The hashtable used to know if two pair of nodes have already been
133  /// visited
135 
136  /// Table uses to know if a given node of first function graph has
137  /// retrograde vrariables
139 
140  /// Table uses to know if a given node of second function graph has
141  /// retrograde vrariables
143 
144  /// Just a comptuationnal trick
145  short int* default__;
146  };
147 
148 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
149  extern template class MultiDimFunctionGraphOperator< double, std::plus >;
150 #endif
151 
152 } // namespace gum
153 
154 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/multiDimFunctionGraphOperator_tpl.h>
155 
156 #endif // GUM_MULTI_DIM_FUNCTION_GRAPH_OPERATOR_H
void findRetrogradeVariables__(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *dg, HashTable< NodeId, short int * > &dgInstNeed)
Establish for each node in both function graph if it has retrograde variables beneath it...
const FUNCTOR< GUM_SCALAR > function__
The function to be performed on the leaves.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
HashTable< NodeId, short int *> DG1InstantiationNeeded__
Table uses to know if a given node of first function graph has retrograde vrariables.
HashTable< double, NodeId > explorationTable__
The hashtable used to know if two pair of nodes have already been visited.
short int * default__
Just a comptuationnal trick.
void establishVarOrder__()
Computes an order for the final Decision graph that will minimize the number of re exploration...
Idx nbVar__
The total number of variable implied in the operation.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * rd__
The resulting function graph.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * DG1__
One of the two function graphs used for the operation.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * DG2__
The other one.
Class used to perform Function Graph Operations.
Idx distance__(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *, const DiscreteVariable *, const DiscreteVariable *)
Heuristic methods to decide which of two retrograde variables should come first.
HashTable< NodeId, short int *> DG2InstantiationNeeded__
Table uses to know if a given node of second function graph has retrograde vrariables.
MultiDimFunctionGraphOperator(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *DG1, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *DG2)
Default constructor.
NodeId compute__(O4DGContext &currentSituation, Idx lastInstVarPos)
The main recursion function.