1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/demo/dim_to_dot.cc Thu Sep 30 17:32:00 2004 +0000
1.3 @@ -0,0 +1,59 @@
1.4 +// -*- c++ -*-
1.5 +
1.6 +// Use a DIMACS max flow file as stdin.
1.7 +// dim_to_dot < dimacs_max_flow_file > dot_output_file
1.8 +// This program makes a dot file from a dimacs max flow file.
1.9 +// This program can be an aid in making up to date visualized documantation
1.10 +// of demo programs.
1.11 +
1.12 +#include <iostream>
1.13 +#include <fstream>
1.14 +
1.15 +#include <lemon/smart_graph.h>
1.16 +#include <lemon/dimacs.h>
1.17 +
1.18 +using namespace lemon;
1.19 +
1.20 +using std::cout;
1.21 +using std::endl;
1.22 +
1.23 +int main()
1.24 +{
1.25 + typedef SmartGraph Graph;
1.26 +
1.27 + typedef Graph::Edge Edge;
1.28 + typedef Graph::Node Node;
1.29 + typedef Graph::EdgeIt EdgeIt;
1.30 + typedef Graph::NodeIt NodeIt;
1.31 + typedef Graph::EdgeMap<int> LengthMap;
1.32 +
1.33 + Graph g;
1.34 + Node s, t;
1.35 + LengthMap length(g);
1.36 +
1.37 + readDimacs(std::cin, g, length, s, t);
1.38 +
1.39 + cout << "digraph lemon_dot_example {" << endl;
1.40 + cout << " node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
1.41 + for(NodeIt n(g); n!=INVALID; ++n) {
1.42 + if (n==s) {
1.43 + cout << " n" << g.id(n)
1.44 + << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
1.45 + } else {
1.46 + if (n==t) {
1.47 + cout << " n" << g.id(n)
1.48 + << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl;
1.49 + } else {
1.50 + cout << " n" << g.id(n)
1.51 + << " [ label=\"" << g.id(n) << "\" ]; " << endl;
1.52 + }
1.53 + }
1.54 + }
1.55 + cout << " edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
1.56 + for(EdgeIt e(g); e!=INVALID; ++e) {
1.57 + cout << " n" << g.id(g.tail(e)) << " -> " << " n" << g.id(g.head(e))
1.58 + << " [ label=\"" << g.id(e)
1.59 + << ", length:" << length[e] << "\" ]; " << endl;
1.60 + }
1.61 + cout << "}" << endl;
1.62 +}