aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
partialOrderedEliminationSequenceStrategy.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
52
54
55#ifdef GUM_NO_INLINE
57#endif // GU%_NO_INLINE
58
59namespace gum {
60
66
70 const NodeProperty< Size >* dom_sizes,
71 const List< NodeSet >* subsets) {
72 setGraph(graph, dom_sizes);
73 setPartialOrder(subsets);
74
75 // for debugging purposes
77 }
78
87
99
105
109 const NodeProperty< Size >* domain_sizes) {
110 if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
112 return true;
113 }
114 return false;
115 }
116
119 const List< NodeSet >* subsets) const {
120 if ((graph_ == nullptr) || (subsets == nullptr)) return true;
121
122 // determine the set of nodes in the subsets that belong to the graph
123 NodeSet nodes_found(graph_->size() / 2);
124 for (const auto& nodes: *subsets) {
125 for (const auto node: nodes) {
126 if (graph_->existsNode(node)) { nodes_found.insert(node); }
127 }
128 }
129
130 // check that the size of nodes_found is equal to that of the graph
131 return nodes_found.size() != graph_->size();
132 }
133
136 // check that the partial order contains all the nodes of the graph
138
140 subsets_ = subsets;
141
142 // initialize properly the set of nodes that can be currently eliminated:
143 // find the first subset that contains some node(s) of the graph
144 nodeset_.clear();
145 for (subset_iter_ = subsets_->cbegin(); subset_iter_ != subsets_->cend(); ++subset_iter_) {
146 for (const auto node: *subset_iter_) {
147 if (graph_->existsNode(node)) { nodeset_.insert(node); }
148 }
149 if (!nodeset_.empty()) return true;
150 }
151 }
152
153 return false;
154 }
155
163
164} /* namespace gum */
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
UndiGraph * graph_
the graph to be triangulated
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
UndiGraph * graph() const noexcept
returns the current graph
Generic doubly linked lists.
Definition list.h:379
bool isPartialOrderNeeded_(const List< NodeSet > *subsets) const
indicate whether a partial ordering is compatible with the current graph
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
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
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)
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
NodeSet nodeset_
the nodes which can be currently eliminated
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:636
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539
Base class for undirected graphs.
Definition undiGraph.h:128
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes e...
Base class for all elimination sequence algorithm that impose a given partial ordering on the nodes e...