SubGraphWrapper code example, converter from dimacs to graphviz dot file.
authormarci
Thu, 30 Sep 2004 17:32:00 +0000
changeset 9319227ecd7b0bc
parent 930 e89f3bd26fd4
child 932 ade3cdb9b45d
SubGraphWrapper code example, converter from dimacs to graphviz dot file.
The second one can be a tool for generating documentation of code examples.
src/demo/dim_to_dot.cc
src/demo/sub_graph_wrapper_demo.cc
     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 +}
     2.1 --- a/src/demo/sub_graph_wrapper_demo.cc	Thu Sep 30 17:30:20 2004 +0000
     2.2 +++ b/src/demo/sub_graph_wrapper_demo.cc	Thu Sep 30 17:32:00 2004 +0000
     2.3 @@ -14,7 +14,7 @@
     2.4  #include <lemon/graph_wrapper.h>
     2.5  #include <lemon/dimacs.h>
     2.6  #include <lemon/preflow.h>
     2.7 -#include <lemon/tight_edge_filter_map.h>
     2.8 +#include <tight_edge_filter_map.h>
     2.9  
    2.10  using namespace lemon;
    2.11  
    2.12 @@ -37,9 +37,9 @@
    2.13  
    2.14    readDimacs(std::cin, g, length, s, t);
    2.15  
    2.16 -  cout << "edges with lengths (of form tail--length->head): " << endl;
    2.17 +  cout << "edges with lengths (of form id, tail--length->head): " << endl;
    2.18    for(EdgeIt e(g); e!=INVALID; ++e) 
    2.19 -    cout << " " << g.id(g.tail(e)) << "--" 
    2.20 +    cout << " " << g.id(e) << ", " << g.id(g.tail(e)) << "--" 
    2.21  	 << length[e] << "->" << g.id(g.head(e)) << endl;
    2.22  
    2.23    cout << "s: " << g.id(s) << " t: " << g.id(t) << endl;
    2.24 @@ -67,12 +67,13 @@
    2.25      preflow(gw, s, t, const_1_map, flow);
    2.26    preflow.run();
    2.27  
    2.28 +  cout << "maximum number of edge-disjoint shortest path: " 
    2.29 +       << preflow.flowValue() << endl;
    2.30    cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " 
    2.31         << endl;
    2.32    for(EdgeIt e(g); e!=INVALID; ++e) 
    2.33      if (flow[e])
    2.34 -      cout << " " << g.id(g.tail(e)) << "--" 
    2.35 +      cout << " " << g.id(e) << ", "
    2.36 +	   << g.id(g.tail(e)) << "--" 
    2.37  	   << length[e] << "->" << g.id(g.head(e)) << endl;
    2.38 -
    2.39 -  return 0;
    2.40  }