aGrUM  0.16.0
defaultEliminationSequenceStrategy.cpp
Go to the documentation of this file.
1 
29 #include <agrum/agrum.h>
30 #include <agrum/core/math/math.h>
32 
33 namespace gum {
34 
37  double theRatio, double theThreshold) :
38  __simplicial_ratio(theRatio),
39  __simplicial_threshold(theThreshold) {
40  // for debugging purposes
41  GUM_CONSTRUCTOR(DefaultEliminationSequenceStrategy);
42  }
43 
47  const NodeProperty< Size >* domain_sizes,
48  double ratio,
49  double threshold) :
50  __simplicial_ratio(ratio),
51  __simplicial_threshold(threshold) {
52  setGraph(graph, domain_sizes);
53 
54  // for debugging purposes
55  GUM_CONSTRUCTOR(DefaultEliminationSequenceStrategy);
56  }
57 
62  // no need to set __log_weights because the copy of the simplicial set
63  // will set it properly
65  _graph,
68  false)),
72  // for debugging purposes
74  }
75 
80  __log_weights(std::move(from.__log_weights)),
85  __simplicial_set->replaceLogWeights(&from.__log_weights, &__log_weights);
86  from.__simplicial_set = nullptr;
87 
88  // for debugging purposes
90  }
91 
94  // for debugging purposes
95  GUM_DESTRUCTOR(DefaultEliminationSequenceStrategy);
96 
97  if (__simplicial_set != nullptr) delete __simplicial_set;
98  }
99 
106  }
107 
111  return new DefaultEliminationSequenceStrategy(*this);
112  }
113 
116  // remove the old simplicial set, if any
117  if (__simplicial_set != nullptr) {
118  delete __simplicial_set;
119  __simplicial_set = nullptr;
120  }
121 
122  if (_graph != nullptr) {
123  // create a simplicial set suited for the graph
126  &__log_weights,
129 
131  }
132  }
133 
136  UndiGraph* graph, const NodeProperty< Size >* domain_sizes) {
137  if (UnconstrainedEliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
139  return true;
140  }
141 
142  return false;
143  }
144 
148 
149  __log_weights.clear();
150  if (__simplicial_set != nullptr) {
151  delete __simplicial_set;
152  __simplicial_set = nullptr;
153  }
154  }
155 
158  // if there is no simplicial set, send an exception
159  if (_graph == nullptr) { GUM_ERROR(NotFound, "the graph is empty"); }
160 
161  // select a node to be eliminated: try simplicial nodes, then almost
162  // simplicial nodes, then quasi-simplicial nodes
163  // note that if __graph != 0, __simplicial_set has been allocated
170  else {
171  // here: select the node through Kjaerulff's heuristic
172  auto iter_heuristic = __log_weights.cbegin();
173 
174  if (iter_heuristic == __log_weights.cend())
175  GUM_ERROR(NotFound, "there exists no more node to eliminate");
176 
177  double min_weight = iter_heuristic.val();
178  NodeId removable_node = iter_heuristic.key();
179  for (++iter_heuristic; iter_heuristic != __log_weights.cend();
180  ++iter_heuristic) {
181  if (iter_heuristic.val() < min_weight) {
182  removable_node = iter_heuristic.key();
183  min_weight = iter_heuristic.val();
184  }
185  }
186 
187  return removable_node;
188  }
189  }
190 
195  __provide_fill_ins = do_it;
196 
197  if (__simplicial_set != nullptr)
199  }
200 
205  return __provide_fill_ins;
206  }
207 
211  return true;
212  }
213 
216  if (__simplicial_set != nullptr) {
219  }
220  }
221 
225  if (!__provide_fill_ins || (__simplicial_set == nullptr))
227  else
228  return __simplicial_set->fillIns();
229  }
230 
231 } /* namespace gum */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
void __createSimplicialSet()
create a new simplicial set suited for the current graph
void makeClique(const NodeId id)
adds the necessary edges so that node &#39;id&#39; and its neighbors form a clique
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
NodeId bestQuasiSimplicialNode()
gets a quasi simplicial node with the lowest clique weight
NodeProperty< double > __log_weights
for each node, the weight of the clique created by the node&#39;s elimination
UndiGraph * _graph
the graph to be triangulated
bool hasQuasiSimplicialNode()
indicates whether there exists a quasi simplicial node
void replaceLogWeights(NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights)
reassigns a new set of cliques&#39; log weights (with the same content)
virtual void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
bool hasAlmostSimplicialNode()
indicates whether there exists an almost simplicial node
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
void eraseClique(const NodeId id)
removes a node and its adjacent edges from the underlying graph
STL namespace.
DefaultEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
virtual bool providesFillIns() const final
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
virtual const EdgeSet & fillIns() final
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
SimplicialSet * __simplicial_set
the simplicial set used for determining the best nodes to eliminate
The class for generic Hash Tables.
Definition: hashTable.h:679
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
UndiGraph * graph() const noexcept
returns the current graph
An efficient unconstrained elimination sequence algorithm.
virtual void askFillIns(bool do_it) final
if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to ...
virtual bool providesGraphUpdate() const final
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
Class enabling fast retrieval of simplicial, quasi and almost simplicial nodes.
Definition: simplicialSet.h:60
bool hasSimplicialNode()
indicates whether there exists a simplicial node
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
sets a new graph to be triangulated
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
NodeId bestAlmostSimplicialNode()
gets the almost simplicial node with the lowest clique weight
virtual void clear() final
clears the sequence (to prepare, for instance, a new elimination sequence)
Base class for undirected graphs.
Definition: undiGraph.h:109
NodeId bestSimplicialNode()
returns the simplicial node with the lowest clique weight
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool __provide_fill_ins
indicates whether we compute new fill-ins
virtual NodeId nextNodeToEliminate() final
returns the new node to be eliminated within the triangulation algorithm
void setFillIns(bool on_off)
sets/unset the fill-ins storage in the standard triangulation procedure
The base class for all elimination sequence algorithms that require only the graph to be triangulated...
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
virtual DefaultEliminationSequenceStrategy * copyFactory() const final
virtual copy constructor
const EdgeSet & fillIns() const
returns the set of all the fill-ins added to the graph so far
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
virtual DefaultEliminationSequenceStrategy * newFactory() const final
creates a new elimination sequence of the same type as the current object, but this sequence contains...