aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
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-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
48
49
#include <
agrum/agrum.h
>
50
51
#include <
agrum/base/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy.h
>
52
53
#ifdef GUM_NO_INLINE
54
# include <
agrum/base/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy_inl.h
>
55
#endif
// GU%_NO_INLINE
56
57
namespace
gum
{
58
59
// an empty fill-ins set returned by default when we ask for a fill-ins set
60
const
EdgeSet
&
EliminationSequenceStrategy::_empty_fill_ins_
() {
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
78
EliminationSequenceStrategy::EliminationSequenceStrategy
() {
79
GUM_CONSTRUCTOR(
EliminationSequenceStrategy
);
80
}
81
82
// constructor for a (tensorly) non empty graph
83
EliminationSequenceStrategy::EliminationSequenceStrategy
(
84
UndiGraph
*
graph
,
85
const
NodeProperty< Size >
* domain_sizes) {
86
EliminationSequenceStrategy::setGraph
(
graph
, domain_sizes);
87
88
GUM_CONSTRUCTOR(
EliminationSequenceStrategy
);
89
}
90
91
// copy constructor
92
EliminationSequenceStrategy::EliminationSequenceStrategy
(
93
const
EliminationSequenceStrategy
& from) :
94
graph_
(from.
graph_
),
domain_sizes_
(from.
domain_sizes_
),
95
log_domain_sizes_
(from.
log_domain_sizes_
) {
96
GUM_CONS_CPY(
EliminationSequenceStrategy
);
97
}
98
100
EliminationSequenceStrategy::EliminationSequenceStrategy
(
EliminationSequenceStrategy
&& from) :
101
graph_
(from.
graph_
),
domain_sizes_
(from.
domain_sizes_
),
102
log_domain_sizes_
(
std
::move(from.
log_domain_sizes_
)) {
103
GUM_CONS_MOV(
EliminationSequenceStrategy
);
104
}
105
106
// destructor
107
EliminationSequenceStrategy::~EliminationSequenceStrategy
() {
108
GUM_DESTRUCTOR(
EliminationSequenceStrategy
);
109
}
110
111
// performs all the graph/fill-ins updates provided
112
void
EliminationSequenceStrategy::eliminationUpdate
(
const
NodeId
node) {}
113
116
const
EdgeSet
&
EliminationSequenceStrategy::fillIns
() {
return
_empty_fill_ins_
(); }
117
118
// clears the sequence (to prepare, for instance, a new elimination sequence)
119
void
EliminationSequenceStrategy::clear
() {
120
graph_
=
nullptr
;
121
domain_sizes_
=
nullptr
;
122
log_domain_sizes_
.clear();
123
}
124
125
// sets a new graph to be triangulated
126
bool
EliminationSequenceStrategy::setGraph
(
UndiGraph
*
graph
,
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
))) {
132
GUM_ERROR
(
GraphError
,
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))
141
GUM_ERROR
(
GraphError
,
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 */
agrum.h
gum::EliminationSequenceStrategy::setGraph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
Definition
eliminationSequenceStrategy.cpp:126
gum::EliminationSequenceStrategy::EliminationSequenceStrategy
EliminationSequenceStrategy()
default constructor
Definition
eliminationSequenceStrategy.cpp:78
gum::EliminationSequenceStrategy::log_domain_sizes_
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
Definition
eliminationSequenceStrategy.h:180
gum::EliminationSequenceStrategy::domain_sizes_
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
Definition
eliminationSequenceStrategy.h:177
gum::EliminationSequenceStrategy::graph_
UndiGraph * graph_
the graph to be triangulated
Definition
eliminationSequenceStrategy.h:174
gum::EliminationSequenceStrategy::_empty_fill_ins_
static const EdgeSet & _empty_fill_ins_()
an empty fill-ins set used by default
Definition
eliminationSequenceStrategy.cpp:60
gum::EliminationSequenceStrategy::clear
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
Definition
eliminationSequenceStrategy.cpp:119
gum::EliminationSequenceStrategy::graph
UndiGraph * graph() const noexcept
returns the current graph
Definition
eliminationSequenceStrategy_inl.h:59
gum::EliminationSequenceStrategy::~EliminationSequenceStrategy
virtual ~EliminationSequenceStrategy()
destructor
Definition
eliminationSequenceStrategy.cpp:107
gum::EliminationSequenceStrategy::eliminationUpdate
virtual void eliminationUpdate(const NodeId node)
performs all the graph/fill-ins updates provided (if any)
Definition
eliminationSequenceStrategy.cpp:112
gum::EliminationSequenceStrategy::fillIns
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
Definition
eliminationSequenceStrategy.cpp:116
GraphError
Exception base for graph error.
gum::HashTable::exists
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
Definition
hashTable_tpl.h:591
gum::NodeGraphPart::sizeNodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
Definition
nodeGraphPart_inl.h:295
gum::UndiGraph
Base class for undirected graphs.
Definition
undiGraph.h:130
eliminationSequenceStrategy.h
Base Class for all elimination sequence algorithms used by triangulations.
eliminationSequenceStrategy_inl.h
Base Class for all elimination sequence algorithms used by triangulations.
GUM_ERROR
#define GUM_ERROR(type, msg)
Definition
exceptions.h:76
gum::EdgeSet
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Definition
graphElements.h:391
gum::NodeId
Size NodeId
Type for node ids.
Definition
graphElements.h:117
gum::NodeProperty
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Definition
graphElements.h:407
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
std
STL namespace.
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0