dim_to_dot.cc File Reference


Detailed Description

This program can convert the DIMACS format to Graphviz format.

dim_to_dot dimacs_max_flow_file > dot_output_file

This program makes a dot file from a DIMACS max flow file. This program can be an aid in making up to date visualized documantation of demo programs.

/* -*- C++ -*-
 *
 * This file is a part of LEMON, a generic C++ optimization library
 *
 * Copyright (C) 2003-2008
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
 *
 * Permission to use, modify and distribute this software is granted
 * provided that this copyright notice appears in all copies. For
 * precise terms see the accompanying LICENSE file.
 *
 * This software is provided "AS IS" with no warranty of any kind,
 * express or implied, and with no claim as to its suitability for any
 * purpose.
 *
 */


#include <iostream>
#include <fstream>

#include <lemon/smart_graph.h>
#include <lemon/dimacs.h>

using namespace lemon;

using std::cout;
using std::endl;

int main(int argc, char *argv[]) 
{
  if(argc<2)
  {
      std::cerr << "USAGE: dim_to_dot input_file.dim" << std::endl;
      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;
      return 0;
  }

  //input stream to read the graph from
  std::ifstream is(argv[1]);

  typedef SmartGraph Graph;

  typedef Graph::Edge Edge;
  typedef Graph::Node Node;
  typedef Graph::EdgeIt EdgeIt;
  typedef Graph::NodeIt NodeIt;
  typedef Graph::EdgeMap<int> LengthMap;

  Graph g;
  Node s, t;
  LengthMap length(g);

  readDimacs(is, g, length, s, t);

  cout << "digraph lemon_dot_example {" << endl;
  cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
  for(NodeIt n(g); n!=INVALID; ++n) {
    if (n==s) {
      cout << "  n" << g.id(n) 
           << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
    } else {
      if (n==t) {
        cout << "  n" << g.id(n) 
             << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; 
      } else {
        cout << "  n" << g.id(n) 
             << " [ label=\"" << g.id(n) << "\" ]; " << endl; 
      }
    }
  }
  cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
  for(EdgeIt e(g); e!=INVALID; ++e) {
    cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
         << " [ label=\"" << g.id(e) 
         << ", length:" << length[e] << "\" ]; " << endl;
  } 
  cout << "}" << endl;
}
#include <iostream>
#include <fstream>
#include <lemon/smart_graph.h>
#include <lemon/dimacs.h>

Generated on Thu Jun 4 04:03:09 2009 for LEMON by  doxygen 1.5.9