Added workaround for bug in Boost Graph Library
[libdai.git] / utils / fg2dot.cpp
1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
4
5 This file is part of libDAI.
6
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22
23 #include <iostream>
24 #include <fstream>
25 #include <cstdlib>
26 #include <string>
27 #include <dai/factorgraph.h>
28
29
30 using namespace dai;
31 using namespace std;
32
33
34 int main( int argc, char *argv[] ) {
35 if( argc != 3 ) {
36 cout << "Usage: " << argv[0] << " <in.fg> <out.dot>" << endl << endl;
37 cout << "Converts a .fg (FactorGraph) file to a .dot (GraphViz) file for" << endl;
38 cout << "visualization. The .dot file can be converted to .ps (PostScript) by" << endl;
39 cout << "'neato -T ps out.dot > out.ps' or by 'dot -T ps out.dot > out.ps'" << endl << endl;
40 return 1;
41 } else {
42 // Read factorgraph
43 FactorGraph fg;
44 char *infile = argv[1];
45
46 fg.ReadFromFile( infile );
47
48 ostream *os = &cout;
49 ofstream outfile;
50 if( string( argv[2] ) != "-" ) {
51 outfile.open( argv[2] );
52 if( !outfile.is_open() ) {
53 cerr << "Cannot open " << argv[2] << " for writing" << endl;
54 return 1;
55 }
56 os = &outfile;
57 }
58
59 fg.printDot( *os );
60
61 return 0;
62 }
63 }