demo/dim_to_dot.cc
author deba
Mon, 02 Oct 2006 16:11:00 +0000
changeset 2229 4dbb6dd2dd4b
parent 1956 a055123339d5
child 2391 14a343be7a5a
permissions -rw-r--r--
Mersenne Twister random number generator

The code is based on the official MT19937 implementation
It is fully rewritten:

http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

todo: fixing copyright information
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@1956
     5
 * Copyright (C) 2003-2006
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@2081
    20
///\brief Dim (Dimacs) to Dot (Graphviz) converter
deba@2081
    21
///
deba@2081
    22
/// This program can convert the dimacs format to graphviz dot format.
deba@2081
    23
///
deba@2081
    24
/// Use a DIMACS max flow file as stdin.
deba@2081
    25
///
deba@2081
    26
/// <tt>dim_to_dot < dimacs_max_flow_file > dot_output_file</tt>
deba@2081
    27
///
deba@2081
    28
/// This program makes a dot file from a dimacs max flow file. 
deba@2081
    29
/// This program can be an aid in making up to date visualized documantation 
deba@2081
    30
/// of demo programs.
deba@2081
    31
///
deba@2081
    32
/// \include dim_to_dot.cc
athos@1577
    33
marci@931
    34
#include <iostream>
marci@931
    35
#include <fstream>
marci@931
    36
marci@931
    37
#include <lemon/smart_graph.h>
marci@931
    38
#include <lemon/dimacs.h>
marci@931
    39
marci@931
    40
using namespace lemon;
marci@931
    41
marci@931
    42
using std::cout;
marci@931
    43
using std::endl;
marci@931
    44
athos@1577
    45
int main(int argc, char *argv[]) 
athos@1577
    46
{
athos@1577
    47
  if(argc<2)
athos@1577
    48
  {
athos@1577
    49
      std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl;
athos@1577
    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;
athos@1577
    51
      return 0;
athos@1577
    52
  }
athos@1577
    53
athos@1577
    54
athos@1577
    55
  //input stream to read the graph from
athos@1577
    56
  std::ifstream is(argv[1]);
athos@1577
    57
marci@931
    58
  typedef SmartGraph Graph;
marci@931
    59
marci@931
    60
  typedef Graph::Edge Edge;
marci@931
    61
  typedef Graph::Node Node;
marci@931
    62
  typedef Graph::EdgeIt EdgeIt;
marci@931
    63
  typedef Graph::NodeIt NodeIt;
marci@931
    64
  typedef Graph::EdgeMap<int> LengthMap;
marci@931
    65
marci@931
    66
  Graph g;
marci@931
    67
  Node s, t;
marci@931
    68
  LengthMap length(g);
marci@931
    69
athos@1577
    70
  readDimacs(is, g, length, s, t);
marci@931
    71
marci@931
    72
  cout << "digraph lemon_dot_example {" << endl;
marci@931
    73
  cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
marci@931
    74
  for(NodeIt n(g); n!=INVALID; ++n) {
marci@931
    75
    if (n==s) {
marci@931
    76
      cout << "  n" << g.id(n) 
marci@931
    77
	   << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
marci@931
    78
    } else {
marci@931
    79
      if (n==t) {
marci@931
    80
	cout << "  n" << g.id(n) 
marci@931
    81
	     << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; 
marci@931
    82
      } else {
marci@931
    83
	cout << "  n" << g.id(n) 
marci@931
    84
	     << " [ label=\"" << g.id(n) << "\" ]; " << endl; 
marci@931
    85
      }
marci@931
    86
    }
marci@931
    87
  }
marci@931
    88
  cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
marci@931
    89
  for(EdgeIt e(g); e!=INVALID; ++e) {
alpar@986
    90
    cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
marci@931
    91
	 << " [ label=\"" << g.id(e) 
marci@931
    92
	 << ", length:" << length[e] << "\" ]; " << endl;
marci@931
    93
  } 
marci@931
    94
  cout << "}" << endl;
marci@931
    95
}