[Julien Rebetez] added FactorGraph::printDot() to SWIG interface
[libdai.git] / swig / dai.i
1 /* This file is part of libDAI - http://www.libdai.org/
2 *
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 *
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6 */
7
8
9 %module dai
10
11 #include <fstream>
12
13 %include "std_string.i"
14 %include "std_vector.i"
15 %template(IntVector) std::vector<size_t>;
16 //%include "std_set.i" /* for python */
17
18 %{
19 #include "../include/dai/alldai.h"
20
21 using namespace dai;
22 %}
23
24 // ************************************************************************************************
25 %include "../include/dai/util.h"
26
27 // ************************************************************************************************
28 %ignore dai::Var::label() const;
29 %ignore dai::Var::states() const;
30 %ignore operator<<(std::ostream&, const Var&);
31 %include "../include/dai/var.h"
32 %extend dai::Var {
33 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
34 inline std::string __str() const { return (*self).toString(); } /* for octave */
35 };
36
37 // ************************************************************************************************
38 %ignore operator<<(std::ostream&, const SmallSet&);
39 %rename(__eq__) operator==(const SmallSet&, const SmallSet&); /* for python */
40 %rename(__ne__) operator!=(const SmallSet&, const SmallSet&); /* for python */
41 %rename(__lt__) operator<(const SmallSet&, const SmallSet&); /* for python */
42 %include "../include/dai/smallset.h"
43 %template(SmallSetVar) dai::SmallSet< dai::Var >;
44 %extend dai::SmallSet<dai::Var> {
45 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
46 inline std::string __str() const { return (*self).toString(); } /* for octave */
47 }
48
49 // ************************************************************************************************
50 %ignore operator<<(std::ostream&, const VarSet&);
51 %include "../include/dai/varset.h"
52 %extend dai::VarSet {
53 inline void append(const dai::Var &v) { (*self) |= v; } /* for python, octave */
54 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
55 inline std::string __str() const { return (*self).toString(); } /* for octave */
56 };
57
58 // ************************************************************************************************
59 %ignore dai::TProb::operator[];
60 %include "../include/dai/prob.h"
61 %template(Prob) dai::TProb<dai::Real>;
62 %extend dai::TProb<dai::Real> {
63 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
64 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
65 inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
66 inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
67 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
68 inline std::string __str() const { return (*self).toString(); } /* for octave */
69 };
70
71 // ************************************************************************************************
72 %ignore dai::TFactor::operator[];
73 %include "../include/dai/factor.h"
74 %extend dai::TFactor<dai::Real> {
75 inline dai::Real __getitem__(int i) const {return (*self).get(i);} /* for python */
76 inline void __setitem__(int i,dai::Real d) {(*self).set(i,d);} /* for python */
77 inline dai::Real __paren__(int i) const {return (*self).get(i);} /* for octave */
78 inline void __paren_asgn__(int i,dai::Real d) {(*self).set(i,d);} /* for octave */
79 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
80 inline std::string __str() const { return (*self).toString(); } /* for octave */
81 };
82 %template(Factor) dai::TFactor<dai::Real>;
83 %inline %{
84 typedef std::vector<dai::Factor> VecFactor;
85 typedef std::vector<VecFactor> VecVecFactor;
86 %}
87 %template(VecFactor) std::vector<dai::Factor>;
88 %template(VecVecFactor) std::vector<VecFactor>;
89
90 // ************************************************************************************************
91 %ignore operator<<(std::ostream&, const GraphAL&);
92 %rename(toInt) dai::Neighbor::operator size_t() const;
93 %include "../include/dai/graph.h"
94 %extend dai::GraphAL {
95 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
96 inline std::string __str() const { return (*self).toString(); } /* for octave */
97 }
98
99 // ************************************************************************************************
100 %ignore operator<<(std::ostream&, const BipartiteGraph&);
101 %include "../include/dai/bipgraph.h"
102 %extend dai::BipartiteGraph {
103 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
104 inline std::string __str() const { return (*self).toString(); } /* for octave */
105 }
106
107 // ************************************************************************************************
108 %ignore operator<<(std::ostream&, const FactorGraph&);
109 %ignore operator>>(std::istream&,FactorGraph&);
110 %include "../include/dai/factorgraph.h"
111 %extend dai::FactorGraph {
112 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
113 inline std::string __str() const { return (*self).toString(); } /* for octave */
114 inline void printDot(const std::string& fname) const {
115 std::ofstream o(fname.c_str(), std::ofstream::out);
116 self->printDot(o);
117 o.close();
118 }
119 }
120
121 // ************************************************************************************************
122 %ignore operator<<(std::ostream&, const RegionGraph&);
123 %include "../include/dai/regiongraph.h"
124 %extend dai::RegionGraph {
125 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
126 inline std::string __str() const { return (*self).toString(); } /* for octave */
127 }
128
129 // ************************************************************************************************
130 //%ignore operator<<(std::ostream&, const CobwebGraph&);
131 //%include "../include/dai/cobwebgraph.h"
132 //%extend dai::CobwebGraph {
133 // inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
134 // inline std::string __str() const { return (*self).toString(); } /* for octave */
135 //}
136 //TODO fix problems with CobwebGraph
137
138 // ************************************************************************************************
139 %ignore operator<<(std::ostream&, const PropertySet&);
140 %ignore operator>>(std::istream&,PropertySet&);
141 %include "../include/dai/properties.h"
142 %extend dai::PropertySet {
143 inline void __setitem__(char *name, char *val) {
144 self->set(std::string(name), std::string(val));
145 }
146 inline const char* __str__() const { return (*self).toString().c_str(); } /* for python */
147 inline std::string __str() const { return (*self).toString(); } /* for octave */
148 }
149
150 // ************************************************************************************************
151 %ignore dai::IndexFor::operator++;
152 %rename(toInt) dai::IndexFor::operator size_t() const;
153 %ignore dai::Permute::operator[];
154 %ignore dai::multifor::operator++;
155 %ignore dai::multifor::operator[];
156 %rename(toInt) dai::multifor::operator size_t() const;
157 %ignore dai::State::operator++;
158 %rename(toInt) dai::State::operator size_t() const;
159 %ignore dai::State::operator const std::map<Var,size_t>&;
160 %include "../include/dai/index.h"
161 %extend dai::IndexFor {
162 inline void next() { return (*self)++; }
163 };
164 %extend dai::Permute {
165 inline size_t __getitem__(int i) const {return (*self)[i];} /* for python */
166 inline size_t __paren__(int i) const {return (*self)[i];} /* for octave */
167 };
168 %extend dai::multifor {
169 inline void next() { return (*self)++; }
170 inline size_t __getitem__(int i) const {return (*self)[i];} /* for python */
171 inline size_t __paren__(int i) const {return (*self)[i];} /* for octave */
172 };
173 %extend dai::State {
174 inline void next() { return (*self)++; }
175 };
176
177 // ************************************************************************************************
178 %include "../include/dai/daialg.h"
179 //TODO: why do the following lines not work?
180 //%template(DAIAlgFG) dai::DAIAlg<dai::FactorGraph>;
181 //%template(DAIAlgRG) dai::DAIAlg<dai::RegionGraph>;
182 //%template(DAIAlgCG) dai::DAIAlg<dai::CobwebGraph>;
183
184 // ************************************************************************************************
185 %include "../include/dai/alldai.h"
186
187 // ************************************************************************************************
188 %ignore dai::BP::operator=;
189 %include "../include/dai/bp.h"
190
191 // ************************************************************************************************
192 %include "../include/dai/fbp.h"
193
194 // ************************************************************************************************
195 %include "../include/dai/trwbp.h"
196
197 // ************************************************************************************************
198 %include "../include/dai/mf.h"
199
200 // ************************************************************************************************
201 %include "../include/dai/hak.h"
202
203 // ************************************************************************************************
204 %include "../include/dai/lc.h"
205
206 // ************************************************************************************************
207 %include "../include/dai/jtree.h"
208
209 // ************************************************************************************************
210 %ignore dai::TreeEP::operator=;
211 %include "../include/dai/treeep.h"
212
213 // ************************************************************************************************
214 %include "../include/dai/mr.h"
215
216 // ************************************************************************************************
217 %include "../include/dai/gibbs.h"
218
219 // ************************************************************************************************
220 %include "../include/dai/cbp.h"
221
222 // ************************************************************************************************
223 %include "../include/dai/decmap.h"
224
225 // ************************************************************************************************
226 %include "../include/dai/glc.h"