aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
treeRegress_tpl.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 Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
29  */
30 
31 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/internalNode.h>
32 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/treeOperator.h>
33 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/treeRegress.h>
34 
35 #define ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
36 #define DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
37 
38 namespace gum {
39 
40  template < typename GUM_SCALAR,
41  template < typename >
42  class COMBINEOPERATOR,
43  template < typename >
44  class PROJECTOPERATOR,
45  template < typename >
46  class TerminalNodePolicy >
47  TreeRegress< GUM_SCALAR, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::
48  TreeRegress(
49  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* qAction,
50  const Bijection<
51  const DiscreteVariable*,
52  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* > pxi) :
53  vFunc__(qAction),
54  pxi__(pxi) {
55  GUM_CONSTRUCTOR(TreeRegress);
56  }
57 
58  template < typename GUM_SCALAR,
59  template < typename >
60  class COMBINEOPERATOR,
61  template < typename >
62  class PROJECTOPERATOR,
63  template < typename >
64  class TerminalNodePolicy >
68  }
69 
70  // This function is the main function. To be call every time an operation
71  // between the two given Function Graphs is required
72  template < typename GUM_SCALAR,
73  template < typename >
74  class COMBINEOPERATOR,
75  template < typename >
76  class PROJECTOPERATOR,
77  template < typename >
78  class TerminalNodePolicy >
88  ret->copy(*vFunc__);
89  } else
91  return ret;
92  }
93 
94 
95  template < typename GUM_SCALAR,
96  template < typename >
97  class COMBINEOPERATOR,
98  template < typename >
99  class PROJECTOPERATOR,
100  template < typename >
101  class TerminalNodePolicy >
108 
110  varbucket;
111 
112  for (Idx moda = 0; moda < currentNode->nodeVar()->domainSize(); ++moda) {
117  if (value) {
121  }
122  } else {
124  }
125 
126  if (vpxi != nullptr) {
128  vpxi,
130  context__);
132  }
133  delete vpxi;
135  }
136 
137  if (varbucket.empty()) return nullptr;
138 
141  while (!varbucket.empty()) {
144  vp = projope.compute();
145  delete temp;
146  temp = varbucket.back();
148  delete temp;
149  }
150 
151  return vp;
152  }
153 
154 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669