aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
eliminationSequenceStrategy.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48
49#include <agrum/agrum.h>
50
52
53#ifdef GUM_NO_INLINE
55#endif // GU%_NO_INLINE
56
57namespace gum {
58
59 // an empty fill-ins set returned by default when we ask for a fill-ins set
61#ifdef GUM_DEBUG_MODE
62 static bool first_use = true;
63 if (first_use) {
64 first_use = false;
65 __debug__::_dec_creation_("Set", " __empty_edge_set", 0, "static variable correction", 0);
66 __debug__::_dec_creation_("HashTable",
67 " __empty_edge_set",
68 0,
69 "static variable correction",
70 0);
71 }
72#endif
73 static EdgeSet empty_fill_ins;
74 return empty_fill_ins;
75 }
76
77 // default constructor
81
82 // constructor for a (tensorly) non empty graph
90
91 // copy constructor
98
105
106 // destructor
110
111 // performs all the graph/fill-ins updates provided
113
117
118 // clears the sequence (to prepare, for instance, a new elimination sequence)
120 graph_ = nullptr;
121 domain_sizes_ = nullptr;
122 log_domain_sizes_.clear();
123 }
124
125 // sets a new graph to be triangulated
127 const NodeProperty< Size >* dom_sizes) {
128 // check that both the graph and the domain sizes are different from nullptr
129 // or else that both are equal to nullptr
130 if (((graph != nullptr) && (dom_sizes == nullptr))
131 || ((graph == nullptr) && (dom_sizes != nullptr))) {
133 "EliminationSequenceStrategy: one of the graph or the set of "
134 "domain sizes is a null pointer.");
135 }
136
137 // check that each node has a domain size
138 if (graph != nullptr) {
139 for (const auto node: *graph)
140 if (!dom_sizes->exists(node))
142 "EliminationSequenceStrategy needs a domain size "
143 "for every node in the graph.");
144 }
145
146 // avoid empty modifications
147 if ((graph != graph_) || (dom_sizes != domain_sizes_)) {
148 // remove, if any, the current graph
149 clear();
150
151 // assign a new graph
152 graph_ = graph;
153 domain_sizes_ = dom_sizes;
154
155 if (graph_ != nullptr) {
156 // compute the log of the modalities
157 log_domain_sizes_.resize(graph_->sizeNodes() / 2);
158
159 for (const auto node: *graph_)
160 log_domain_sizes_.insert(node, std::log((*domain_sizes_)[node]));
161 }
162
163 return true;
164 }
165
166 return false;
167 }
168
169} /* namespace gum */
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
UndiGraph * graph_
the graph to be triangulated
static const EdgeSet & _empty_fill_ins_()
an empty fill-ins set used by default
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
UndiGraph * graph() const noexcept
returns the current graph
virtual void eliminationUpdate(const NodeId node)
performs all the graph/fill-ins updates provided (if any)
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
Exception base for graph error.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
Base class for undirected graphs.
Definition undiGraph.h:128
Base Class for all elimination sequence algorithms used by triangulations.
Base Class for all elimination sequence algorithms used by triangulations.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.