aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
fusionContext_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 Templates for fusion context class
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 // =======================================================
30 #include <agrum/tools/core/math/math_utils.h>
31 #include <agrum/FMDP/learning/datastructure/leaves/fusionContext.h>
32 // =======================================================
33 
34 namespace gum {
35 
36  // ############################################################################
37  // Constructors / Destructors
38  // ############################################################################
39 
40  // ============================================================================
41  // Default constructor.
42  // ============================================================================
43  template < bool isInitial >
44  FusionContext< isInitial >::FusionContext(AbstractLeaf* leaf) : leaf__(leaf) {
45  GUM_CONSTRUCTOR(FusionContext);
46  }
47 
48  // ============================================================================
49  // Default constructor.
50  // ============================================================================
51  template < bool isInitial >
54 
55  for (auto leafIter = leaf2Pair__.beginSafe();
57  ++leafIter)
58  delete leafIter.val();
59 
60  delete leaf__;
61  }
62 
63  // ############################################################################
64  //
65  // ############################################################################
66 
67  // ============================================================================
68  //
69  // ============================================================================
70  template < bool isInitial >
72  Int2Type< false >) {
73  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
74  ;
75  LeafPair* p = new LeafPair(l, leaf__);
79 
80  return ptop != pairsHeap__.top();
81  }
82 
83  // ============================================================================
84  //
85  // ============================================================================
86  template < bool isInitial >
88  Int2Type< false >) {
89  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
90  ;
93 
94  return ptop != pairsHeap__.top();
95  }
96 
97  // ============================================================================
98  //
99  // ============================================================================
100  template < bool isInitial >
102  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
103  ;
107  ++pairIter) {
110  }
111  LeafPair* ctop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
112 
113  return ptop != ctop;
114  }
115 
116  // ============================================================================
117  //
118  // ============================================================================
119  template < bool isInitial >
121  Int2Type< false >) {
122  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
125 
126  LeafPair* ctop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
127 
128  return ptop != ctop;
129  }
130 
131 
132  // ############################################################################
133  //
134  // ############################################################################
135 
136  // ============================================================================
137  //
138  // ============================================================================
139  template < bool isInitial >
141  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
143 
144  return ptop != pairsHeap__.top();
145  }
146 
147  // ============================================================================
148  //
149  // ============================================================================
150  template < bool isInitial >
152  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
154 
155  return ptop != pairsHeap__.top();
156  }
157 
158  // ============================================================================
159  //
160  // ============================================================================
161  template < bool isInitial >
163  LeafPair* ptop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
165 
166  LeafPair* ctop = pairsHeap__.empty() ? nullptr : pairsHeap__.top();
167 
168  return ptop != ctop;
169  }
170 
171 
172  // ############################################################################
173  //
174  // ############################################################################
175 
176  // ============================================================================
177  //
178  // ============================================================================
179  template < bool isInitial >
180  Set< LeafPair* >
182  Set< LeafPair* > retBag;
183  for (auto pairIter = leaf2Pair__.beginSafe();
185  ++pairIter)
186  retBag << pairIter.val();
187 
188  return retBag;
189  }
190 
191 
192  template < bool isInitial >
195  if (leaf__)
196  ss << "Associated Leaf : " << leaf__->toString() << std::endl
197  << "Leaves Heap : " << std::endl;
198 
199  // for( HashTableConstIteratorSafe<LeafPair*, std::vector<Size>>
200  // leafIter = pairsHeap__.allValues().cbeginSafe();
201  // leafIter != pairsHeap__.allValues().cendSafe(); ++leafIter ){
202  // ss << leafIter.key()->toString() << std::endl;
203  // }
204  if (!pairsHeap__.empty())
205  ss << "Top pair : " << pairsHeap__.top()->toString() << std::endl;
206 
207  return ss.str();
208  }
209 
210 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669