aGrUM  0.14.2
arcGraphPart.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 #ifndef GUM_ARC_GRAPH_PART_H
21 #define GUM_ARC_GRAPH_PART_H
22 
23 #include <algorithm>
24 #include <utility>
25 
26 #include <agrum/agrum.h>
27 
30 
31 namespace gum {
32 
76  class ArcGraphPart {
77  public:
79 
80  Signaler2< NodeId, NodeId > onArcAdded; // onArcAdded(tail,head)
81  Signaler2< NodeId, NodeId > onArcDeleted; // onArcDeleted(tail,head)
82 
83  // ############################################################################
85  // ############################################################################
87 
89 
91  explicit ArcGraphPart(Size arcs_size = HashTableConst::default_size,
92  bool arcs_resize_policy = true);
93 
95 
96  ArcGraphPart(const ArcGraphPart& s);
97 
99  virtual ~ArcGraphPart();
100 
102 
103  // ############################################################################
105  // ############################################################################
107 
109 
111 
113 
114  bool operator==(const ArcGraphPart& p) const;
115 
117 
118  bool operator!=(const ArcGraphPart& p) const;
119 
121 
122  // ############################################################################
124  // ############################################################################
126 
128 
132  virtual void addArc(const NodeId tail, const NodeId head);
133 
135 
139  virtual void eraseArc(const Arc& arc);
140 
142 
144  bool existsArc(const Arc& arc) const;
145 
147 
151  bool existsArc(const NodeId tail, const NodeId head) const;
152 
154  bool emptyArcs() const;
155 
157  void clearArcs();
158 
160  Size sizeArcs() const;
161 
163  const ArcSet& arcs() const;
164 
166 
169  const NodeSet& parents(const NodeId id) const;
170 
172 
175  const NodeSet& children(const NodeId id) const;
176 
178 
185  void eraseParents(const NodeId id);
186 
188 
189  void unvirtualizedEraseParents(const NodeId id);
190 
192 
199  void eraseChildren(const NodeId id);
200 
202 
203  void unvirtualizedEraseChildren(const NodeId id);
204 
206  const std::string toString() const;
207 
215  template < typename VAL >
216  ArcProperty< VAL > arcsProperty(VAL (*f)(const Arc&), Size size = 0) const;
217 
225  template < typename VAL >
226  ArcProperty< VAL > arcsProperty(const VAL& a, Size size = 0) const;
227 
231  template < typename VAL >
232  List< VAL > listMapArcs(VAL (*f)(const Arc&)) const;
233 
235 
239  const std::vector< NodeId > directedPath(const NodeId node1,
240  const NodeId node2) const;
241 
243 
247  const std::vector< NodeId > directedUnorientedPath(const NodeId node1,
248  const NodeId node2) const;
249 
251 
252  protected:
254 
256  void _eraseSetOfArcs(const ArcSet& set);
257 
259 
262  void _unvirtualizedEraseSetOfArcs(const ArcSet& set);
263 
264  private:
267 
270 
273 
277  void __checkParents(const NodeId id) const;
278 
282  void __checkChildren(const NodeId id) const;
283  };
284 
286 
288  std::ostream& operator<<(std::ostream& s, const ArcGraphPart& a);
289 
290 } /* namespace gum */
291 
292 #ifndef GUM_NO_INLINE
294 #endif // GUM_NOINLINE
295 
297 
298 #endif // GUM_ARC_GRAPH_PART_H
const std::vector< NodeId > directedUnorientedPath(const NodeId node1, const NodeId node2) const
returns an unoriented (directed) path from node1 to node2 in the arc set
void __checkParents(const NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
const std::string toString() const
to friendly display the content of the ArcGraphPart
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the ArcGraphPart
ArcGraphPart & operator=(const ArcGraphPart &s)
copy operator
void clearArcs()
removes all the arcs from the ArcGraphPart
Classes for directed edge sets.
Definition: arcGraphPart.h:76
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
ArcProperty< VAL > arcsProperty(VAL(*f)(const Arc &), Size size=0) const
a method to create a hashMap of VAL from a set of arcs (using for every arc, say x, the VAL f(x))
static constexpr Size default_size
The default number of slots in hashtables.
Definition: hashTable.h:77
Generic doubly linked lists.
Definition: list.h:369
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
void __checkChildren(const NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
Classes of signaler.
Inline implementation of classes for directed edge sets.
void _eraseSetOfArcs(const ArcSet &set)
a (virtualized) function to remove a given set of arcs
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:583
bool emptyArcs() const
indicates wether the ArcGraphPart contains any arc
bool operator!=(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain different arcs
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
void _unvirtualizedEraseSetOfArcs(const ArcSet &set)
similar to _eraseSetOfArcs except that it is unvirtualized
const std::vector< NodeId > directedPath(const NodeId node1, const NodeId node2) const
returns a directed path from node1 to node2 belonging to the set of arcs
void eraseChildren(const NodeId id)
removes all the children of a given node
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
ArcSetIterator ArcIterator
Definition: arcGraphPart.h:78
Unsafe iterators for the Set class.
Definition: set.h:1022
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:80
virtual ~ArcGraphPart()
destructor
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
Implementation of the gumArcGraphPart.
void unvirtualizedEraseChildren(const NodeId id)
same function as eraseChildren but without any virtual call to an erase
void unvirtualizedEraseParents(const NodeId id)
same function as eraseParents but without any virtual call to an erase
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:81
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
List< VAL > listMapArcs(VAL(*f)(const Arc &)) const
a method to create a list of VAL from a set of arcs (using for every arc, say x, the VAL f(x)) ...
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void eraseParents(const NodeId id)
erase all the parents of a given node
some utils for topology : NodeId, Edge, Arc and consorts ...