| 1 | /* -*- C++ -*- |
|---|
| 2 | * |
|---|
| 3 | * This file is a part of LEMON, a generic C++ optimization library |
|---|
| 4 | * |
|---|
| 5 | * Copyright (C) 2003-2006 |
|---|
| 6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|---|
| 7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
|---|
| 8 | * |
|---|
| 9 | * Permission to use, modify and distribute this software is granted |
|---|
| 10 | * provided that this copyright notice appears in all copies. For |
|---|
| 11 | * precise terms see the accompanying LICENSE file. |
|---|
| 12 | * |
|---|
| 13 | * This software is provided "AS IS" with no warranty of any kind, |
|---|
| 14 | * express or implied, and with no claim as to its suitability for any |
|---|
| 15 | * purpose. |
|---|
| 16 | * |
|---|
| 17 | */ |
|---|
| 18 | |
|---|
| 19 | ///\file |
|---|
| 20 | ///\brief Dim (Dimacs) to Dot (Graphviz) converter |
|---|
| 21 | /// |
|---|
| 22 | /// This program can convert the dimacs format to graphviz dot format. |
|---|
| 23 | /// |
|---|
| 24 | /// Use a DIMACS max flow file as stdin. |
|---|
| 25 | /// |
|---|
| 26 | /// <tt>dim_to_dot < dimacs_max_flow_file > dot_output_file</tt> |
|---|
| 27 | /// |
|---|
| 28 | /// This program makes a dot file from a dimacs max flow file. |
|---|
| 29 | /// This program can be an aid in making up to date visualized documantation |
|---|
| 30 | /// of demo programs. |
|---|
| 31 | /// |
|---|
| 32 | /// \include dim_to_dot.cc |
|---|
| 33 | |
|---|
| 34 | #include <iostream> |
|---|
| 35 | #include <fstream> |
|---|
| 36 | |
|---|
| 37 | #include <lemon/smart_graph.h> |
|---|
| 38 | #include <lemon/dimacs.h> |
|---|
| 39 | |
|---|
| 40 | using namespace lemon; |
|---|
| 41 | |
|---|
| 42 | using std::cout; |
|---|
| 43 | using std::endl; |
|---|
| 44 | |
|---|
| 45 | int main(int argc, char *argv[]) |
|---|
| 46 | { |
|---|
| 47 | if(argc<2) |
|---|
| 48 | { |
|---|
| 49 | std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl; |
|---|
| 50 | 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; |
|---|
| 51 | return 0; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | //input stream to read the graph from |
|---|
| 56 | std::ifstream is(argv[1]); |
|---|
| 57 | |
|---|
| 58 | typedef SmartGraph Graph; |
|---|
| 59 | |
|---|
| 60 | typedef Graph::Edge Edge; |
|---|
| 61 | typedef Graph::Node Node; |
|---|
| 62 | typedef Graph::EdgeIt EdgeIt; |
|---|
| 63 | typedef Graph::NodeIt NodeIt; |
|---|
| 64 | typedef Graph::EdgeMap<int> LengthMap; |
|---|
| 65 | |
|---|
| 66 | Graph g; |
|---|
| 67 | Node s, t; |
|---|
| 68 | LengthMap length(g); |
|---|
| 69 | |
|---|
| 70 | readDimacs(is, g, length, s, t); |
|---|
| 71 | |
|---|
| 72 | cout << "digraph lemon_dot_example {" << endl; |
|---|
| 73 | cout << " node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; |
|---|
| 74 | for(NodeIt n(g); n!=INVALID; ++n) { |
|---|
| 75 | if (n==s) { |
|---|
| 76 | cout << " n" << g.id(n) |
|---|
| 77 | << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl; |
|---|
| 78 | } else { |
|---|
| 79 | if (n==t) { |
|---|
| 80 | cout << " n" << g.id(n) |
|---|
| 81 | << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; |
|---|
| 82 | } else { |
|---|
| 83 | cout << " n" << g.id(n) |
|---|
| 84 | << " [ label=\"" << g.id(n) << "\" ]; " << endl; |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | cout << " edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; |
|---|
| 89 | for(EdgeIt e(g); e!=INVALID; ++e) { |
|---|
| 90 | cout << " n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e)) |
|---|
| 91 | << " [ label=\"" << g.id(e) |
|---|
| 92 | << ", length:" << length[e] << "\" ]; " << endl; |
|---|
| 93 | } |
|---|
| 94 | cout << "}" << endl; |
|---|
| 95 | } |
|---|