aGrUM  0.14.2
graphElements.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 
21 
83 #ifndef GUM_GRAPH_ELEMENTS_H
84 #define GUM_GRAPH_ELEMENTS_H
85 
86 #include <iostream>
87 
88 #include <agrum/agrum.h>
89 
90 #include <agrum/core/set.h>
91 
92 namespace gum {
93 
97  typedef Size NodeId;
98 
99  /* ===========================================================================
100  */
101  /* ===========================================================================
102  */
103  /* === GENERIC UNDIRECTED EDGES ===
104  */
105  /* ===========================================================================
106  */
107  /* ===========================================================================
108  */
141  /* ===========================================================================
142  */
143 
144  class Edge {
145  public:
146  // ############################################################################
148  // ############################################################################
150 
152 
154  Edge(NodeId aN1, NodeId aN2);
155 
157  Edge(const Edge& src);
158 
160  ~Edge();
161 
163 
164  // ############################################################################
166  // ############################################################################
168 
170  NodeId other(NodeId id) const;
171 
173  NodeId first() const;
174 
176  NodeId second() const;
177 
179 
180  // ############################################################################
182  // ############################################################################
184 
186  Edge& operator=(const Edge& src);
187 
189 
191  bool operator==(const Edge& src) const;
192 
194 
196  bool operator!=(const Edge& src) const;
197 
199 
200  private:
202  NodeId n1, n2;
203  };
204 
205  /* ===========================================================================
206  */
207  /* ===========================================================================
208  */
209  /* === GENERIC DIRECTED EDGES ===
210  */
211  /* ===========================================================================
212  */
213  /* ===========================================================================
214  */
247  /* ===========================================================================
248  */
249 
250  class Arc {
251  public:
252  // ############################################################################
254  // ############################################################################
256 
258 
259  Arc(NodeId tail, NodeId head);
260 
262  Arc(const Arc& src);
263 
265  ~Arc();
266 
268 
269  // ############################################################################
271  // ############################################################################
273 
275  NodeId tail() const;
276 
278  NodeId head() const;
279 
281  NodeId other(NodeId id) const;
282 
284  NodeId first() const;
285 
287  NodeId second() const;
288 
290 
291  // ############################################################################
293  // ############################################################################
295 
297  Arc& operator=(const Arc& src);
298 
300 
302  bool operator==(const Arc& src) const;
303 
305 
308  bool operator!=(const Arc& src) const;
309 
311 
312  private:
314  NodeId n1, n2;
315 
317  void __setTail(NodeId id);
318 
320  void __setHead(NodeId id);
321 
323  void operator-();
324  };
325 
327  // we need to provide hash functions for some Edge and Arc
328 
329 #ifndef DOXYGEN_SHOULD_SKIP_THIS
330 
331  template <>
332  class HashFunc< Edge > : public HashFuncBase< Edge > {
333  public:
339  static Size castToSize(const Edge& key);
340 
346  virtual Size operator()(const Edge& key) const override final;
347  };
348 
349 
350  template <>
351  class HashFunc< Arc > : public HashFuncBase< Arc > {
352  public:
358  static Size castToSize(const Arc& key);
359 
365  virtual Size operator()(const Arc& key) const override final;
366  };
367 
368 #endif // DOXYGEN_SHOULD_SKIP_THIS
369 
377 
387  template < class VAL >
389  template < class VAL >
391  template < class VAL >
393 
395 
397  std::ostream& operator<<(std::ostream& stream, const Edge& edge);
398 
400  std::ostream& operator<<(std::ostream& stream, const Arc& arc);
401 
402 } /* namespace gum */
403 
404 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
405 extern template class gum::HashFunc< gum::NodeSet >;
406 #endif
407 
408 #ifndef GUM_NO_INLINE
410 #endif /* GUM_NO_INLINE */
411 
412 #endif // GUM_GRAPHELEMENTS_H
EdgeSet::const_iterator EdgeSetIterator
Some typdefs and define for shortcuts ...
Inlined implementation of directed and undirected edges.
NodeId second() const
returns the node ID of the other extremal node ID
NodeSet::const_iterator NodeSetIterator
Some typdefs and define for shortcuts ...
Sets of elements (i.e.
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:469
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
The class for generic Hash Tables.
Definition: hashTable.h:676
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:583
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:346
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:1022
The base class for all undirected edges.
All hash functions should inherit from this class.
Definition: hashFunc.h:147
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
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:97
NodeId other(NodeId id) const
returns an extremal node of an edge given the ID of the other one