aGrUM  0.14.2
partialOrderedEliminationSequenceStrategy.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  ***************************************************************************/
32 
33 #ifdef GUM_NO_INLINE
35 #endif // GUM_NOINLINE
36 
37 namespace gum {
38 
42  // for debugging purposes
44  }
45 
50  const NodeProperty< Size >* dom_sizes,
51  const List< NodeSet >* subsets) {
52  setGraph(graph, dom_sizes);
53  setPartialOrder(subsets);
54 
55  // for debugging purposes
57  }
58 
66  // for debugging purposes
68  }
69 
74  EliminationSequenceStrategy(std::move(from)),
76  _nodeset(std::move(from._nodeset)),
78  from._partial_order_needed = true;
79 
80  // for debugging purposes
82  }
83 
87  // for debugging purposes
89  }
90 
93  UndiGraph* graph, const NodeProperty< Size >* domain_sizes) {
94  if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
96  return true;
97  }
98  return false;
99  }
100 
103  const List< NodeSet >* subsets) const {
104  if ((_graph == nullptr) || (subsets == nullptr)) return true;
105 
106  // determine the set of nodes in the subsets that belong to the graph
107  NodeSet nodes_found(_graph->size() / 2);
108  for (const auto& nodes : *subsets) {
109  for (const auto node : nodes) {
110  if (_graph->existsNode(node)) { nodes_found.insert(node); }
111  }
112  }
113 
114  // check that the size of nodes_found is equal to that of the graph
115  return nodes_found.size() != _graph->size();
116  }
117 
120  const List< NodeSet >* subsets) {
121  // check that the partial order contains all the nodes of the graph
123 
124  if (!_partial_order_needed) {
125  _subsets = subsets;
126 
127  // initialize properly the set of nodes that can be currently eliminated:
128  // find the first subset that contains some node(s) of the graph
129  _nodeset.clear();
130  for (_subset_iter = _subsets->cbegin(); _subset_iter != _subsets->cend();
131  ++_subset_iter) {
132  for (const auto node : *_subset_iter) {
133  if (_graph->existsNode(node)) { _nodeset.insert(node); }
134  }
135  if (!_nodeset.empty()) return true;
136  }
137  }
138 
139  return false;
140  }
141 
145  _subsets = nullptr;
146  _nodeset.clear();
147  _partial_order_needed = true;
148  }
149 
150 } /* namespace gum */
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes e...
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
UndiGraph * _graph
the graph to be triangulated
bool _isPartialOrderNeeded(const List< NodeSet > *subsets) const
indicate whether a partial ordering is compatible with the current graph
Size size() const
alias for sizeNodes
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
STL namespace.
Generic doubly linked lists.
Definition: list.h:369
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
Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes e...
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes e...
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
NodeSet _nodeset
the nodes which can be currently eliminated
const List< NodeSet > * _subsets
the subsets constituting the partial ordering
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
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
List< NodeSet >::const_iterator _subset_iter
the iterator indicating which is the current subset on which we work
bool _partial_order_needed
indicate whether a new partial ordering is necessary for the elimination
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610