aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
simplicialSet_inl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief inline implementations of simplicial set
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #include <limits>
28 #include <sstream>
29 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 
32 // to ease IDE parser
33 # include <agrum/tools/core/math/math_utils.h>
34 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/defaultPartialOrderedEliminationSequenceStrategy.h>
35 
36 namespace gum {
37 
38  /* ===========================================================================
39  */
40  /* ===========================================================================
41  */
42  /* === CLASS FOR RETRIEVING SIMPLICIAL, ALMOST AND QUASI SIMPLICIAL NODES ===
43  */
44  /* ===========================================================================
45  */
46  /* ===========================================================================
47  */
48 
49  /// indicates whether a given node is a simplicial node
50  INLINE
51  bool SimplicialSet::isSimplicial(const NodeId id) {
52  // update the list to which the node belongs if needed
53  if (changed_status__.contains(id)) updateList__(id);
54 
55  // check if the node belongs to the simplicial list
56  return simplicial_nodes__.contains(id);
57  }
58 
59 
60  /// gets a simplicial node
61  INLINE
62  NodeId SimplicialSet::bestSimplicialNode() {
63  if (!hasSimplicialNode()) {
64  GUM_ERROR(NotFound, "No simplicial node could be found");
65  }
66 
67  return simplicial_nodes__.top();
68  }
69 
70 
71  /// gets an almost simplicial node
72  INLINE
73  NodeId SimplicialSet::bestAlmostSimplicialNode() {
74  if (!hasAlmostSimplicialNode()) {
75  GUM_ERROR(NotFound, "no almost simplicial node could be found");
76  }
77 
78  return almost_simplicial_nodes__.top();
79  }
80 
81 
82  /// gets a quasi simplicial node
83  INLINE
84  NodeId SimplicialSet::bestQuasiSimplicialNode() {
85  if (!hasQuasiSimplicialNode()) {
86  GUM_ERROR(NotFound, "no quasi simplicial node could be found");
87  }
88 
89  return quasi_simplicial_nodes__.top();
90  }
91 
92 
93  /// put all the nodes in their appropriate list
94  INLINE
95  void SimplicialSet::updateAllNodes__() {
96  // check if a node can enter the simplicial list
97  for (auto iter = changed_status__.beginSafe(); // safe iterator needed here
98  iter != changed_status__.endSafe();
99  ++iter) {
100  updateList__(*iter);
101  }
102  }
103 
104 
105  /// returns all the simplicial nodes
106  INLINE
107  const PriorityQueue< NodeId, double >& SimplicialSet::allSimplicialNodes() {
108  updateAllNodes__();
109  return simplicial_nodes__;
110  }
111 
112 
113  /// returns all the almost simplicial nodes
114  INLINE
115  const PriorityQueue< NodeId, double >&
116  SimplicialSet::allAlmostSimplicialNodes() {
117  updateAllNodes__();
118  return almost_simplicial_nodes__;
119  }
120 
121 
122  /// returns all the quasi simplicial nodes
123  INLINE
124  const PriorityQueue< NodeId, double >& SimplicialSet::allQuasiSimplicialNodes() {
125  updateAllNodes__();
126  return quasi_simplicial_nodes__;
127  }
128 
129 
130  /// sets/unset the fill-ins storage in the standard triangulation procedure
131  INLINE
132  void SimplicialSet::setFillIns(bool b) { we_want_fill_ins__ = b; }
133 
134 
135  /// returns the set of fill-ins
136  INLINE
137  const EdgeSet& SimplicialSet::fillIns() const { return fill_ins_list__; }
138 
139 
140 } /* namespace gum */
141 
142 #endif /* DOXYGEN_SHOULD_SKIP_THIS */