aGrUM  0.14.2
eliminationSequenceStrategy.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #include <agrum/agrum.h>
29 
30 #ifdef GUM_NO_INLINE
32 #endif // GUM_NOINLINE
33 
34 namespace gum {
35 
36  // an empty fill-ins set returned by default when we ask for a fill-ins set
38 #ifdef GUM_DEBUG_MODE
39  static bool first_use = true;
40  if (first_use) {
41  first_use = false;
42  __debug__::__dec_creation(
43  "Set", "__empty_edge_set", 0, "static variable correction", 0);
44  __debug__::__dec_creation(
45  "HashTable", "__empty_edge_set", 0, "static variable correction", 0);
46  }
47 #endif
48  static EdgeSet empty_fill_ins;
49  return empty_fill_ins;
50  }
51 
52  // default constructor
54  // for debugging purposes
55  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
56  }
57 
58  // constructor for an a priori non empty graph
60  UndiGraph* graph, const NodeProperty< Size >* domain_sizes) {
61  EliminationSequenceStrategy::setGraph(graph, domain_sizes);
62 
63  // for debugging purposes
64  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
65  }
66 
67  // copy constructor
69  const EliminationSequenceStrategy& from) :
70  _graph(from._graph),
73  // for debugging purposes
74  GUM_CONS_CPY(EliminationSequenceStrategy);
75  }
76 
80  _graph(from._graph),
83  // for debugging purposes
84  GUM_CONS_MOV(EliminationSequenceStrategy);
85  }
86 
87  // destructor
89  // for debugging purposes
90  GUM_DESTRUCTOR(EliminationSequenceStrategy);
91  }
92 
93  // performs all the graph/fill-ins updates provided
95 
99  return __empty_fill_ins();
100  }
101 
102  // clears the sequence (to prepare, for instance, a new elimination sequence)
104  _graph = nullptr;
105  _domain_sizes = nullptr;
106  _log_domain_sizes.clear();
107  }
108 
109  // sets a new graph to be triangulated
110  bool
112  const NodeProperty< Size >* dom_sizes) {
113  // check that both the graph and the domain sizes are different from nullptr
114  // or else that both are equal to nullptr
115  if (((graph != nullptr) && (dom_sizes == nullptr))
116  || ((graph == nullptr) && (dom_sizes != nullptr))) {
118  "EliminationSequenceStrategy: one of the graph or the set of "
119  "domain sizes is a null pointer.");
120  }
121 
122  // check that each node has a domain size
123  if (graph != nullptr) {
124  for (const auto node : *graph)
125  if (!dom_sizes->exists(node))
127  "EliminationSequenceStrategy needs a domain size "
128  "for every node in the graph.");
129  }
130 
131  // avoid empty modifications
132  if ((graph != _graph) || (dom_sizes != _domain_sizes)) {
133  // remove, if any, the current graph
134  clear();
135 
136  // assign a new graph
137  _graph = graph;
138  _domain_sizes = dom_sizes;
139 
140  if (_graph != nullptr) {
141  // compute the log of the modalities
142  _log_domain_sizes.resize(_graph->sizeNodes() / 2);
143 
144  for (const auto node : *_graph)
145  _log_domain_sizes.insert(node, std::log((*_domain_sizes)[node]));
146  }
147 
148  return true;
149  }
150 
151  return false;
152  }
153 
154 } /* namespace gum */
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
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 ...
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
STL namespace.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
UndiGraph * graph() const noexcept
returns the current graph
static const EdgeSet & __empty_fill_ins()
an empty fill-ins set used by default
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
Base Class for all elimination sequence algorithms used by triangulations.
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
The base class for all elimination sequence algorithms used by triangulation algorithms.
Base class for undirected graphs.
Definition: undiGraph.h:106
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes
Base Class for all elimination sequence algorithms used by triangulations.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52