demo/dim_to_dot.cc
author hegyi
Sun, 07 Aug 2005 22:14:59 +0000
changeset 1617 c17d61f77319
parent 1435 8e85e6bbefdf
child 1636 260ac104190f
permissions -rw-r--r--
Until this commitment gui gave us segmentation fault in the case when no element was on graph_displayer_canvas and a map to visualize by a property has been changed.
marci@931
     1
// -*- c++ -*-
marci@931
     2
marci@931
     3
// Use a DIMACS max flow file as stdin.
marci@931
     4
// dim_to_dot < dimacs_max_flow_file > dot_output_file
marci@931
     5
// This program makes a dot file from a dimacs max flow file. 
marci@931
     6
// This program can be an aid in making up to date visualized documantation 
marci@931
     7
// of demo programs.
marci@931
     8
athos@1577
     9
// For later documentation (if marci does not do it)
athos@1577
    10
// Az a graphviz csomag egy egyszeru formatuma, ami egy graphrajzolo csomag.
athos@1577
    11
// Az EdgeSubGraphAdaptor doksijaban szerepel egy kirajzolt graf. Azt nem
athos@1577
    12
// kezzel csinaltam, hanem a megfelelo dim file-bol ezzel a progival. A
athos@1577
    13
// doxygen ugyanis ilyet eszik, igy a juzer vizualisan is latja a grafot a
athos@1577
    14
// doksiban, es sajat maga is le tudja futtatni az algoritmust, mert ott van
athos@1577
    15
// a kezeben a dim file is. Es mivel ez egy generalt file, ezert ha vmit
athos@1577
    16
// valtoztatunk a dim-en, ezt is konnyu bemasolni. Uff.
athos@1577
    17
athos@1577
    18
marci@931
    19
#include <iostream>
marci@931
    20
#include <fstream>
marci@931
    21
marci@931
    22
#include <lemon/smart_graph.h>
marci@931
    23
#include <lemon/dimacs.h>
marci@931
    24
marci@931
    25
using namespace lemon;
marci@931
    26
marci@931
    27
using std::cout;
marci@931
    28
using std::endl;
marci@931
    29
athos@1577
    30
int main(int argc, char *argv[]) 
athos@1577
    31
{
athos@1577
    32
  if(argc<2)
athos@1577
    33
  {
athos@1577
    34
      std::cerr << "USAGE: sub_graph_adaptor_demo input_file.dim" << std::endl;
athos@1577
    35
      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
    36
      return 0;
athos@1577
    37
  }
athos@1577
    38
athos@1577
    39
athos@1577
    40
  //input stream to read the graph from
athos@1577
    41
  std::ifstream is(argv[1]);
athos@1577
    42
marci@931
    43
  typedef SmartGraph Graph;
marci@931
    44
marci@931
    45
  typedef Graph::Edge Edge;
marci@931
    46
  typedef Graph::Node Node;
marci@931
    47
  typedef Graph::EdgeIt EdgeIt;
marci@931
    48
  typedef Graph::NodeIt NodeIt;
marci@931
    49
  typedef Graph::EdgeMap<int> LengthMap;
marci@931
    50
marci@931
    51
  Graph g;
marci@931
    52
  Node s, t;
marci@931
    53
  LengthMap length(g);
marci@931
    54
athos@1577
    55
  readDimacs(is, g, length, s, t);
marci@931
    56
marci@931
    57
  cout << "digraph lemon_dot_example {" << endl;
marci@931
    58
  cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
marci@931
    59
  for(NodeIt n(g); n!=INVALID; ++n) {
marci@931
    60
    if (n==s) {
marci@931
    61
      cout << "  n" << g.id(n) 
marci@931
    62
	   << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
marci@931
    63
    } else {
marci@931
    64
      if (n==t) {
marci@931
    65
	cout << "  n" << g.id(n) 
marci@931
    66
	     << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; 
marci@931
    67
      } else {
marci@931
    68
	cout << "  n" << g.id(n) 
marci@931
    69
	     << " [ label=\"" << g.id(n) << "\" ]; " << endl; 
marci@931
    70
      }
marci@931
    71
    }
marci@931
    72
  }
marci@931
    73
  cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
marci@931
    74
  for(EdgeIt e(g); e!=INVALID; ++e) {
alpar@986
    75
    cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
marci@931
    76
	 << " [ label=\"" << g.id(e) 
marci@931
    77
	 << ", length:" << length[e] << "\" ]; " << endl;
marci@931
    78
  } 
marci@931
    79
  cout << "}" << endl;
marci@931
    80
}