1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
4 This file is part of libDAI.
6 libDAI is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libDAI is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libDAI; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <dai/factorgraph.h>
32 int main( int argc
, char *argv
[] ) {
34 cout
<< "Usage: " << argv
[0] << " <in.fg> <out.dot>" << endl
<< endl
;
35 cout
<< "Converts a .fg (FactorGraph) file to a .dot (GraphViz) file for visualization." << endl
;
36 cout
<< "The .dot file can be converted to .ps (PostScript by 'neato -T ps out.dot > out.ps'" << endl
;
41 char *infile
= argv
[1];
43 if( fg
.ReadFromFile( infile
) ) {
44 cerr
<< "Error reading file " << infile
<< endl
;
47 if( string( argv
[2] ) != "-" )
48 fg
.WriteToDotFile( argv
[2] );
50 cout
<< "graph G {" << endl
;
51 cout
<< "graph[size=\"9,9\"];" << endl
;
52 cout
<< "node[shape=circle,width=0.4,fixedsize=true];" << endl
;
53 for( size_t i
= 0; i
< fg
.nrVars(); i
++ )
54 cout
<< "\tx" << fg
.var(i
).label() << ";" << endl
;
55 cout
<< "node[shape=box,style=filled,color=lightgrey,width=0.3,height=0.3,fixedsize=true];" << endl
;
56 for( size_t I
= 0; I
< fg
.nrFactors(); I
++ )
57 cout
<< "\tp" << I
<< ";" << endl
;
58 for( size_t i
= 0; i
< fg
.nrVars(); i
++ )
59 foreach( const FactorGraph::Neighbor
&I
, fg
.nbV(i
) )
60 cout
<< "\tx" << fg
.var(i
).label() << " -- p" << I
<< ";" << endl
;