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