Various cleanups
[libdai.git] / src / alldai.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 <string>
24 #include <dai/alldai.h>
25 #include <dai/properties.h>
26 #include <dai/exceptions.h>
27
28
29 namespace dai {
30
31
32 using namespace std;
33
34
35 InfAlg *newInfAlg( const std::string &name, const FactorGraph &fg, const PropertySet &opts ) {
36 if( name == ExactInf::Name )
37 return new ExactInf (fg, opts);
38 #ifdef DAI_WITH_BP
39 if( name == BP::Name )
40 return new BP (fg, opts);
41 #endif
42 #ifdef DAI_WITH_MF
43 if( name == MF::Name )
44 return new MF (fg, opts);
45 #endif
46 #ifdef DAI_WITH_HAK
47 if( name == HAK::Name )
48 return new HAK (fg, opts);
49 #endif
50 #ifdef DAI_WITH_LC
51 if( name == LC::Name )
52 return new LC (fg, opts);
53 #endif
54 #ifdef DAI_WITH_TREEEP
55 if( name == TreeEP::Name )
56 return new TreeEP (fg, opts);
57 #endif
58 #ifdef DAI_WITH_JTREE
59 if( name == JTree::Name )
60 return new JTree (fg, opts);
61 #endif
62 #ifdef DAI_WITH_MR
63 if( name == MR::Name )
64 return new MR (fg, opts);
65 #endif
66 #ifdef DAI_WITH_GIBBS
67 if( name == Gibbs::Name )
68 return new Gibbs (fg, opts);
69 #endif
70 #ifdef DAI_WITH_CBP
71 if( name == CBP::Name )
72 return new CBP (fg, opts);
73 #endif
74 DAI_THROW(UNKNOWN_DAI_ALGORITHM);
75 }
76
77
78 /// \todo Make alias file non-testdai-specific, and use it in newInfAlgFromString
79 InfAlg *newInfAlgFromString( const std::string &s, const FactorGraph &fg ) {
80 string::size_type pos = s.find_first_of('[');
81 string name;
82 PropertySet opts;
83 if( pos == string::npos ) {
84 name = s;
85 } else {
86 name = s.substr(0,pos);
87
88 stringstream ss;
89 ss << s.substr(pos,s.length());
90 ss >> opts;
91 }
92 return newInfAlg(name,fg,opts);
93 }
94
95
96 } // end of namespace dai