demo/dim_to_dot.cc
author alpar
Mon, 20 Feb 2006 06:44:07 +0000
changeset 1974 191223f4b639
parent 1875 98698b69a902
child 2081 94a7deb46c07
permissions -rw-r--r--
Public data members of xy became documented
     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 // Use a DIMACS max flow file as stdin.
    20 // dim_to_dot < dimacs_max_flow_file > dot_output_file
    21 // This program makes a dot file from a dimacs max flow file. 
    22 // This program can be an aid in making up to date visualized documantation 
    23 // of demo programs.
    24 
    25 // For later documentation (if marci does not do it)
    26 // Az a graphviz csomag egy egyszeru formatuma, ami egy graphrajzolo csomag.
    27 // Az EdgeSubGraphAdaptor doksijaban szerepel egy kirajzolt graf. Azt nem
    28 // kezzel csinaltam, hanem a megfelelo dim file-bol ezzel a progival. A
    29 // doxygen ugyanis ilyet eszik, igy a juzer vizualisan is latja a grafot a
    30 // doksiban, es sajat maga is le tudja futtatni az algoritmust, mert ott van
    31 // a kezeben a dim file is. Es mivel ez egy generalt file, ezert ha vmit
    32 // valtoztatunk a dim-en, ezt is konnyu bemasolni. Uff.
    33 
    34 
    35 #include <iostream>
    36 #include <fstream>
    37 
    38 #include <lemon/smart_graph.h>
    39 #include <lemon/dimacs.h>
    40 
    41 using namespace lemon;
    42 
    43 using std::cout;
    44 using std::endl;
    45 
    46 int main(int argc, char *argv[]) 
    47 {
    48   if(argc<2)
    49   {
    50       std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl;
    51       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;
    52       return 0;
    53   }
    54 
    55 
    56   //input stream to read the graph from
    57   std::ifstream is(argv[1]);
    58 
    59   typedef SmartGraph Graph;
    60 
    61   typedef Graph::Edge Edge;
    62   typedef Graph::Node Node;
    63   typedef Graph::EdgeIt EdgeIt;
    64   typedef Graph::NodeIt NodeIt;
    65   typedef Graph::EdgeMap<int> LengthMap;
    66 
    67   Graph g;
    68   Node s, t;
    69   LengthMap length(g);
    70 
    71   readDimacs(is, g, length, s, t);
    72 
    73   cout << "digraph lemon_dot_example {" << endl;
    74   cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
    75   for(NodeIt n(g); n!=INVALID; ++n) {
    76     if (n==s) {
    77       cout << "  n" << g.id(n) 
    78 	   << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
    79     } else {
    80       if (n==t) {
    81 	cout << "  n" << g.id(n) 
    82 	     << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; 
    83       } else {
    84 	cout << "  n" << g.id(n) 
    85 	     << " [ label=\"" << g.id(n) << "\" ]; " << endl; 
    86       }
    87     }
    88   }
    89   cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
    90   for(EdgeIt e(g); e!=INVALID; ++e) {
    91     cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
    92 	 << " [ label=\"" << g.id(e) 
    93 	 << ", length:" << length[e] << "\" ]; " << endl;
    94   } 
    95   cout << "}" << endl;
    96 }