aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
arcGraphPart_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 implementation of classes for directed edge sets
24  *
25  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
26  *
27  */
28 
29 // to ease parsing by IDE
30 #include <agrum/tools/graphs/parts/arcGraphPart.h>
31 
32 namespace gum {
33 
34  INLINE bool ArcGraphPart::emptyArcs() const { return _arcs_.empty(); }
35 
36  INLINE Size ArcGraphPart::sizeArcs() const { return _arcs_.size(); }
37 
38  INLINE const ArcSet& ArcGraphPart::arcs() const { return _arcs_; }
39 
40  INLINE bool ArcGraphPart::existsArc(const Arc& arc) const { return _arcs_.contains(arc); }
41 
44  }
45 
47  if (!_parents_.exists(id)) { _parents_.insert(id, new NodeSet); }
48  }
49 
51  if (!_children_.exists(id)) { _children_.insert(id, new NodeSet); }
52  }
53 
56  return *(_parents_[id]);
57  }
58 
61  NodeSet res{id};
62  return res + parents(id);
63  }
64 
65  /// returns the set of children of a set of nodes
67  NodeSet res;
68  for (const auto node: ids)
69  res += children(node);
70  return res;
71  }
72 
73  /// returns the set of parents of a set of nodes
75  NodeSet res;
76  for (const auto node: ids)
77  res += parents(node);
78  return res;
79  }
80 
81  /// returns the set of family nodes of a set of nodes
83  NodeSet res;
84  for (const auto node: ids)
85  res += family(node);
86  return res;
87  }
88 
91  return *(_children_[id]);
92  }
93 
95  Arc arc(tail, head);
96 
97  _arcs_.insert(arc);
102 
104  }
105 
107  // ASSUMING tail and head exists in _parents_ anf _children_
108  // (if not, it is an error)
109  if (existsArc(arc)) {
110  NodeId tail = arc.tail(), head = arc.head();
113  _arcs_.erase(arc);
115  }
116  }
117 
119  for (const auto& arc: set)
120  eraseArc(arc);
121  }
122 
124  if (_parents_.exists(id)) {
125  NodeSet& parents = *(_parents_[id]);
126 
127  for (auto iter = parents.beginSafe(); // safe iterator needed here
128  iter != parents.endSafe();
129  ++iter) {
130  // warning: use this erase so that you actually use the virtualized
131  // arc removal function
132  eraseArc(Arc(*iter, id));
133  }
134  }
135  }
136 
138  if (_children_.exists(id)) {
139  NodeSet& children = *(_children_[id]);
140 
141  for (auto iter = children.beginSafe(); // safe iterator needed here
142  iter != children.endSafe();
143  ++iter) {
144  // warning: use this erase so that you actually use the vritualized
145  // arc removal function
146  eraseArc(Arc(id, *iter));
147  }
148  }
149  }
150 
152  for (const auto& arc: set)
154  }
155 
157  if (_parents_.exists(id)) {
158  NodeSet& parents = *(_parents_[id]);
159 
160  for (auto iter = parents.beginSafe(); // safe iterator needed here
161  iter != parents.endSafe();
162  ++iter) {
164  }
165  }
166  }
167 
169  if (_children_.exists(id)) {
170  NodeSet& children = *(_children_[id]);
171 
172  for (auto iter = children.beginSafe(); // safe iterator needed here
173  iter != children.endSafe();
174  ++iter) {
176  }
177  }
178  }
179 
180  INLINE bool ArcGraphPart::operator==(const ArcGraphPart& p) const { return _arcs_ == p._arcs_; }
181 
182  INLINE bool ArcGraphPart::operator!=(const ArcGraphPart& p) const { return _arcs_ != p._arcs_; }
183 
184 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643