src/demo/dim_to_dot.cc
author alpar
Sun, 27 Mar 2005 15:59:04 +0000
changeset 1268 a1f9a4d4ea0c
parent 931 9227ecd7b0bc
permissions -rw-r--r--
Use the standard idMap
     1 // -*- c++ -*-
     2 
     3 // Use a DIMACS max flow file as stdin.
     4 // dim_to_dot < dimacs_max_flow_file > dot_output_file
     5 // This program makes a dot file from a dimacs max flow file. 
     6 // This program can be an aid in making up to date visualized documantation 
     7 // of demo programs.
     8 
     9 #include <iostream>
    10 #include <fstream>
    11 
    12 #include <lemon/smart_graph.h>
    13 #include <lemon/dimacs.h>
    14 
    15 using namespace lemon;
    16 
    17 using std::cout;
    18 using std::endl;
    19 
    20 int main()
    21 {    
    22   typedef SmartGraph Graph;
    23 
    24   typedef Graph::Edge Edge;
    25   typedef Graph::Node Node;
    26   typedef Graph::EdgeIt EdgeIt;
    27   typedef Graph::NodeIt NodeIt;
    28   typedef Graph::EdgeMap<int> LengthMap;
    29 
    30   Graph g;
    31   Node s, t;
    32   LengthMap length(g);
    33 
    34   readDimacs(std::cin, g, length, s, t);
    35 
    36   cout << "digraph lemon_dot_example {" << endl;
    37   cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
    38   for(NodeIt n(g); n!=INVALID; ++n) {
    39     if (n==s) {
    40       cout << "  n" << g.id(n) 
    41 	   << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
    42     } else {
    43       if (n==t) {
    44 	cout << "  n" << g.id(n) 
    45 	     << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; 
    46       } else {
    47 	cout << "  n" << g.id(n) 
    48 	     << " [ label=\"" << g.id(n) << "\" ]; " << endl; 
    49       }
    50     }
    51   }
    52   cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
    53   for(EdgeIt e(g); e!=INVALID; ++e) {
    54     cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
    55 	 << " [ label=\"" << g.id(e) 
    56 	 << ", length:" << length[e] << "\" ]; " << endl;
    57   } 
    58   cout << "}" << endl;
    59 }