aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
arcGraphPart_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 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 {
41  return arcs__.contains(arc);
42  }
43 
46  }
47 
49  if (!parents__.exists(id)) { parents__.insert(id, new NodeSet); }
50  }
51 
53  if (!children__.exists(id)) { children__.insert(id, new NodeSet); }
54  }
55 
58  return *(parents__[id]);
59  }
60 
63  NodeSet res{id};
64  return res + parents(id);
65  }
66 
67  /// returns the set of children of a set of nodes
69  NodeSet res;
70  for (const auto node: ids)
71  res += children(node);
72  return res;
73  }
74 
75  /// returns the set of parents of a set of nodes
77  NodeSet res;
78  for (const auto node: ids)
79  res += parents(node);
80  return res;
81  }
82 
83  /// returns the set of family nodes of a set of nodes
85  NodeSet res;
86  for (const auto node: ids)
87  res += family(node);
88  return res;
89  }
90 
93  return *(children__[id]);
94  }
95 
97  Arc arc(tail, head);
98 
99  arcs__.insert(arc);
104 
106  }
107 
109  // ASSUMING tail and head exists in parents__ anf children__
110  // (if not, it is an error)
111  if (existsArc(arc)) {
112  NodeId tail = arc.tail(), head = arc.head();
115  arcs__.erase(arc);
117  }
118  }
119 
121  for (const auto& arc: set)
122  eraseArc(arc);
123  }
124 
126  if (parents__.exists(id)) {
127  NodeSet& parents = *(parents__[id]);
128 
129  for (auto iter = parents.beginSafe(); // safe iterator needed here
130  iter != parents.endSafe();
131  ++iter) {
132  // warning: use this erase so that you actually use the virtualized
133  // arc removal function
134  eraseArc(Arc(*iter, id));
135  }
136  }
137  }
138 
140  if (children__.exists(id)) {
141  NodeSet& children = *(children__[id]);
142 
143  for (auto iter = children.beginSafe(); // safe iterator needed here
144  iter != children.endSafe();
145  ++iter) {
146  // warning: use this erase so that you actually use the vritualized
147  // arc removal function
148  eraseArc(Arc(id, *iter));
149  }
150  }
151  }
152 
154  for (const auto& arc: set)
156  }
157 
159  if (parents__.exists(id)) {
160  NodeSet& parents = *(parents__[id]);
161 
162  for (auto iter = parents.beginSafe(); // safe iterator needed here
163  iter != parents.endSafe();
164  ++iter) {
166  }
167  }
168  }
169 
171  if (children__.exists(id)) {
172  NodeSet& children = *(children__[id]);
173 
174  for (auto iter = children.beginSafe(); // safe iterator needed here
175  iter != children.endSafe();
176  ++iter) {
178  }
179  }
180  }
181 
182  INLINE bool ArcGraphPart::operator==(const ArcGraphPart& p) const {
183  return arcs__ == p.arcs__;
184  }
185 
186  INLINE bool ArcGraphPart::operator!=(const ArcGraphPart& p) const {
187  return arcs__ != p.arcs__;
188  }
189 
190 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669