aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
multiDimFunctionGraphOperator.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 = ExactTerminalNodePolicy >
56  public:
57  // ============================================================================
58  /// @name Constructors / Destructors
59  // ============================================================================
60  /// @{
61 
62  /**
63  * @brief Default constructor.
64  */
66  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* DG1,
67  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* DG2);
68 
69  /**
70  * @brief Default destructor.
71  */
73 
74  /// @}
75  // ============================================================================
76  /// @name Main Method
77  // ============================================================================
78  /// @{
79 
80  /**
81  * @brief Computes and builds the Function Graph that is the result of the
82  * operation.
83  */
85 
86  /// @}
87 
88  Idx nbCall();
89  Idx nbVarRetro();
91 
92  private:
96 
97  /// Computes an order for the final Decision graph that will minimize the
98  /// number of re exploration
99  void _establishVarOrder_();
100 
101  /// Heuristic methods to decide which of two retrograde variables should
102  /// come first
104  const DiscreteVariable*,
105  const DiscreteVariable*);
106 
107  /// Establish for each node in both function graph if it has retrograde
108  /// variables beneath it
109  void
110  _findRetrogradeVariables_(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* dg,
111  HashTable< NodeId, short int* >& dgInstNeed);
112 
113  /// The main recursion function
115 
116  /// One of the two function graphs used for the operation
118 
119  /// The other one
121 
122  /// The resulting function graph
124 
125  /// The total number of variable implied in the operation
127 
128  /// The function to be performed on the leaves
129  const FUNCTOR< GUM_SCALAR > _function_;
130 
131  /// The hashtable used to know if two pair of nodes have already been
132  /// visited
134 
135  /// Table uses to know if a given node of first function graph has
136  /// retrograde vrariables
138 
139  /// Table uses to know if a given node of second function graph has
140  /// retrograde vrariables
142 
143  /// Just a comptuationnal trick
144  short int* _default_;
145  };
146 
147 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
148  extern template class MultiDimFunctionGraphOperator< double, std::plus >;
149 #endif
150 
151 } // namespace gum
152 
153 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/multiDimFunctionGraphOperator_tpl.h>
154 
155 #endif // GUM_MULTI_DIM_FUNCTION_GRAPH_OPERATOR_H
NodeId _compute_(O4DGContext &currentSituation, Idx lastInstVarPos)
The main recursion function.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _DG1_
One of the two function graphs used for the operation.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
HashTable< NodeId, short int *> _DG2InstantiationNeeded_
Table uses to know if a given node of second function graph has retrograde vrariables.
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 MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _DG2_
The other one.
void _establishVarOrder_()
Computes an order for the final Decision graph that will minimize the number of re exploration...
HashTable< double, NodeId > _explorationTable_
The hashtable used to know if two pair of nodes have already been visited.
Idx _distance_(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *, const DiscreteVariable *, const DiscreteVariable *)
Heuristic methods to decide which of two retrograde variables should come first.
short int * _default_
Just a comptuationnal trick.
Idx _nbVar_
The total number of variable implied in the operation.
const FUNCTOR< GUM_SCALAR > _function_
The function to be performed on the leaves.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _rd_
The resulting function graph.
Class used to perform Function Graph Operations.
HashTable< NodeId, short int *> _DG1InstantiationNeeded_
Table uses to know if a given node of first function graph has retrograde vrariables.
MultiDimFunctionGraphOperator(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *DG1, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *DG2)
Default constructor.