ladanyi@1636: /* -*- C++ -*- ladanyi@1636: * alpar@1956: * This file is a part of LEMON, a generic C++ optimization library alpar@1956: * alpar@2391: * Copyright (C) 2003-2007 alpar@1956: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport ladanyi@1636: * (Egervary Research Group on Combinatorial Optimization, EGRES). ladanyi@1636: * ladanyi@1636: * Permission to use, modify and distribute this software is granted ladanyi@1636: * provided that this copyright notice appears in all copies. For ladanyi@1636: * precise terms see the accompanying LICENSE file. ladanyi@1636: * ladanyi@1636: * This software is provided "AS IS" with no warranty of any kind, ladanyi@1636: * express or implied, and with no claim as to its suitability for any ladanyi@1636: * purpose. ladanyi@1636: * ladanyi@1636: */ marci@931: deba@2081: ///\file deba@2413: ///\brief Dim (DIMACS) to Dot (Graphviz) converter deba@2081: /// deba@2413: /// This program can convert the DIMACS format to Graphviz format. deba@2081: /// deba@2413: /// dim_to_dot dimacs_max_flow_file > dot_output_file deba@2081: /// deba@2413: /// This program makes a dot file from a DIMACS max flow file. deba@2413: /// This program can be an aid in making up to date visualized deba@2413: /// documantation of demo programs. deba@2081: /// deba@2081: /// \include dim_to_dot.cc athos@1577: marci@931: #include marci@931: #include marci@931: marci@931: #include marci@931: #include marci@931: marci@931: using namespace lemon; marci@931: marci@931: using std::cout; marci@931: using std::endl; marci@931: athos@1577: int main(int argc, char *argv[]) athos@1577: { athos@1577: if(argc<2) athos@1577: { deba@2413: std::cerr << "USAGE: dim_to_dot input_file.dim" << std::endl; athos@1577: 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: return 0; athos@1577: } athos@1577: athos@1577: //input stream to read the graph from athos@1577: std::ifstream is(argv[1]); athos@1577: marci@931: typedef SmartGraph Graph; marci@931: marci@931: typedef Graph::Edge Edge; marci@931: typedef Graph::Node Node; marci@931: typedef Graph::EdgeIt EdgeIt; marci@931: typedef Graph::NodeIt NodeIt; marci@931: typedef Graph::EdgeMap LengthMap; marci@931: marci@931: Graph g; marci@931: Node s, t; marci@931: LengthMap length(g); marci@931: athos@1577: readDimacs(is, g, length, s, t); marci@931: marci@931: cout << "digraph lemon_dot_example {" << endl; marci@931: cout << " node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; marci@931: for(NodeIt n(g); n!=INVALID; ++n) { marci@931: if (n==s) { marci@931: cout << " n" << g.id(n) marci@931: << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl; marci@931: } else { marci@931: if (n==t) { marci@931: cout << " n" << g.id(n) marci@931: << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl; marci@931: } else { marci@931: cout << " n" << g.id(n) marci@931: << " [ label=\"" << g.id(n) << "\" ]; " << endl; marci@931: } marci@931: } marci@931: } marci@931: cout << " edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl; marci@931: for(EdgeIt e(g); e!=INVALID; ++e) { alpar@986: cout << " n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e)) marci@931: << " [ label=\"" << g.id(e) marci@931: << ", length:" << length[e] << "\" ]; " << endl; marci@931: } marci@931: cout << "}" << endl; marci@931: }