aGrUM  0.14.2
undiGraph.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  ***************************************************************************/
25 #ifndef GUM_UNDIGRAPH_H
26 #define GUM_UNDIGRAPH_H
27 
28 #include <iostream>
29 #include <utility>
30 
31 #include <agrum/agrum.h>
32 
35 
36 namespace gum {
37 
38  /* ===========================================================================
39  */
40  /* === BASE CLASS FOR MANIPULATING ALL UNDIRECTED GRAPHS ===
41  */
42  /* ===========================================================================
43  */
103  /* ===========================================================================
104  */
105 
106  class UndiGraph
107  : public virtual NodeGraphPart
108  , public EdgeGraphPart {
109  public:
110  // ############################################################################
112  // ############################################################################
114 
116 
120  explicit UndiGraph(Size nodes_size = HashTableConst::default_size,
121  bool nodes_resize_policy = true,
122  Size edges_size = HashTableConst::default_size,
123  bool edges_resize_policy = true);
124 
126 
127  UndiGraph(const UndiGraph& g);
128 
130  virtual ~UndiGraph();
131 
133 
134  // ############################################################################
136  // ############################################################################
138 
140 
141  UndiGraph& operator=(const UndiGraph& g);
142 
144 
145  // not virtual : it is a feature !!! :)
146  bool operator==(const UndiGraph& g) const;
147 
149 
150  // not virtual : it is a feature !!! :)
151  bool operator!=(const UndiGraph& g) const;
152 
154 
155  // ############################################################################
157  // ############################################################################
159 
161 
168  virtual void addEdge(const NodeId first, const NodeId second);
169 
171 
174  virtual void eraseNode(const NodeId id);
175 
177  virtual void clear();
178 
180  virtual const std::string toString() const;
181 
183  virtual const std::string toDot() const;
184 
186  bool hasUndirectedCycle() const;
187 
189  virtual UndiGraph partialUndiGraph(NodeSet nodesSet);
190 
192  };
193 
195  std::ostream& operator<<(std::ostream&, const UndiGraph&);
196 
197 } /* namespace gum */
198 
199 #ifndef GUM_NO_INLINE
201 #endif // GUM_NOINLINE
202 
203 #endif /* GUM_UNDIGRAPH_H */
Inline implementation of Base classes for undirected graphs.
Base node set class for graphs.
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:40
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:32
static constexpr Size default_size
The default number of slots in hashtables.
Definition: hashTable.h:77
Classes for undirected edge sets.
Definition: edgeGraphPart.h:72
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual void eraseNode(const NodeId id)
remove a node and its adjacent edges from the graph
Definition: undiGraph_inl.h:55
virtual ~UndiGraph()
destructor
Definition: undiGraph.cpp:50
bool operator!=(const UndiGraph &g) const
tests whether two UndiGraphs are different
Definition: undiGraph_inl.h:67
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 operator==(const UndiGraph &g) const
tests whether two UndiGraphs are identical (same nodes, same edges)
Definition: undiGraph_inl.h:63
Class for node sets in graph.
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition: undiGraph.cpp:37
Base class for undirected graphs.
Definition: undiGraph.h:106
bool hasUndirectedCycle() const
checks whether the graph contains cycles
Definition: undiGraph.cpp:52
UndiGraph & operator=(const UndiGraph &g)
copy operator
Definition: undiGraph_inl.h:45
virtual const std::string toString() const
to friendly display the content of the graph
Definition: undiGraph.cpp:99
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size NodeId
Type for node ids.
Definition: graphElements.h:97
virtual const std::string toDot() const
to friendly display graph in DOT format
Definition: undiGraph.cpp:106
virtual UndiGraph partialUndiGraph(NodeSet nodesSet)
returns the partial graph formed by the nodes given in parameter
Definition: undiGraph.cpp:136