aGrUM  0.16.0
graphElements.h
Go to the documentation of this file.
1 
84 #ifndef GUM_GRAPH_ELEMENTS_H
85 #define GUM_GRAPH_ELEMENTS_H
86 
87 #include <iostream>
88 
89 #include <agrum/agrum.h>
90 
91 #include <agrum/core/set.h>
92 
93 namespace gum {
94 
98  typedef Size NodeId;
99 
100  /* ===========================================================================
101  */
102  /* ===========================================================================
103  */
104  /* === GENERIC UNDIRECTED EDGES ===
105  */
106  /* ===========================================================================
107  */
108  /* ===========================================================================
109  */
142  /* ===========================================================================
143  */
144 
145  class Edge {
146  public:
147  // ############################################################################
149  // ############################################################################
151 
153 
155  Edge(NodeId aN1, NodeId aN2);
156 
158  Edge(const Edge& src);
159 
161  ~Edge();
162 
164 
165  // ############################################################################
167  // ############################################################################
169 
171  NodeId other(NodeId id) const;
172 
174  NodeId first() const;
175 
177  NodeId second() const;
178 
180 
181  // ############################################################################
183  // ############################################################################
185 
187  Edge& operator=(const Edge& src);
188 
190 
192  bool operator==(const Edge& src) const;
193 
195 
197  bool operator!=(const Edge& src) const;
198 
200 
201  private:
203  NodeId n1, n2;
204  };
205 
206  /* ===========================================================================
207  */
208  /* ===========================================================================
209  */
210  /* === GENERIC DIRECTED EDGES ===
211  */
212  /* ===========================================================================
213  */
214  /* ===========================================================================
215  */
248  /* ===========================================================================
249  */
250 
251  class Arc {
252  public:
253  // ############################################################################
255  // ############################################################################
257 
259 
260  Arc(NodeId tail, NodeId head);
261 
263  Arc(const Arc& src);
264 
266  ~Arc();
267 
269 
270  // ############################################################################
272  // ############################################################################
274 
276  NodeId tail() const;
277 
279  NodeId head() const;
280 
282  NodeId other(NodeId id) const;
283 
285  NodeId first() const;
286 
288  NodeId second() const;
289 
291 
292  // ############################################################################
294  // ############################################################################
296 
298  Arc& operator=(const Arc& src);
299 
301 
303  bool operator==(const Arc& src) const;
304 
306 
309  bool operator!=(const Arc& src) const;
310 
312 
313  private:
315  NodeId n1, n2;
316 
318  void __setTail(NodeId id);
319 
321  void __setHead(NodeId id);
322 
324  void operator-();
325  };
326 
328  // we need to provide hash functions for some Edge and Arc
329 
330 #ifndef DOXYGEN_SHOULD_SKIP_THIS
331 
332  template <>
333  class HashFunc< Edge > : public HashFuncBase< Edge > {
334  public:
340  static Size castToSize(const Edge& key);
341 
347  virtual Size operator()(const Edge& key) const override final;
348  };
349 
350 
351  template <>
352  class HashFunc< Arc > : public HashFuncBase< Arc > {
353  public:
359  static Size castToSize(const Arc& key);
360 
366  virtual Size operator()(const Arc& key) const override final;
367  };
368 
369 #endif // DOXYGEN_SHOULD_SKIP_THIS
370 
378 
388  template < class VAL >
390  template < class VAL >
392  template < class VAL >
394 
396 
398  std::ostream& operator<<(std::ostream& stream, const Edge& edge);
399 
401  std::ostream& operator<<(std::ostream& stream, const Arc& arc);
402 
403 } /* namespace gum */
404 
405 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
406 extern template class gum::HashFunc< gum::NodeSet >;
407 #endif
408 
409 #ifndef GUM_NO_INLINE
411 #endif /* GUM_NO_INLINE */
412 
413 #endif // GUM_GRAPHELEMENTS_H
EdgeSet::const_iterator EdgeSetIterator
Some typdefs and define for shortcuts ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeId second() const
returns the node ID of the other extremal node ID
NodeSet::const_iterator NodeSetIterator
Some typdefs and define for shortcuts ...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Edge & operator=(const Edge &src)
copy operator
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeId n2
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
Edge(NodeId aN1, NodeId aN2)
constructs a new edge (aN1,aN2)
~Edge()
destructor
Class template representing hashing function of LpCol.
Definition: hashFunc.h:471
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
The class for generic Hash Tables.
Definition: hashTable.h:679
NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
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:605
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
ListConstIterator< Val >::difference_type operator-(const ListConstIterator< Val > &iter1, const ListConstIterator< Val > &iter2)
For STL compliance, a distance operator.
Definition: list_tpl.h:349
bool operator!=(const Edge &src) const
checks whether two undirected edges are different
ArcSet::const_iterator ArcSetIterator
Some typdefs and define for shortcuts ...
Unsafe iterators for the Set class.
Definition: set.h:1025
The base class for all undirected edges.
All hash functions should inherit from this class.
Definition: hashFunc.h:149
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
NodeId n1
the extremal nodes of the edge (their order is unimportant)
bool operator==(const Edge &src) const
checks whether two undirected edges are equal
Size NodeId
Type for node ids.
Definition: graphElements.h:98
NodeId other(NodeId id) const
returns an extremal node of an edge given the ID of the other one