[931] | 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 | |
---|
[1577] | 9 | // For later documentation (if marci does not do it) |
---|
| 10 | // Az a graphviz csomag egy egyszeru formatuma, ami egy graphrajzolo csomag. |
---|
| 11 | // Az EdgeSubGraphAdaptor doksijaban szerepel egy kirajzolt graf. Azt nem |
---|
| 12 | // kezzel csinaltam, hanem a megfelelo dim file-bol ezzel a progival. A |
---|
| 13 | // doxygen ugyanis ilyet eszik, igy a juzer vizualisan is latja a grafot a |
---|
| 14 | // doksiban, es sajat maga is le tudja futtatni az algoritmust, mert ott van |
---|
| 15 | // a kezeben a dim file is. Es mivel ez egy generalt file, ezert ha vmit |
---|
| 16 | // valtoztatunk a dim-en, ezt is konnyu bemasolni. Uff. |
---|
| 17 | |
---|
| 18 | |
---|
[931] | 19 | #include <iostream> |
---|
| 20 | #include <fstream> |
---|
| 21 | |
---|
| 22 | #include <lemon/smart_graph.h> |
---|
| 23 | #include <lemon/dimacs.h> |
---|
| 24 | |
---|
| 25 | using namespace lemon; |
---|
| 26 | |
---|
| 27 | using std::cout; |
---|
| 28 | using std::endl; |
---|
| 29 | |
---|
[1577] | 30 | int main(int argc, char *argv[]) |
---|
| 31 | { |
---|
| 32 | if(argc<2) |
---|
| 33 | { |
---|
| 34 | std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl; |
---|
| 35 | std::cerr << "The file 'input_file.dim' has to contain a max flow instance in DIMACS format (e.g. sub_graph_adaptor_demo.dim is such a file)." << std::endl; |
---|
| 36 | return 0; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | //input stream to read the graph from |
---|
| 41 | std::ifstream is(argv[1]); |
---|
| 42 | |
---|
[931] | 43 | typedef SmartGraph Graph; |
---|
| 44 | |
---|
| 45 | typedef Graph::Edge Edge; |
---|
| 46 | typedef Graph::Node Node; |
---|
| 47 | typedef Graph::EdgeIt EdgeIt; |
---|
| 48 | typedef Graph::NodeIt NodeIt; |
---|
| 49 | typedef Graph::EdgeMap<int> LengthMap; |
---|
| 50 | |
---|
| 51 | Graph g; |
---|
| 52 | Node s, t; |
---|
| 53 | LengthMap length(g); |
---|
| 54 | |
---|
[1577] | 55 | readDimacs(is, g, length, s, t); |
---|
[931] | 56 | |
---|
| 57 | cout << "digraph lemon_dot_example {" << endl; |
---|
| 58 | cout << " node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; |
---|
| 59 | for(NodeIt n(g); n!=INVALID; ++n) { |
---|
| 60 | if (n==s) { |
---|
| 61 | cout << " n" << g.id(n) |
---|
| 62 | << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl; |
---|
| 63 | } else { |
---|
| 64 | if (n==t) { |
---|
| 65 | cout << " n" << g.id(n) |
---|
| 66 | << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; |
---|
| 67 | } else { |
---|
| 68 | cout << " n" << g.id(n) |
---|
| 69 | << " [ label=\"" << g.id(n) << "\" ]; " << endl; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | cout << " edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; |
---|
| 74 | for(EdgeIt e(g); e!=INVALID; ++e) { |
---|
[986] | 75 | cout << " n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e)) |
---|
[931] | 76 | << " [ label=\"" << g.id(e) |
---|
| 77 | << ", length:" << length[e] << "\" ]; " << endl; |
---|
| 78 | } |
---|
| 79 | cout << "}" << endl; |
---|
| 80 | } |
---|