aGrUM  0.14.2
diGraph.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_DIGRAPH_H
26 #define GUM_DIGRAPH_H
27 
28 #include <iostream>
29 #include <sstream>
30 #include <utility>
31 
32 #include <agrum/agrum.h>
33 #include <agrum/core/sequence.h>
34 
37 
38 namespace gum {
39 
40  /* ===========================================================================
41  */
42  /* === BASE CLASS FOR MANIPULATING ALL DIRECTED GRAPHS ===
43  */
44  /* ===========================================================================
45  */
106  /* ===========================================================================
107  */
108  class DiGraph
109  : public virtual NodeGraphPart
110  , public ArcGraphPart {
111  public:
112  // ############################################################################
114  // ############################################################################
116 
118 
122  explicit DiGraph(Size nodes_size = HashTableConst::default_size,
123  bool nodes_resize_policy = true,
125  bool arcs_resize_policy = true);
126 
128 
129  DiGraph(const DiGraph& g);
130 
132  virtual ~DiGraph();
133 
135 
136  // ############################################################################
138  // ############################################################################
140 
142 
143  DiGraph& operator=(const DiGraph& g);
144 
146 
147  // not virtual : it is a feature !!! :)
148  bool operator==(const DiGraph& g) const;
149 
151 
152  // not virtual : it is a feature !!! :)
153  bool operator!=(const DiGraph& g) const;
154 
156 
157  // ############################################################################
159  // ############################################################################
161 
163 
168  virtual void addArc(const NodeId tail, const NodeId head);
169 
171 
174  virtual void eraseNode(const NodeId id);
175 
177  virtual void clear();
178 
180  virtual const std::string toString() const;
181 
183 
185  virtual const std::string toDot() const;
186 
193  const Sequence< NodeId >& topologicalOrder(bool clear = true) const;
195 
196  private:
199 
202  void __topologicalOrder() const;
203  };
204 
206  std::ostream& operator<<(std::ostream&, const DiGraph&);
207 
208 } /* namespace gum */
209 
210 #ifndef GUM_NO_INLINE
211 # include <agrum/graphs/diGraph_inl.h>
212 #endif // GUM_NOINLINE
213 
214 #endif /* GUM_DIGRAPH_H */
DiGraph & operator=(const DiGraph &g)
copy operator
Definition: diGraph_inl.h:45
Base node set class for graphs.
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: diGraph_inl.h:32
bool operator!=(const DiGraph &g) const
tests whether two DiGraphs are different
Definition: diGraph_inl.h:80
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition: diGraph.cpp:34
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
Classes for directed edge sets.
Definition: arcGraphPart.h:76
virtual void clear()
removes all the nodes and arcs from the graph
Definition: diGraph_inl.h:40
virtual const std::string toString() const
to friendly display the content of the graph
Definition: diGraph.cpp:58
static constexpr Size default_size
The default number of slots in hashtables.
Definition: hashTable.h:77
virtual ~DiGraph()
destructor
Definition: diGraph.cpp:53
bool operator==(const DiGraph &g) const
tests whether two DiGraphs are identical (same nodes, same arcs)
Definition: diGraph_inl.h:76
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Sequence< NodeId > * __mutableTopologicalOrder
The topology sequence of this Directed Graphical Model.
Definition: diGraph.h:198
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
Base class for all oriented graphs.
Definition: diGraph.h:108
virtual const std::string toDot() const
to friendly display the content of the graph in the DOT syntax
Definition: diGraph.cpp:65
Class for node sets in graph.
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: diGraph.cpp:88
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Inline implementation of Base classes for oriented graphs.
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:66
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void __topologicalOrder() const
Returns a topological order of this DAGModel.
Definition: diGraph.cpp:105