aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
defaultEliminationSequenceStrategy.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
47
48#include <agrum/agrum.h>
49
51
53
54namespace gum {
55
58 double theThreshold) :
59 _simplicial_ratio_(theRatio), _simplicial_threshold_(theThreshold) {
61 }
62
66 const NodeProperty< Size >* domain_sizes,
67 double ratio,
68 double threshold) : _simplicial_ratio_(ratio), _simplicial_threshold_(threshold) {
69 setGraph(graph, domain_sizes);
70
72 }
73
90
104
111
117
122
125 // remove the old simplicial set, if any
126 if (_simplicial_set_ != nullptr) {
127 delete _simplicial_set_;
128 _simplicial_set_ = nullptr;
129 }
130
131 if (graph_ != nullptr) {
132 // create a simplicial set suited for the graph
138
140 }
141 }
142
145 const NodeProperty< Size >* domain_sizes) {
148 return true;
149 }
150
151 return false;
152 }
153
164
167 // if there is no simplicial set, send an exception
168 if (graph_ == nullptr) { GUM_ERROR(NotFound, "the graph is empty") }
169
170 // select a node to be eliminated: try simplicial nodes, then almost
171 // simplicial nodes, then quasi-simplicial nodes
172 // note that if _graph_ != 0, _simplicial_set_ has been allocated
178 else {
179 // here: select the node through Kjaerulff's heuristic
180 auto iter_heuristic = _log_weights_.cbegin();
181
182 if (iter_heuristic == _log_weights_.cend())
183 GUM_ERROR(NotFound, "there exists no more node to eliminate")
184
185 double min_weight = iter_heuristic.val();
186 NodeId removable_node = iter_heuristic.key();
187 for (++iter_heuristic; iter_heuristic != _log_weights_.cend(); ++iter_heuristic) {
188 if (iter_heuristic.val() < min_weight) {
189 removable_node = iter_heuristic.key();
190 min_weight = iter_heuristic.val();
191 }
192 }
193
194 return removable_node;
195 }
196 }
197
206
211
215
223
231
232} /* namespace gum */
void askFillIns(bool do_it) final
if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to ...
NodeId nextNodeToEliminate() final
returns the new node to be eliminated within the triangulation algorithm
void _createSimplicialSet_()
create a new simplicial set suited for the current graph
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node's elimination
const EdgeSet & fillIns() final
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
bool providesGraphUpdate() const final
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
void clear() final
clears the sequence (to prepare, for instance, a new elimination sequence)
void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
DefaultEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
bool providesFillIns() const final
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
bool _provide_fill_ins_
indicates whether we compute new fill-ins
bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
sets a new graph to be triangulated
DefaultEliminationSequenceStrategy * newFactory() const final
creates a new elimination sequence of the same type as the current object, but this sequence contains...
DefaultEliminationSequenceStrategy * copyFactory() const final
virtual copy constructor
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
UndiGraph * graph_
the graph to be triangulated
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
Exception : the element we looked for cannot be found.
Class enabling fast retrieval of simplicial, quasi and almost simplicial nodes.
NodeId bestSimplicialNode()
returns the simplicial node with the lowest clique weight
bool hasSimplicialNode()
indicates whether there exists a simplicial node
bool hasAlmostSimplicialNode()
indicates whether there exists an almost simplicial node
SimplicialSet(UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
constructor. initializes the simplicial set w.r.t. a given graph
NodeId bestAlmostSimplicialNode()
gets the almost simplicial node with the lowest clique weight
NodeId bestQuasiSimplicialNode()
gets a quasi simplicial node with the lowest clique weight
void makeClique(const NodeId id)
adds the necessary edges so that node 'id' and its neighbors form a clique
void setFillIns(bool on_off)
sets/unset the fill-ins storage in the standard triangulation procedure
void replaceLogWeights(NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights)
reassigns a new set of cliques' log weights (with the same content)
void eraseClique(const NodeId id)
removes a node and its adjacent edges from the underlying graph
bool hasQuasiSimplicialNode()
indicates whether there exists a quasi simplicial node
const EdgeSet & fillIns() const
returns the set of all the fill-ins added to the graph so far
Base class for undirected graphs.
Definition undiGraph.h:130
An efficient unconstrained elimination sequence algorithm.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Useful macros for maths.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.