aGrUM  0.16.0
eliminationSequenceStrategy.cpp
Go to the documentation of this file.
1 
30 #include <agrum/agrum.h>
32 
33 #ifdef GUM_NO_INLINE
35 #endif // GUM_NOINLINE
36 
37 namespace gum {
38 
39  // an empty fill-ins set returned by default when we ask for a fill-ins set
41 #ifdef GUM_DEBUG_MODE
42  static bool first_use = true;
43  if (first_use) {
44  first_use = false;
45  __debug__::__dec_creation(
46  "Set", "__empty_edge_set", 0, "static variable correction", 0);
47  __debug__::__dec_creation(
48  "HashTable", "__empty_edge_set", 0, "static variable correction", 0);
49  }
50 #endif
51  static EdgeSet empty_fill_ins;
52  return empty_fill_ins;
53  }
54 
55  // default constructor
57  // for debugging purposes
58  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
59  }
60 
61  // constructor for an a priori non empty graph
63  UndiGraph* graph, const NodeProperty< Size >* domain_sizes) {
64  EliminationSequenceStrategy::setGraph(graph, domain_sizes);
65 
66  // for debugging purposes
67  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
68  }
69 
70  // copy constructor
72  const EliminationSequenceStrategy& from) :
73  _graph(from._graph),
76  // for debugging purposes
77  GUM_CONS_CPY(EliminationSequenceStrategy);
78  }
79 
83  _graph(from._graph),
86  // for debugging purposes
87  GUM_CONS_MOV(EliminationSequenceStrategy);
88  }
89 
90  // destructor
92  // for debugging purposes
93  GUM_DESTRUCTOR(EliminationSequenceStrategy);
94  }
95 
96  // performs all the graph/fill-ins updates provided
98 
102  return __empty_fill_ins();
103  }
104 
105  // clears the sequence (to prepare, for instance, a new elimination sequence)
107  _graph = nullptr;
108  _domain_sizes = nullptr;
109  _log_domain_sizes.clear();
110  }
111 
112  // sets a new graph to be triangulated
113  bool
115  const NodeProperty< Size >* dom_sizes) {
116  // check that both the graph and the domain sizes are different from nullptr
117  // or else that both are equal to nullptr
118  if (((graph != nullptr) && (dom_sizes == nullptr))
119  || ((graph == nullptr) && (dom_sizes != nullptr))) {
121  "EliminationSequenceStrategy: one of the graph or the set of "
122  "domain sizes is a null pointer.");
123  }
124 
125  // check that each node has a domain size
126  if (graph != nullptr) {
127  for (const auto node : *graph)
128  if (!dom_sizes->exists(node))
130  "EliminationSequenceStrategy needs a domain size "
131  "for every node in the graph.");
132  }
133 
134  // avoid empty modifications
135  if ((graph != _graph) || (dom_sizes != _domain_sizes)) {
136  // remove, if any, the current graph
137  clear();
138 
139  // assign a new graph
140  _graph = graph;
141  _domain_sizes = dom_sizes;
142 
143  if (_graph != nullptr) {
144  // compute the log of the modalities
145  _log_domain_sizes.resize(_graph->sizeNodes() / 2);
146 
147  for (const auto node : *_graph)
148  _log_domain_sizes.insert(node, std::log((*_domain_sizes)[node]));
149  }
150 
151  return true;
152  }
153 
154  return false;
155  }
156 
157 } /* 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:109
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55