COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/dim_to_dot.cc @ 2553:bfced05fa852

Last change on this file since 2553:bfced05fa852 was 2553:bfced05fa852, checked in by Alpar Juttner, 16 years ago

Happy New Year to LEMON (+ better update-copyright-header script)

File size: 2.6 KB
RevLine 
[1636]1/* -*- C++ -*-
2 *
[1956]3 * This file is a part of LEMON, a generic C++ optimization library
4 *
[2553]5 * Copyright (C) 2003-2008
[1956]6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1636]7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
[931]18
[2081]19///\file
[2413]20///\brief Dim (DIMACS) to Dot (Graphviz) converter
[2081]21///
[2413]22/// This program can convert the DIMACS format to Graphviz format.
[2081]23///
[2413]24/// <tt>dim_to_dot dimacs_max_flow_file > dot_output_file</tt>
[2081]25///
[2413]26/// This program makes a dot file from a DIMACS max flow file.
27/// This program can be an aid in making up to date visualized
28/// documantation of demo programs.
[2081]29///
30/// \include dim_to_dot.cc
[1577]31
[931]32#include <iostream>
33#include <fstream>
34
35#include <lemon/smart_graph.h>
36#include <lemon/dimacs.h>
37
38using namespace lemon;
39
40using std::cout;
41using std::endl;
42
[1577]43int main(int argc, char *argv[])
44{
45  if(argc<2)
46  {
[2413]47      std::cerr << "USAGE: dim_to_dot input_file.dim" << std::endl;
[1577]48      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;
49      return 0;
50  }
51
52  //input stream to read the graph from
53  std::ifstream is(argv[1]);
54
[931]55  typedef SmartGraph Graph;
56
57  typedef Graph::Edge Edge;
58  typedef Graph::Node Node;
59  typedef Graph::EdgeIt EdgeIt;
60  typedef Graph::NodeIt NodeIt;
61  typedef Graph::EdgeMap<int> LengthMap;
62
63  Graph g;
64  Node s, t;
65  LengthMap length(g);
66
[1577]67  readDimacs(is, g, length, s, t);
[931]68
69  cout << "digraph lemon_dot_example {" << endl;
70  cout << "  node [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
71  for(NodeIt n(g); n!=INVALID; ++n) {
72    if (n==s) {
73      cout << "  n" << g.id(n)
74           << " [ label=\"" << g.id(n) << " (s)\" ]; " << endl;
75    } else {
76      if (n==t) {
77        cout << "  n" << g.id(n)
78             << " [ label=\"" << g.id(n) << " (t)\" ]; " << endl;
79      } else {
80        cout << "  n" << g.id(n)
81             << " [ label=\"" << g.id(n) << "\" ]; " << endl;
82      }
83    }
84  }
85  cout << "  edge [ shape=ellipse, fontname=Helvetica, fontsize=10 ];" << endl;
86  for(EdgeIt e(g); e!=INVALID; ++e) {
[986]87    cout << "  n" << g.id(g.source(e)) << " -> " << " n" << g.id(g.target(e))
[931]88         << " [ label=\"" << g.id(e)
89         << ", length:" << length[e] << "\" ]; " << endl;
90  }
91  cout << "}" << endl;
92}
Note: See TracBrowser for help on using the repository browser.