aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
simplicialSet_inl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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()) { GUM_ERROR(NotFound, "No simplicial node could be found") }
64 
65  return _simplicial_nodes_.top();
66  }
67 
68 
69  /// gets an almost simplicial node
70  INLINE
71  NodeId SimplicialSet::bestAlmostSimplicialNode() {
72  if (!hasAlmostSimplicialNode()) {
73  GUM_ERROR(NotFound, "no almost simplicial node could be found")
74  }
75 
76  return _almost_simplicial_nodes_.top();
77  }
78 
79 
80  /// gets a quasi simplicial node
81  INLINE
82  NodeId SimplicialSet::bestQuasiSimplicialNode() {
83  if (!hasQuasiSimplicialNode()) {
84  GUM_ERROR(NotFound, "no quasi simplicial node could be found")
85  }
86 
87  return _quasi_simplicial_nodes_.top();
88  }
89 
90 
91  /// put all the nodes in their appropriate list
92  INLINE
93  void SimplicialSet::_updateAllNodes_() {
94  // check if a node can enter the simplicial list
95  for (auto iter = _changed_status_.beginSafe(); // safe iterator needed here
96  iter != _changed_status_.endSafe();
97  ++iter) {
98  _updateList_(*iter);
99  }
100  }
101 
102 
103  /// returns all the simplicial nodes
104  INLINE
105  const PriorityQueue< NodeId, double >& SimplicialSet::allSimplicialNodes() {
106  _updateAllNodes_();
107  return _simplicial_nodes_;
108  }
109 
110 
111  /// returns all the almost simplicial nodes
112  INLINE
113  const PriorityQueue< NodeId, double >& SimplicialSet::allAlmostSimplicialNodes() {
114  _updateAllNodes_();
115  return _almost_simplicial_nodes_;
116  }
117 
118 
119  /// returns all the quasi simplicial nodes
120  INLINE
121  const PriorityQueue< NodeId, double >& SimplicialSet::allQuasiSimplicialNodes() {
122  _updateAllNodes_();
123  return _quasi_simplicial_nodes_;
124  }
125 
126 
127  /// sets/unset the fill-ins storage in the standard triangulation procedure
128  INLINE
129  void SimplicialSet::setFillIns(bool b) { _we_want_fill_ins_ = b; }
130 
131 
132  /// returns the set of fill-ins
133  INLINE
134  const EdgeSet& SimplicialSet::fillIns() const { return _fill_ins_list_; }
135 
136 
137 } /* namespace gum */
138 
139 #endif /* DOXYGEN_SHOULD_SKIP_THIS */