aGrUM  0.13.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 unsigned int 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 HashFuncSmallKeyPair< NodeId, NodeId > {
333  public:
337  Size operator()(const Edge& key) const;
338 
339  private:
340  mutable std::pair< NodeId, NodeId > pair;
341  };
342 
343  template <>
344  class HashFunc< Arc > : public HashFuncSmallKeyPair< NodeId, NodeId > {
345  public:
349  Size operator()(const Arc& key) const;
350 
351  private:
352  mutable std::pair< NodeId, NodeId > pair;
353  };
354 
355 #endif // DOXYGEN_SHOULD_SKIP_THIS
356 
364 
374  template < class VAL >
376  template < class VAL >
378  template < class VAL >
380 
382 
384  std::ostream& operator<<(std::ostream& stream, const Edge& edge);
385 
387  std::ostream& operator<<(std::ostream& stream, const Arc& arc);
388 
389 } /* namespace gum */
390 
391 extern template class gum::HashFunc< gum::NodeSet >;
392 
393 #ifndef GUM_NO_INLINE
395 #endif /* GUM_NO_INLINE */
396 
397 #endif // GUM_GRAPHELEMENTS_H
EdgeSet::const_iterator EdgeSetIterator
Some typdefs and define for shortcuts ...
Inlined implementation of directed and undirected edges.
NodeSet::const_iterator NodeSetIterator
Some typdefs and define for shortcuts ...
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
Sets of elements (i.e.
NodeId second() const
returns the node ID of the other extremal node ID
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 ...
NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
Edge(NodeId aN1, NodeId aN2)
constructs a new edge (aN1,aN2)
~Edge()
destructor
Class template representing hashing function of LpCol.
Definition: hashFunc.h:612
bool operator==(const Edge &src) const
checks whether two undirected edges are equal
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 other(NodeId id) const
returns an extremal node of an edge given the ID of the other one
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:573
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
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.
NodeId n1
the extremal nodes of the edge (their order is unimportant)
bool operator!=(const Edge &src) const
checks whether two undirected edges are different
Generic hash functions for pairs of, at most, two long integer keys.
Definition: hashFunc.h:418