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