36 #endif // GUM_NO_INLINE 48 _elimination_sequence_strategy(elimSeq.newFactory()),
49 _junction_tree_strategy(JTStrategy.newFactory()), __original_graph(theGraph),
50 __minimality_required(minimality) {
56 if (theGraph !=
nullptr) {
144 if (from.__junction_tree !=
nullptr) {
200 std::vector< NodeId > adj;
226 bool require_mint =
true;
228 for (
unsigned int j = 0; require_mint; ++j) {
233 for (
const auto& edge : T) {
234 node1 = edge.first();
235 node2 = edge.second();
238 if ((R[node1] < j) && (R[node2] < j))
continue;
242 if (__triangulated_graph.neighbours(node2).size()
243 < __triangulated_graph.neighbours(node1).size()) {
253 for (
const auto adjnode : __triangulated_graph.neighbours(node1))
254 if (__triangulated_graph.existsEdge(node2, adjnode))
255 adj.push_back(adjnode);
258 for (
unsigned int k = 0; k < adj.size() && !incomplete; ++k) {
259 for (
unsigned int m = k + 1; m < adj.size(); ++m) {
260 if (!__triangulated_graph.existsEdge(adj[k], adj[m])) {
278 for (
const auto& edge : T_prime) {
280 __triangulated_graph.eraseEdge(edge);
285 if (T_prime.size() == 0) require_mint =
false;
302 numbered_neighbours(std::greater< unsigned int >(),
303 __triangulated_graph.size());
312 NodeId node = numbered_neighbours.pop();
316 for (
const auto neighbour : __triangulated_graph.neighbours(node)) {
318 numbered_neighbours.setPriority(
319 neighbour, 1 + numbered_neighbours.priority(neighbour));
331 for (
const auto neighbour : __triangulated_graph.neighbours(__elim_order[i]))
358 for (
const auto node : list_of_nodes) {
361 if ((node != clique_i_creator) && (child > it_elim_step))
362 child = it_elim_step;
365 if (child <= __original_graph->bound()) {
379 std::vector< Arc >& merged_cliques,
384 if (other_node != from) {
387 bool complete =
true;
389 for (
auto iter_sep1 = separator.
begin();
390 iter_sep1 != separator.
end() && complete;
392 auto iter_sep2 = iter_sep1;
394 for (++iter_sep2; iter_sep2 != separator.
end(); ++iter_sep2) {
403 if (!complete) merged_cliques.push_back(
Arc(other_node, node));
427 T_mpd_cliques.
insert(clik, clik);
431 std::vector< Arc > merged_cliques;
442 for (
unsigned int i = 0; i < merged_cliques.size(); ++i) {
443 T_mpd_cliques[merged_cliques[i].tail()] =
444 T_mpd_cliques[merged_cliques[i].head()];
448 for (
const auto& elt : T_mpd_cliques)
449 if (elt.first == elt.second)
455 for (
const auto& elt : T_mpd_cliques)
456 if (elt.first != elt.second)
465 NodeId node1 = T_mpd_cliques[edge.first()];
466 NodeId node2 = T_mpd_cliques[edge.second()];
468 if (node1 != node2) {
480 for (
const auto& elt : node_2_junction_clique)
501 const NodeSet& clique = __junction_tree->clique(clik_id);
502 std::vector< NodeId > clique_nodes(clique.
size());
505 for (
const auto node : clique) {
506 clique_nodes[i] = node;
510 for (i = 0; i < clique_nodes.size(); ++i) {
511 for (
unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
531 if (graph !=
nullptr) {
573 NodeId removable_node = 0;
575 for (
unsigned int nb_elim = 0; tmp_graph.
size() != 0; ++nb_elim) {
583 cliques << removable_node;
584 for (
const auto clik : tmp_graph.
neighbours(removable_node))
594 for (
auto iter_edges1 = nei.
begin(); iter_edges1 != nei.
end();
596 node1 = *iter_edges1;
597 auto iter_edges2 = iter_edges1;
599 for (++iter_edges2; iter_edges2 != nei.
end(); ++iter_edges2) {
600 node2 = *iter_edges2;
601 Edge edge(node1, node2);
604 current_fill.
insert(edge);
621 for (
auto iter_edges1 = nei.
begin(); iter_edges1 != nei.
end();
623 node1 = *iter_edges1;
624 auto iter_edges2 = iter_edges1;
626 for (++iter_edges2; iter_edges2 != nei.
end(); ++iter_edges2) {
627 node2 = *iter_edges2;
628 Edge edge(node1, node2);
648 for (
auto iter_edges1 = nei.
begin(); iter_edges1 != nei.
end();
650 node1 = *iter_edges1;
651 auto iter_edges2 = iter_edges1;
653 for (++iter_edges2; iter_edges2 != nei.
end(); ++iter_edges2) {
654 node2 = *iter_edges2;
655 Edge edge(node1, node2);
707 std::vector< NodeId > clique_nodes(clique.
size());
710 for (
const auto node : clique) {
711 clique_nodes[i] = node;
715 for (i = 0; i < clique_nodes.size(); ++i) {
716 for (
unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
717 Edge edge(clique_nodes[i], clique_nodes[j]);
const CliqueGraph & junctionTree()
returns a compatible junction tree
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
const UndiGraph & triangulatedGraph()
returns the triangulated graph
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 ...
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
virtual const NodeProperty< NodeId > & createdCliques()=0
returns, for each node, the clique of the junction tree which was created by its deletion ...
virtual void clear()
removes all the nodes and edges from the graph
void clear()
reinitialize the graph to be triangulated to an empty graph
virtual EliminationSequenceStrategy * copyFactory() const =0
virtual copy constructor
NodeProperty< NodeId > __node_2_max_prime_clique
indicates which clique of the max prime junction tree was created by the elmination of a given node (...
void __triangulate()
the function that performs the triangulation
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual ~StaticTriangulation()
destructor
EliminationSequenceStrategy * _elimination_sequence_strategy
the elimination sequence strategy used by the triangulation
const UndiGraph * __original_graph
a pointer to the (external) original graph (which will be triangulated)
virtual void _initTriangulation(UndiGraph &graph)
the function called to initialize the triangulation process
Size size() const
alias for sizeNodes
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
const EdgeSet & fillIns()
returns the fill-ins added by the triangulation algorithm
void __computeMaxPrimeJunctionTree()
computes the junction tree of the maximal prime subgraphs
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
void erase(const Key &k)
Erases an element from the set.
UndiGraph __triangulated_graph
the triangulated graph
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
iterator begin() const
The usual unsafe begin iterator to parse the set.
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
The class for generic Hash Tables.
An efficient unconstrained elimination sequence algorithm.
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes of the graph
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
virtual void eraseNode(const NodeId id)
remove a node and its adjacent edges from the graph
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
virtual void clear()=0
resets the current junction tree strategy data structures
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
A priorityQueue is a heap in which each element has a mutable priorityA priority queue is quite simil...
virtual JunctionTreeStrategy * copyFactory(StaticTriangulation *triangulation=nullptr) const =0
virtual copy constructor
virtual void addToClique(const NodeId clique_id, const NodeId node_id)
changes the set of nodes included into a given clique and returns the new set
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
virtual void setTriangulation(StaticTriangulation *triangulation)=0
assigns the triangulation to the junction tree strategy
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
CliqueGraph __max_prime_junction_tree
the maximal prime subgraph junction tree computed from the junction tree
Base Class for all the algorithms producing a junction given a set of cliques/subcliques resulting fr...
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual bool providesGraphUpdate() const =0
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
virtual NodeId nextNodeToEliminate()=0
returns the new node to be eliminated within the triangulation algorithm
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual StaticTriangulation * newFactory() const =0
returns a fresh triangulation of the same type as the current object but over an empty graph ...
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.
The base class for all undirected edges.
bool __we_want_fill_ins
a boolean indicating if we want fill-ins list with the standard triangulation method ...
bool __has_fill_ins
indicates whether we actually computed fill-ins
bool __minimality_required
indicates whether the triangulation must be minimal
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
base class for all non-incremental triangulation methods
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
void __computeEliminationTree()
returns an elimination tree from a triangulated graph
Base class for undirected graphs.
Size Idx
Type for indexes.
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void setGraph(const UndiGraph *graph, const NodeProperty< Size > *domsizes)
initialize the triangulation data structures for a new graph
void clear()
Removes all the elements, if any, from the set.
void __computeMaxPrimeMergings(const NodeId node, const NodeId from, std::vector< Arc > &merged_cliques, NodeSet &mark) const
used for computing the junction tree of the maximal prime subgraphs
std::size_t Size
In aGrUM, hashed values are unsigned long int.
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
Interface for all the triangulation methods.
Size size() const noexcept
Returns the number of elements in the set.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void __computeRecursiveThinning()
removes redondant fill-ins and compute proper elimination cliques and order
virtual const CliqueGraph & junctionTree()=0
returns the junction tree computed
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
virtual void moveTriangulation(StaticTriangulation *triangulation)
assigns a new triangulation to the junction tree strategy during a move construction ...
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
virtual bool providesFillIns() const =0
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
CliqueGraph __elim_tree
the elimination tree computed by the algorithm
StaticTriangulation(const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
default constructor: without any graph
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void askFillIns(bool do_it)=0
if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to ...
An algorithm producing a junction given the elimination tree produced by a triangulation algorithm...