aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
eliminationSequenceStrategy.cpp
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 /** @file
23  * @brief implementation of the base class for all elimination sequence
24  *algorithms
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #include <agrum/agrum.h>
30 #include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy.h>
31 
32 #ifdef GUM_NO_INLINE
33 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy_inl.h>
34 #endif // GUM_NOINLINE
35 
36 namespace gum {
37 
38  // an empty fill-ins set returned by default when we ask for a fill-ins set
40 #ifdef GUM_DEBUG_MODE
41  static bool first_use = true;
42  if (first_use) {
43  first_use = false;
45  "__empty_edge_set",
46  0,
47  "static variable correction",
48  0);
49  __debug__::dec_creation__("HashTable",
50  "__empty_edge_set",
51  0,
52  "static variable correction",
53  0);
54  }
55 #endif
56  static EdgeSet empty_fill_ins;
57  return empty_fill_ins;
58  }
59 
60  // default constructor
62  // for debugging purposes
64  }
65 
66  // constructor for an a priori non empty graph
69  const NodeProperty< Size >* domain_sizes) {
71 
72  // for debugging purposes
74  }
75 
76  // copy constructor
82  // for debugging purposes
84  }
85 
86  /// move constructor
92  // for debugging purposes
94  }
95 
96  // destructor
98  // for debugging purposes
100  }
101 
102  // performs all the graph/fill-ins updates provided
104 
105  /** @brief in case fill-ins are provided, this function returns the fill-ins
106  * due to all the nodes eliminated so far */
108  return empty_fill_ins__();
109  }
110 
111  // clears the sequence (to prepare, for instance, a new elimination sequence)
113  graph_ = nullptr;
114  domain_sizes_ = nullptr;
116  }
117 
118  // sets a new graph to be triangulated
119  bool
121  const NodeProperty< Size >* dom_sizes) {
122  // check that both the graph and the domain sizes are different from nullptr
123  // or else that both are equal to nullptr
124  if (((graph != nullptr) && (dom_sizes == nullptr))
125  || ((graph == nullptr) && (dom_sizes != nullptr))) {
127  "EliminationSequenceStrategy: one of the graph or the set of "
128  "domain sizes is a null pointer.");
129  }
130 
131  // check that each node has a domain size
132  if (graph != nullptr) {
133  for (const auto node: *graph)
134  if (!dom_sizes->exists(node))
136  "EliminationSequenceStrategy needs a domain size "
137  "for every node in the graph.");
138  }
139 
140  // avoid empty modifications
141  if ((graph != graph_) || (dom_sizes != domain_sizes_)) {
142  // remove, if any, the current graph
143  clear();
144 
145  // assign a new graph
146  graph_ = graph;
148 
149  if (graph_ != nullptr) {
150  // compute the log of the modalities
152 
153  for (const auto node: *graph_)
155  }
156 
157  return true;
158  }
159 
160  return false;
161  }
162 
163 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669