# HG changeset patch # User marci # Date 1096565520 0 # Node ID 9227ecd7b0bc84ec5882c6ab72e6126f047fae6a # Parent e89f3bd26fd46373f50e24d9c6f52431a0646de8 SubGraphWrapper code example, converter from dimacs to graphviz dot file. The second one can be a tool for generating documentation of code examples. diff -r e89f3bd26fd4 -r 9227ecd7b0bc src/demo/dim_to_dot.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/demo/dim_to_dot.cc Thu Sep 30 17:32:00 2004 +0000 @@ -0,0 +1,59 @@ +// -*- c++ -*- + +// Use a DIMACS max flow file as stdin. +// dim_to_dot < dimacs_max_flow_file > dot_output_file +// This program makes a dot file from a dimacs max flow file. +// This program can be an aid in making up to date visualized documantation +// of demo programs. + +#include +#include + +#include +#include + +using namespace lemon; + +using std::cout; +using std::endl; + +int main() +{ + typedef SmartGraph Graph; + + typedef Graph::Edge Edge; + typedef Graph::Node Node; + typedef Graph::EdgeIt EdgeIt; + typedef Graph::NodeIt NodeIt; + typedef Graph::EdgeMap LengthMap; + + Graph g; + Node s, t; + LengthMap length(g); + + readDimacs(std::cin, g, length, s, t); + + cout << "digraph lemon_dot_example {" << endl; + cout << " node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; + for(NodeIt n(g); n!=INVALID; ++n) { + if (n==s) { + cout << " n" << g.id(n) + << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl; + } else { + if (n==t) { + cout << " n" << g.id(n) + << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; + } else { + cout << " n" << g.id(n) + << " [ label=\"" << g.id(n) << "\" ]; " << endl; + } + } + } + cout << " edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; + for(EdgeIt e(g); e!=INVALID; ++e) { + cout << " n" << g.id(g.tail(e)) << " -> " << " n" << g.id(g.head(e)) + << " [ label=\"" << g.id(e) + << ", length:" << length[e] << "\" ]; " << endl; + } + cout << "}" << endl; +} diff -r e89f3bd26fd4 -r 9227ecd7b0bc src/demo/sub_graph_wrapper_demo.cc --- a/src/demo/sub_graph_wrapper_demo.cc Thu Sep 30 17:30:20 2004 +0000 +++ b/src/demo/sub_graph_wrapper_demo.cc Thu Sep 30 17:32:00 2004 +0000 @@ -14,7 +14,7 @@ #include #include #include -#include +#include using namespace lemon; @@ -37,9 +37,9 @@ readDimacs(std::cin, g, length, s, t); - cout << "edges with lengths (of form tail--length->head): " << endl; + cout << "edges with lengths (of form id, tail--length->head): " << endl; for(EdgeIt e(g); e!=INVALID; ++e) - cout << " " << g.id(g.tail(e)) << "--" + cout << " " << g.id(e) << ", " << g.id(g.tail(e)) << "--" << length[e] << "->" << g.id(g.head(e)) << endl; cout << "s: " << g.id(s) << " t: " << g.id(t) << endl; @@ -67,12 +67,13 @@ preflow(gw, s, t, const_1_map, flow); preflow.run(); + cout << "maximum number of edge-disjoint shortest path: " + << preflow.flowValue() << endl; cout << "edges of the maximum number of edge-disjoint shortest s-t paths: " << endl; for(EdgeIt e(g); e!=INVALID; ++e) if (flow[e]) - cout << " " << g.id(g.tail(e)) << "--" + cout << " " << g.id(e) << ", " + << g.id(g.tail(e)) << "--" << length[e] << "->" << g.id(g.head(e)) << endl; - - return 0; }