-
Notifications
You must be signed in to change notification settings - Fork 0
/
csw.i
289 lines (245 loc) · 9.93 KB
/
csw.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
%module csw
%include "std_string.i" //gets exceptions.i
using namespace std;
%exception {
try {
$action;
} catch( ExCLError & e) {
PyErr_SetObject( PyExc_RuntimeError, explanation_list( &e ));
return 0;
}
}
%{
#include "cassowary/Variable.h"
#include "cassowary/SimplexSolver.h"
#include "cassowary/LinearEquation.h"
#include "cassowary/LinearInequality.h"
#include "cassowary/Errors.h"
#include "cassowary/EditConstraint.h"
#include "cassowary/StayConstraint.h"
#ifdef CL_BUILD_FD_SOLVER
#include "cassowary/FDBinaryOneWayConstraint.h"
#include "cassowary/FDSolver.h"
#endif
#include "explan.cpp"
#include <sstream>
%}
#ifdef TRACE_NEWDEL
%inline %{
extern int trace_newdel;
%}
#endif
#ifdef TRACE_MALLOC
%inline %{
extern int trace_malloc;
%}
#endif
#define REFCOUNT_DEF
%ignore incref;
%ignore decref;
%ignore ReverseInequality;
%ignore StrCnRelation;
%ignore PrintOn;
%ignore PrintTo;
%ignore PrintInternalInfo;
%ignore PrintOnVerbose;
%ignore SimplexSolver::SetResolveCallback;
%ignore SimplexSolver::SetCnSatCallback;
%ignore SimplexSolver::Resolve( const vector<Number> & );
%ignore SimplexSolver::Resolve( Number x, Number y);
%ignore SimplexSolver::AddLowerBound;
%ignore SimplexSolver::AddUpperBound;
%ignore SimplexSolver::AddBounds;
%ignore SimplexSolver::AddPointStay;
%ignore SimplexSolver::AddPointStays;
%ignore *::operator =;
%ignore RefCountPtr::RefCountPtr;
%ignore RefCountPtr::ptr;
%ignore RefCountPtr::__deref__;
%include "cassowary/my/refcntp.h"
%ignore Constraint;
%template( P_Constraint ) RefCountPtr<Constraint> ;
#define P_Constraint RefCountPtr<Constraint>
%ignore P_AbstractVariable;
%ignore AbstractVariable;
%ignore EditOrStayConstraint;
%ignore StayConstraint;
%include "cassowary/Cassowary.h"
%include "cassowary/Typedefs.h"
%ignore Variable::operator ->;
%ignore Variable::Variable( AbstractVariable *);
%ignore Variable::Variable( AbstractVariable &);
%ignore Variable::Variable( P_AbstractVariable);
%ignore Variable::get_pclv;
%ignore Variable::SetVarMap;
%ignore Variable::VarMap;
%ignore Variable::pmapStrPclv;
%ignore clvNil;
%ignore operator <;
%ignore operator <<;
%ignore operator >>;
%ignore operator +;
%ignore operator -;
%ignore operator *;
%ignore operator /;
%ignore operator ==;
%include "cassowary/Variable.h"
%include "cassowary/LinearExpression.h"
//%include "cassowary/LinearExpression_fwd.h"
#define GLE GenericLinearExpression<Number>
%template( LinearExpression ) GLE;
typedef GLE* P_LinearExpression ;
#define LinearExpression GLE
%include "cassowary/Strength.h"
%include "cassowary/Constraint.h"
%include "cassowary/Constraint_P.h"
%include "cassowary/Solver.h"
%ignore Tableau;
%include "cassowary/SimplexSolver.h"
#ifdef CL_BUILD_FD_SOLVER
%include "cassowary/FDBinaryOneWayConstraint.h"
%include "cassowary/FDSolver.h"
#endif
#define DEF__str__(x) string __str__() const { ostringstream ss; (x)->PrintOn(ss); return ss.str(); } //ss << ends;
%extend GLE { //LinearExpression
DEF__str__(self)
//epxr+var is expr; expr+const is expr
GLE operator+( Variable e2 ) const { return GLE( *self). Plus(e2); }
GLE operator-( Variable e2 ) const { return GLE( *self). Minus(e2); }
GLE operator*( Variable e2 ) const { return GLE( *self). Times(e2); }
GLE operator/( Variable e2 ) const { return GLE( *self). Divide(e2); }
GLE operator+( Number e2 ) const { return GLE( *self). Plus(e2); }
GLE operator-( Number e2 ) const { return GLE( *self). Minus(e2); }
GLE operator*( Number e2 ) const { return GLE( *self). Times(e2); }
GLE operator/( Number e2 ) const { return GLE( *self). Divide(e2); }
bool operator == (const GLE &e2) const {
return (*self).Constant() == e2.Constant() && (*self).Terms() == e2.Terms(); }
bool operator != (const GLE &e2) const {
return (*self).Constant() != e2.Constant() || (*self).Terms() != e2.Terms(); }
%pythoncode %{
def __radd__(self,e2): return self.__add__(e2)
def __rsub__(self,e2): return LinearExpression(e2).__sub__(self)
#Expr(e2)-self dies : cant get __sub__ and loops forever for new-type class-object
# and is slower anyway
def __rmul__(self,e2): return self.__mul__(e2)
def __rdiv__(self,e2): return LinearExpression(e2).__div__(self)
%}
/*
PyObject * getTerms() const {
PyObject * m = PyList_New();
GenericLinearExpression::VarToCoeffMap::const_iterator it = self->Terms().begin();
while (it != self->Terms().end()) {
PyObject *p = PyTuple_New(2);
PyTuple_SetItem( p, 0, SWIG_NewPointerObj( (void *) &(*it).first, SWIGTYPE_p_Variable, 1) );
PyTuple_SetItem( p, 1, PyFloat_FromDouble( (*it).second) );
PyList_Append( m, p);
++it;
}
return m;
}
*/
};
%extend Strength {
DEF__str__(self)
}
%extend RefCountPtr<Constraint> { //P_Constraint
DEF__str__(*self)
};
%extend Variable {
DEF__str__(self)
//var+var is expr; var+const is expr
LinearExpression operator+( const LinearExpression & e2 ) const { return LinearExpression( *self). Plus(e2); }
LinearExpression operator-( const LinearExpression & e2 ) const { return LinearExpression( *self). Minus(e2); }
LinearExpression operator*( const LinearExpression & e2 ) const { return LinearExpression( *self). Times(e2); }
LinearExpression operator/( const LinearExpression & e2 ) const { return LinearExpression( *self). Divide(e2); }
LinearExpression operator+( Variable e2 ) const { return LinearExpression( *self). Plus(e2); }
LinearExpression operator-( Variable e2 ) const { return LinearExpression( *self). Minus(e2); }
LinearExpression operator*( Variable e2 ) const { return LinearExpression( *self). Times(e2); }
LinearExpression operator/( Variable e2 ) const { return LinearExpression( *self). Divide(e2); }
LinearExpression operator+( Number e2 ) const { return LinearExpression( *self). Plus(e2); }
LinearExpression operator-( Number e2 ) const { return LinearExpression( *self). Minus(e2); }
LinearExpression operator*( Number e2 ) const { return LinearExpression( *self). Times(e2); }
LinearExpression operator/( Number e2 ) const { return LinearExpression( *self). Divide(e2); }
bool operator==( Number e2 ) const { return self->Value() == e2; }
bool operator!=( Number e2 ) const { return self->Value() != e2; }
%pythoncode %{
def __radd__(self,e2): return self.__add__(e2)
def __rsub__(self,e2): return LinearExpression(e2).__sub__(self)
#Expr(e2)-self dies : cant get __sub__ and loops forever for new-type class-object
# and is slower anyway
def __rmul__(self,e2): return self.__mul__(e2)
def __rdiv__(self,e2): return LinearExpression(e2).__div__(self)
%}
};
%rename( LinearEquation) newLinearEquation;
%rename( LinearInequality) newLinearInequality;
%rename( StayConstraint) newStayConstraint;
%inline %{
#define PQ1(what,x) P_Constraint new##what( x a, \
const Strength & strength = sRequired(), double weight = 1.0) \
{ return new what( a,strength, weight); }
#define PQ2(what,x,y) P_Constraint new##what( x a,y b, \
const Strength & strength = sRequired(), double weight = 1.0) \
{ return new what( LinearExpression(a),(b),strength, weight); }
#define PQ3(what,x,y,z) P_Constraint new##what( x a,y b, z c, \
const Strength & strength = sRequired(), double weight = 1.0) \
{ return new what( LinearExpression(a),b,LinearExpression(c),strength, weight); }
#define PEQ1(x) PQ1(LinearEquation,x)
#define PEQ2(x,y) PQ2(LinearEquation,x,y)
#define PNE1(x) PQ1(LinearInequality,x)
#define PNE2(x,y) PQ3(LinearInequality,x, CnRelation, y)
PEQ1( const LinearExpression & )
PEQ2( const Variable & , const LinearExpression & )
PEQ2( const LinearExpression & , const Variable & )
PEQ2( const LinearExpression & , const LinearExpression & )
//AMBIGUOUS in c++
//var is expr; const is expr
PEQ1( Number )
PEQ1( const Variable & )
PEQ2( Number , Number ) //amb
PEQ2( const Variable & , const Variable & ) //amb
PEQ2( const Variable & , Number )
PEQ2( const LinearExpression &, Number ) //amb
PEQ2( Number , const Variable & )
PEQ2( Number , const LinearExpression & ) //amb
#if 10
PNE1( const LinearExpression & )
PNE2( const LinearExpression &, const LinearExpression & )
//AMBIGUOUS in c++
PNE2( const LinearExpression &, const Variable & )
PNE2( const Variable &, const LinearExpression & )
PNE2( const Variable &, const Variable & )
//var is expr; const is expr
PNE1( const Variable & )
PNE2( const Variable & , Number )
PNE2( const LinearExpression &, Number )
PNE2( Number , const Variable & )
PNE2( Number , const LinearExpression & )
#endif
PQ1( StayConstraint, const Variable &)
%}
#if 10
%extend SimplexSolver {
DEF__str__(self)
/*
SimplexSolver & AddLowerBound( Variable v, Variable lower) {
return self->AddConstraint( new LinearInequality(LinearExpression(v - lower)) ); }
SimplexSolver & AddUpperBound( Variable v, Variable upper) {
return self->AddConstraint( new LinearInequality(LinearExpression(upper - v)) ); }
SimplexSolver & AddBounds( Variable v, Variable lower, Variable upper) {
self->AddConstraint( new LinearInequality(LinearExpression(v - lower)) );
return self->AddConstraint( new LinearInequality(LinearExpression(upper - v)) ); }
SimplexSolver & AddBounds( Variable v, Number lower, Variable upper) {
self->AddLowerBound(v,lower);
return self->AddConstraint( new LinearInequality(LinearExpression(upper - v)) ); }
SimplexSolver & AddBounds( Variable v, Variable lower, Number upper) {
self->AddConstraint( new LinearInequality(LinearExpression(v - lower)) );
return self->AddUpperBound(v,upper); }
*/
};
#endif
#if 0
%extend Constraint {
bool operator==( Constraint * c ) const { return self == c; }
};
#endif