25 #ifndef _GRAPH_PRINTER_HPP
26 #define _GRAPH_PRINTER_HPP
39 template<
typename GraphTy,
typename NodeTy>
45 typedef typename std::set<NodeType>::iterator
iterator;
139 return (
unsigned long)node;
160 template <
class Pr
intableGraphTy>
163 static void print(
const char *filename,
const PrintableGraphTy &G) {
164 FILE* file = fopen(filename,
"w");
175 OS<<
"digraph g1 {\n";
176 OS<<
"node [shape = box];\n";
178 G.getGraphName(OS) <<
"\";\n";
182 for(
typename PrintableGraphTy::const_iterator
i = G.begin(),
e = G.end();
i !=
e; ++
i) {
183 typename PrintableGraphTy::NodeType node(*
i);
184 OS<<
"\"node_" << G.getNodeID(node) <<
"\"" <<
"[label=\"";
185 G.getNodeLabel(OS,node) <<
"\", ";
186 G.getNodeAttributes(OS,node) <<
"];\n";
191 for(
typename PrintableGraphTy::const_cluster_iterator
i = G.cluster_begin(),
192 e = G.cluster_end();
i !=
e; ++
i) {
193 unsigned long cid =
i->first;
194 const std::set<typename PrintableGraphTy::NodeType> &
set =
i->second;
195 OS<<
"subgraph cluster_" << cid <<
" {\n";
196 typename PrintableGraphTy::const_cluster_name_iterator name_it = G.cluster_name_find(cid);
197 if (name_it != G.cluster_name_end()) {
198 OS<<
"label = \""<< name_it->second <<
"\";\n";
200 for (
typename std::set<typename PrintableGraphTy::NodeType>::const_iterator ii = set.begin(),
201 ee = set.end(); ii != ee; ++ii) {
202 typename PrintableGraphTy::NodeType node = (*ii);
203 OS<<
"\"node_" << G.getNodeID(node) <<
"\";\n";
209 for(
typename PrintableGraphTy::const_edge_iterator
i = G.edge_begin(),
210 e = G.edge_end();
i !=
e; ++
i) {
211 typename PrintableGraphTy::NodeType a(
i->first);
212 typename PrintableGraphTy::NodeType b(
i->second);
213 OS<<
"\"node_" << G.getNodeID(a) <<
"\" -> " <<
"\"node_" << G.getNodeID(b) <<
"\""
215 G.getEdgeLabel(OS,*
i) <<
"\", ";
216 G.getEdgeAttributes(OS,*
i) <<
"];\n";
227 #endif // _GRAPH_PRINTER_HPP
const_cluster_iterator cluster_begin() const
std::set< NodeType > NodeListType
std::map< unsigned long, std::string > cluster_name
std::set< NodeType >::const_iterator const_iterator
edge_iterator edge_begin()
static void print(const char *filename, const PrintableGraphTy &G)
const_iterator begin() const
const_cluster_name_iterator cluster_name_begin() const
virtual OStream & getEdgeAttributes(OStream &OS, const EdgeType &e) const
std::map< unsigned long, std::set< NodeType > >::iterator cluster_iterator
std::set< NodeType >::iterator iterator
cluster_iterator cluster_begin()
virtual unsigned long getNodeID(const NodeType &node) const
std::set< NodeType > nodes
const_cluster_name_iterator cluster_name_find(unsigned long k) const
std::map< unsigned long, std::string >::iterator cluster_name_iterator
std::map< unsigned long, NodeListType > clusters
static void printNodes(OStream &OS, const PrintableGraphTy &G)
const_edge_iterator edge_begin() const
std::pair< NodeType, NodeType > EdgeType
cluster_name_iterator cluster_name_begin()
virtual OStream & getEdgeLabel(OStream &OS, const EdgeType &e) const
static void printHeader(OStream &OS, const PrintableGraphTy &G)
const_iterator end() const
Simple stream class for formatted output.
static void printFooter(OStream &OS, const PrintableGraphTy &G)
cluster_name_iterator cluster_name_end()
virtual OStream & getNodeAttributes(OStream &OS, const NodeType &node) const
virtual OStream & getNodeLabel(OStream &OS, const NodeType &node) const
cluster_name_iterator cluster_name_find(unsigned long k)
std::set< EdgeType >::iterator edge_iterator
virtual OStream & getGraphName(OStream &OS) const
const_edge_iterator edge_end() const
std::set< EdgeType > successors
cluster_iterator cluster_end()
const_cluster_iterator cluster_end() const
std::map< unsigned long, std::set< NodeType > >::const_iterator const_cluster_iterator
static void printEdges(OStream &OS, const PrintableGraphTy &G)
std::map< unsigned long, std::string >::const_iterator const_cluster_name_iterator
std::set< EdgeType >::const_iterator const_edge_iterator
static void printCluster(OStream &OS, const PrintableGraphTy &G)
const_cluster_name_iterator cluster_name_end() const
std::set< EdgeType > edges