/* -*- C++ -*-
*
* This file is a part of LEMON, a generic C++ optimization library
*
* Copyright (C) 2003-2006
* 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.
*
*/
///\file
///\brief Dim (Dimacs) to Dot (Graphviz) converter
///
/// This program can convert the dimacs format to graphviz dot format.
///
/// Use a DIMACS max flow file as stdin.
///
/// 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.
///
/// \include dim_to_dot.cc
#include
#include
#include
#include
using namespace lemon;
using std::cout;
using std::endl;
int main(int argc, char *argv[])
{
if(argc<2)
{
std::cerr << "USAGE: sub_graph_adaptor_demo 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 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;
}