demo/dim_to_dot.cc
author alpar
Wed, 18 Jan 2006 09:40:53 +0000
changeset 1897 dd90f57b01d1
parent 1636 260ac104190f
child 1956 a055123339d5
permissions -rw-r--r--
Tolerance<long double> added
ladanyi@1636
     1
/* -*- C++ -*-
ladanyi@1636
     2
 * demo/dim_to_dot.cc - Part of LEMON, a generic C++ optimization library
ladanyi@1636
     3
 *
alpar@1875
     4
 * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
ladanyi@1636
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
ladanyi@1636
     6
 *
ladanyi@1636
     7
 * Permission to use, modify and distribute this software is granted
ladanyi@1636
     8
 * provided that this copyright notice appears in all copies. For
ladanyi@1636
     9
 * precise terms see the accompanying LICENSE file.
ladanyi@1636
    10
 *
ladanyi@1636
    11
 * This software is provided "AS IS" with no warranty of any kind,
ladanyi@1636
    12
 * express or implied, and with no claim as to its suitability for any
ladanyi@1636
    13
 * purpose.
ladanyi@1636
    14
 *
ladanyi@1636
    15
 */
marci@931
    16
marci@931
    17
// Use a DIMACS max flow file as stdin.
marci@931
    18
// dim_to_dot < dimacs_max_flow_file > dot_output_file
marci@931
    19
// This program makes a dot file from a dimacs max flow file. 
marci@931
    20
// This program can be an aid in making up to date visualized documantation 
marci@931
    21
// of demo programs.
marci@931
    22
athos@1577
    23
// For later documentation (if marci does not do it)
athos@1577
    24
// Az a graphviz csomag egy egyszeru formatuma, ami egy graphrajzolo csomag.
athos@1577
    25
// Az EdgeSubGraphAdaptor doksijaban szerepel egy kirajzolt graf. Azt nem
athos@1577
    26
// kezzel csinaltam, hanem a megfelelo dim file-bol ezzel a progival. A
athos@1577
    27
// doxygen ugyanis ilyet eszik, igy a juzer vizualisan is latja a grafot a
athos@1577
    28
// doksiban, es sajat maga is le tudja futtatni az algoritmust, mert ott van
athos@1577
    29
// a kezeben a dim file is. Es mivel ez egy generalt file, ezert ha vmit
athos@1577
    30
// valtoztatunk a dim-en, ezt is konnyu bemasolni. Uff.
athos@1577
    31
athos@1577
    32
marci@931
    33
#include <iostream>
marci@931
    34
#include <fstream>
marci@931
    35
marci@931
    36
#include <lemon/smart_graph.h>
marci@931
    37
#include <lemon/dimacs.h>
marci@931
    38
marci@931
    39
using namespace lemon;
marci@931
    40
marci@931
    41
using std::cout;
marci@931
    42
using std::endl;
marci@931
    43
athos@1577
    44
int main(int argc, char *argv[]) 
athos@1577
    45
{
athos@1577
    46
  if(argc<2)
athos@1577
    47
  {
athos@1577
    48
      std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl;
athos@1577
    49
      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
    50
      return 0;
athos@1577
    51
  }
athos@1577
    52
athos@1577
    53
athos@1577
    54
  //input stream to read the graph from
athos@1577
    55
  std::ifstream is(argv[1]);
athos@1577
    56
marci@931
    57
  typedef SmartGraph Graph;
marci@931
    58
marci@931
    59
  typedef Graph::Edge Edge;
marci@931
    60
  typedef Graph::Node Node;
marci@931
    61
  typedef Graph::EdgeIt EdgeIt;
marci@931
    62
  typedef Graph::NodeIt NodeIt;
marci@931
    63
  typedef Graph::EdgeMap<int> LengthMap;
marci@931
    64
marci@931
    65
  Graph g;
marci@931
    66
  Node s, t;
marci@931
    67
  LengthMap length(g);
marci@931
    68
athos@1577
    69
  readDimacs(is, g, length, s, t);
marci@931
    70
marci@931
    71
  cout << "digraph lemon_dot_example {" << endl;
marci@931
    72
  cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
marci@931
    73
  for(NodeIt n(g); n!=INVALID; ++n) {
marci@931
    74
    if (n==s) {
marci@931
    75
      cout << "  n" << g.id(n) 
marci@931
    76
	   << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
marci@931
    77
    } else {
marci@931
    78
      if (n==t) {
marci@931
    79
	cout << "  n" << g.id(n) 
marci@931
    80
	     << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; 
marci@931
    81
      } else {
marci@931
    82
	cout << "  n" << g.id(n) 
marci@931
    83
	     << " [ label=\"" << g.id(n) << "\" ]; " << endl; 
marci@931
    84
      }
marci@931
    85
    }
marci@931
    86
  }
marci@931
    87
  cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
marci@931
    88
  for(EdgeIt e(g); e!=INVALID; ++e) {
alpar@986
    89
    cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
marci@931
    90
	 << " [ label=\"" << g.id(e) 
marci@931
    91
	 << ", length:" << length[e] << "\" ]; " << endl;
marci@931
    92
  } 
marci@931
    93
  cout << "}" << endl;
marci@931
    94
}