aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::PartialOrderedEliminationSequenceStrategy Class Referenceabstract

Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes elimination sequence, that is, the set of all the nodes is divided into several subsets. More...

#include <partialOrderedEliminationSequenceStrategy.h>

+ Inheritance diagram for gum::PartialOrderedEliminationSequenceStrategy:
+ Collaboration diagram for gum::PartialOrderedEliminationSequenceStrategy:

Public Member Functions

Accessors / Modifiers
virtual bool setGraph (UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
 sets a new graph to be triangulated More...
 
virtual bool setPartialOrder (const List< NodeSet > *subsets)
 sets a new partial ordering constraint on the elimination sequence More...
 
virtual void clear ()
 clears the sequence (to prepare, for instance, a new elimination sequence) More...
 
const List< NodeSet > * partialOrder () const noexcept
 returns the current partial ordering More...
 
bool isPartialOrderNeeded () const noexcept
 indicates if a new partial ordering is needed More...
 
Accessors / Modifiers
virtual NodeId nextNodeToEliminate ()=0
 returns the new node to be eliminated within the triangulation algorithm More...
 
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 be activated More...
 
virtual bool providesFillIns () const =0
 indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself. More...
 
virtual bool providesGraphUpdate () const =0
 indicates whether the elimination sequence updates by itself the graph after a node has been eliminated More...
 
virtual void eliminationUpdate (const NodeId node)
 performs all the graph/fill-ins updates provided (if any) More...
 
virtual const EdgeSetfillIns ()
 in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far More...
 
UndiGraphgraph () const noexcept
 returns the current graph More...
 
const NodeProperty< Size > * domainSizes () const noexcept
 returns the current domain sizes More...
 

Protected Attributes

const List< NodeSet > * subsets_ {nullptr}
 the subsets constituting the partial ordering More...
 
List< NodeSet >::const_iterator subset_iter_
 the iterator indicating which is the current subset on which we work More...
 
NodeSet nodeset_
 the nodes which can be currently eliminated More...
 
bool partial_order_needed_ {true}
 indicate whether a new partial ordering is necessary for the elimination More...
 
UndiGraphgraph_ {nullptr}
 the graph to be triangulated More...
 
const NodeProperty< Size > * domain_sizes_ {nullptr}
 the domain sizes of the variables/nodes More...
 
NodeProperty< doublelog_domain_sizes_
 the log of the domain sizes of the variables/nodes More...
 

Protected Member Functions

bool isPartialOrderNeeded_ (const List< NodeSet > *subsets) const
 indicate whether a partial ordering is compatible with the current graph More...
 

Constructors / Destructors

virtual ~PartialOrderedEliminationSequenceStrategy ()
 destructor More...
 
virtual PartialOrderedEliminationSequenceStrategynewFactory () const =0
 creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph More...
 
virtual PartialOrderedEliminationSequenceStrategycopyFactory () const =0
 virtual copy constructor More...
 
 PartialOrderedEliminationSequenceStrategy ()
 default constructor (uses an empty graph) More...
 
 PartialOrderedEliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const List< NodeSet > *subsets)
 constructor for an a priori non empty graph More...
 
 PartialOrderedEliminationSequenceStrategy (const PartialOrderedEliminationSequenceStrategy &)
 copy constructor More...
 
 PartialOrderedEliminationSequenceStrategy (PartialOrderedEliminationSequenceStrategy &&)
 move constructor More...
 

Detailed Description

Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes elimination sequence, that is, the set of all the nodes is divided into several subsets.

Within each subset, any ordering can be chosen. But all the nodes of the first subset must be eliminated before the nodes of the second, which must be eliminated before those of the third subset, and so on.

Definition at line 54 of file partialOrderedEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ ~PartialOrderedEliminationSequenceStrategy()

gum::PartialOrderedEliminationSequenceStrategy::~PartialOrderedEliminationSequenceStrategy ( )
virtual

destructor

Definition at line 82 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

82  {
83  // for debugging purposes
85  }
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ PartialOrderedEliminationSequenceStrategy() [1/4]

gum::PartialOrderedEliminationSequenceStrategy::PartialOrderedEliminationSequenceStrategy ( )
protected

default constructor (uses an empty graph)

default constructor

Definition at line 42 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

42  {
43  // for debugging purposes
45  }
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ PartialOrderedEliminationSequenceStrategy() [2/4]

gum::PartialOrderedEliminationSequenceStrategy::PartialOrderedEliminationSequenceStrategy ( UndiGraph graph,
const NodeProperty< Size > *  dom_sizes,
const List< NodeSet > *  subsets 
)
protected

constructor for an a priori non empty graph

Parameters
graphthe graph to be triangulated, i.e., the nodes of which will be eliminated
dom_sizesthedomain sizes of the nodes/variables
subsetsthe list of the subsets constituting the partial ordering
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph, the domain sizes and the sequence are not copied but only referenced by the elimination sequence algorithm.

Definition at line 48 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

51  {
52  setGraph(graph, dom_sizes);
53  setPartialOrder(subsets);
54 
55  // for debugging purposes
57  }
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
UndiGraph * graph() const noexcept
returns the current graph
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
+ Here is the call graph for this function:

◆ PartialOrderedEliminationSequenceStrategy() [3/4]

gum::PartialOrderedEliminationSequenceStrategy::PartialOrderedEliminationSequenceStrategy ( const PartialOrderedEliminationSequenceStrategy from)
protected

copy constructor

Definition at line 60 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

61  :
63  subsets_(from.subsets_), subset_iter_(from.subset_iter_), nodeset_(from.nodeset_),
64  partial_order_needed_(from.partial_order_needed_) {
65  // for debugging purposes
67  }
List< NodeSet >::const_iterator subset_iter_
the iterator indicating which is the current subset on which we work
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
NodeSet nodeset_
the nodes which can be currently eliminated
+ Here is the call graph for this function:

◆ PartialOrderedEliminationSequenceStrategy() [4/4]

gum::PartialOrderedEliminationSequenceStrategy::PartialOrderedEliminationSequenceStrategy ( PartialOrderedEliminationSequenceStrategy &&  from)
protected

move constructor

Definition at line 70 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

71  :
72  EliminationSequenceStrategy(std::move(from)),
73  subsets_(from.subsets_), subset_iter_(from.subset_iter_), nodeset_(std::move(from.nodeset_)),
74  partial_order_needed_(from.partial_order_needed_) {
75  from.partial_order_needed_ = true;
76 
77  // for debugging purposes
79  }
List< NodeSet >::const_iterator subset_iter_
the iterator indicating which is the current subset on which we work
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
NodeSet nodeset_
the nodes which can be currently eliminated
+ Here is the call graph for this function:

Member Function Documentation

◆ askFillIns()

virtual void gum::EliminationSequenceStrategy::askFillIns ( bool  do_it)
pure virtualinherited

if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to be activated

Parameters
do_itwhen true and the elimination sequence has the ability to compute fill-ins, the elimination sequence will actually compute them (for the triangulation to use them), else they will not be available.

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ clear()

void gum::PartialOrderedEliminationSequenceStrategy::clear ( )
virtual

clears the sequence (to prepare, for instance, a new elimination sequence)

Reimplemented from gum::EliminationSequenceStrategy.

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy.

Definition at line 138 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

138  {
140  subsets_ = nullptr;
141  nodeset_.clear();
142  partial_order_needed_ = true;
143  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
NodeSet nodeset_
the nodes which can be currently eliminated
+ Here is the call graph for this function:

◆ copyFactory()

virtual PartialOrderedEliminationSequenceStrategy* gum::PartialOrderedEliminationSequenceStrategy::copyFactory ( ) const
pure virtual

◆ domainSizes()

INLINE const NodeProperty< Size > * gum::EliminationSequenceStrategy::domainSizes ( ) const
noexceptinherited

returns the current domain sizes

Definition at line 40 of file eliminationSequenceStrategy_inl.h.

References gum::Set< Key, Alloc >::emplace().

40  {
41  return domain_sizes_;
42  }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
+ Here is the call graph for this function:

◆ eliminationUpdate()

void gum::EliminationSequenceStrategy::eliminationUpdate ( const NodeId  node)
virtualinherited

performs all the graph/fill-ins updates provided (if any)

Parameters
nodethe node the elimination of which requires the graph update

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

Definition at line 91 of file eliminationSequenceStrategy.cpp.

91 {}

◆ fillIns()

const EdgeSet & gum::EliminationSequenceStrategy::fillIns ( )
virtualinherited

in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

Definition at line 95 of file eliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

95 { return _empty_fill_ins_(); }
static const EdgeSet & _empty_fill_ins_()
an empty fill-ins set used by default
+ Here is the call graph for this function:

◆ graph()

INLINE UndiGraph * gum::EliminationSequenceStrategy::graph ( ) const
noexceptinherited

returns the current graph

Definition at line 36 of file eliminationSequenceStrategy_inl.h.

References gum::Set< Key, Alloc >::emplace().

36 { return graph_; }
UndiGraph * graph_
the graph to be triangulated
+ Here is the call graph for this function:

◆ isPartialOrderNeeded()

INLINE bool gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded ( ) const
noexcept

indicates if a new partial ordering is needed

if the current partial ordering does not contain all the nodes of the graph or if the graph itself is not defined (nullptr) a new partial ordering will be needed for the next triangulation

Definition at line 44 of file partialOrderedEliminationSequenceStrategy_inl.h.

References gum::Set< Key, Alloc >::emplace().

44  {
45  return partial_order_needed_;
46  }
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
+ Here is the call graph for this function:

◆ isPartialOrderNeeded_()

bool gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded_ ( const List< NodeSet > *  subsets) const
protected

indicate whether a partial ordering is compatible with the current graph

The method checks whether all the nodes of the graph belong to the partial ordering.

Returns
true if some nodes in graph_ do not belong to subsets or if graph_ is not defnined (nullptr)

Definition at line 99 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

100  {
101  if ((graph_ == nullptr) || (subsets == nullptr)) return true;
102 
103  // determine the set of nodes in the subsets that belong to the graph
104  NodeSet nodes_found(graph_->size() / 2);
105  for (const auto& nodes: *subsets) {
106  for (const auto node: nodes) {
107  if (graph_->existsNode(node)) { nodes_found.insert(node); }
108  }
109  }
110 
111  // check that the size of nodes_found is equal to that of the graph
112  return nodes_found.size() != graph_->size();
113  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size size() const
alias for sizeNodes
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
UndiGraph * graph_
the graph to be triangulated
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ newFactory()

virtual PartialOrderedEliminationSequenceStrategy* gum::PartialOrderedEliminationSequenceStrategy::newFactory ( ) const
pure virtual

creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph

Warning
you must deallocate by yourself the object returned
Returns
an empty clone of the current object with the same type

Implements gum::EliminationSequenceStrategy.

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy.

◆ nextNodeToEliminate()

virtual NodeId gum::EliminationSequenceStrategy::nextNodeToEliminate ( )
pure virtualinherited

returns the new node to be eliminated within the triangulation algorithm

Exceptions
NotFoundexception is thrown if there is no more node to eliminate in the graph

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ partialOrder()

INLINE const List< NodeSet > * gum::PartialOrderedEliminationSequenceStrategy::partialOrder ( ) const
noexcept

returns the current partial ordering

Definition at line 38 of file partialOrderedEliminationSequenceStrategy_inl.h.

References gum::Set< Key, Alloc >::emplace().

38  {
39  return subsets_;
40  }
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
+ Here is the call graph for this function:

◆ providesFillIns()

virtual bool gum::EliminationSequenceStrategy::providesFillIns ( ) const
pure virtualinherited

indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself.

An elimination sequence provides fill-ins to its triangulation if and only if it has the ability to compute them and it has been asked to do so (by method askFillIns)

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ providesGraphUpdate()

virtual bool gum::EliminationSequenceStrategy::providesGraphUpdate ( ) const
pure virtualinherited

indicates whether the elimination sequence updates by itself the graph after a node has been eliminated

Some algorithms have more informations than the triangulation algorithm to update the graph after a node has been eliminated. They can thus exploit these informations to update the graph faster than the triangulation itself. Hence the latter should delegate this operation to the elimination sequence. This is the case, for instance, for the defaultEliminationSequenceStrategy, which uses a SimplicialSet that knows that some eliminated nodes do not require any fill-in.

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ setGraph()

bool gum::PartialOrderedEliminationSequenceStrategy::setGraph ( UndiGraph graph,
const NodeProperty< Size > *  dom_sizes 
)
virtual

sets a new graph to be triangulated

The elimination sequence algorithms reinitializes its data to start a new triangulation with graph Graph

Parameters
graphthe new graph to be triangulated
dom_sizesthe domain sizes of the nodes/variables
Returns
true if the data structures were modified (if the graph or the domain sizes did not change, then there is no need to update the data structures).
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph and the sequence are not copied but only referenced by the elimination sequence algorithm.

Reimplemented from gum::EliminationSequenceStrategy.

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy.

Definition at line 89 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

90  {
91  if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
93  return true;
94  }
95  return false;
96  }
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
UndiGraph * graph() const noexcept
returns the current graph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
+ Here is the call graph for this function:

◆ setPartialOrder()

bool gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder ( const List< NodeSet > *  subsets)
virtual

sets a new partial ordering constraint on the elimination sequence

sets a new partial order

Parameters
subsetsthe list of the subsets constituting the partial ordering
Returns
true if the new partial order has been successfully assigned (i.e., if all the nodes of the graph belong to one of the subsets)
Warning
if the subsets contain some nodes that do not belong to the graph, then these nodes are simply ignored.
note that, by aGrUM's rule, the partial ordering is not copied but only referenced by the elimination sequence algorithm.

Definition at line 116 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::Set< Key, Alloc >::emplace().

116  {
117  // check that the partial order contains all the nodes of the graph
119 
120  if (!partial_order_needed_) {
121  subsets_ = subsets;
122 
123  // initialize properly the set of nodes that can be currently eliminated:
124  // find the first subset that contains some node(s) of the graph
125  nodeset_.clear();
126  for (subset_iter_ = subsets_->cbegin(); subset_iter_ != subsets_->cend(); ++subset_iter_) {
127  for (const auto node: *subset_iter_) {
128  if (graph_->existsNode(node)) { nodeset_.insert(node); }
129  }
130  if (!nodeset_.empty()) return true;
131  }
132  }
133 
134  return false;
135  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
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
bool isPartialOrderNeeded_(const List< NodeSet > *subsets) const
indicate whether a partial ordering is compatible with the current graph
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
UndiGraph * graph_
the graph to be triangulated
NodeSet nodeset_
the nodes which can be currently eliminated
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

Member Data Documentation

◆ domain_sizes_

const NodeProperty< Size >* gum::EliminationSequenceStrategy::domain_sizes_ {nullptr}
protectedinherited

the domain sizes of the variables/nodes

Definition at line 158 of file eliminationSequenceStrategy.h.

◆ graph_

UndiGraph* gum::EliminationSequenceStrategy::graph_ {nullptr}
protectedinherited

the graph to be triangulated

Definition at line 155 of file eliminationSequenceStrategy.h.

◆ log_domain_sizes_

NodeProperty< double > gum::EliminationSequenceStrategy::log_domain_sizes_
protectedinherited

the log of the domain sizes of the variables/nodes

Definition at line 161 of file eliminationSequenceStrategy.h.

◆ nodeset_

NodeSet gum::PartialOrderedEliminationSequenceStrategy::nodeset_
protected

the nodes which can be currently eliminated

Definition at line 133 of file partialOrderedEliminationSequenceStrategy.h.

◆ partial_order_needed_

bool gum::PartialOrderedEliminationSequenceStrategy::partial_order_needed_ {true}
protected

indicate whether a new partial ordering is necessary for the elimination

Definition at line 136 of file partialOrderedEliminationSequenceStrategy.h.

◆ subset_iter_

List< NodeSet >::const_iterator gum::PartialOrderedEliminationSequenceStrategy::subset_iter_
protected

the iterator indicating which is the current subset on which we work

Definition at line 130 of file partialOrderedEliminationSequenceStrategy.h.

◆ subsets_

const List< NodeSet >* gum::PartialOrderedEliminationSequenceStrategy::subsets_ {nullptr}
protected

the subsets constituting the partial ordering

Definition at line 127 of file partialOrderedEliminationSequenceStrategy.h.


The documentation for this class was generated from the following files: