Partial adoption of contributions by Giuseppe:
[libdai.git] / utils / fginfo.cpp
1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
3
4 This file is part of libDAI.
5
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.
10
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.
15
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
19 */
20
21
22 #include <iostream>
23 #include <cstdlib>
24 #include <dai/factorgraph.h>
25
26
27 using namespace dai;
28 using namespace std;
29
30
31 int main( int argc, char *argv[] ) {
32 if( argc != 2 ) {
33 cout << "Usage: " << argv[0] << " <in.fg>" << endl << endl;
34 cout << "Reports some characteristics of the .fg network." << endl;
35 return 1;
36 } else {
37 // Read factorgraph
38 FactorGraph fg;
39 char *infile = argv[1];
40
41 if( fg.ReadFromFile( infile ) ) {
42 cerr << "Error reading file " << infile << endl;
43 return 2;
44 } else {
45 cout << "Number of variables: " << fg.nrVars() << endl;
46 cout << "Number of factors: " << fg.nrFactors() << endl;
47 cout << "Connected: " << fg.isConnected() << endl;
48 // cout << "Treewidth: " << endl;
49
50 double cavsum_lcbp = 0.0;
51 double cavsum_lcbp2 = 0.0;
52 size_t max_Delta_size = 0;
53 for( size_t i = 0; i < fg.nrVars(); i++ ) {
54 VarSet di = fg.delta(fg.var(i));
55 size_t Ds = fg.Delta(fg.var(i)).stateSpace();
56 if( Ds > max_Delta_size )
57 max_Delta_size = Ds;
58 cavsum_lcbp += di.stateSpace();
59 for( VarSet::const_iterator j = di.begin(); j != di.end(); j++ )
60 cavsum_lcbp2 += j->states();
61 }
62 cout << "Maximum pancake has " << max_Delta_size << " states" << endl;
63 cout << "LCBP with full cavities needs " << cavsum_lcbp << " BP runs" << endl;
64 cout << "LCBP with only pairinteractions needs " << cavsum_lcbp2 << " BP runs" << endl;
65
66 return 0;
67 }
68 }
69 }
70