-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcineq2_min_func.c
More file actions
460 lines (425 loc) · 13.3 KB
/
Copy pathcineq2_min_func.c
File metadata and controls
460 lines (425 loc) · 13.3 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
/* This file was automatically generated by CasADi.
The CasADi copyright holders make no ownership claim of its contents. */
#ifdef __cplusplus
extern "C" {
#endif
/* How to prefix internal symbols */
#ifdef CASADI_CODEGEN_PREFIX
#define CASADI_NAMESPACE_CONCAT(NS, ID) _CASADI_NAMESPACE_CONCAT(NS, ID)
#define _CASADI_NAMESPACE_CONCAT(NS, ID) NS ## ID
#define CASADI_PREFIX(ID) CASADI_NAMESPACE_CONCAT(CODEGEN_PREFIX, ID)
#else
#define CASADI_PREFIX(ID) cineq2_min_func_ ## ID
#endif
#include <math.h>
#include <stdio.h>
#include <string.h>
#ifdef MATLAB_MEX_FILE
#include <mex.h>
#endif
#ifndef casadi_real
#define casadi_real double
#endif
#ifndef casadi_int
#define casadi_int long long int
#endif
/* Add prefix to internal symbols */
#define casadi_f0 CASADI_PREFIX(f0)
#define casadi_fill CASADI_PREFIX(fill)
#define casadi_from_mex CASADI_PREFIX(from_mex)
#define casadi_s0 CASADI_PREFIX(s0)
#define casadi_s1 CASADI_PREFIX(s1)
#define casadi_s2 CASADI_PREFIX(s2)
#define casadi_to_mex CASADI_PREFIX(to_mex)
/* Symbol visibility in DLLs */
#ifndef CASADI_SYMBOL_EXPORT
#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
#if defined(STATIC_LINKED)
#define CASADI_SYMBOL_EXPORT
#else
#define CASADI_SYMBOL_EXPORT __declspec(dllexport)
#endif
#elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
#define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default")))
#else
#define CASADI_SYMBOL_EXPORT
#endif
#endif
void casadi_fill(casadi_real* x, casadi_int n, casadi_real alpha) {
casadi_int i;
if (x) {
for (i=0; i<n; ++i) *x++ = alpha;
}
}
#ifdef MATLAB_MEX_FILE
casadi_real* casadi_from_mex(const mxArray* p, casadi_real* y, const casadi_int* sp, casadi_real* w) {
casadi_int nrow, ncol, is_sparse, c, k, p_nrow, p_ncol;
const casadi_int *colind, *row;
mwIndex *Jc, *Ir;
const double* p_data;
if (!mxIsDouble(p) || mxGetNumberOfDimensions(p)!=2)
mexErrMsgIdAndTxt("Casadi:RuntimeError",
"\"from_mex\" failed: Not a two-dimensional matrix of double precision.");
nrow = *sp++;
ncol = *sp++;
colind = sp;
row = sp+ncol+1;
p_nrow = mxGetM(p);
p_ncol = mxGetN(p);
is_sparse = mxIsSparse(p);
Jc = 0;
Ir = 0;
if (is_sparse) {
Jc = mxGetJc(p);
Ir = mxGetIr(p);
}
p_data = (const double*)mxGetData(p);
if (p_nrow==1 && p_ncol==1) {
casadi_int nnz;
double v = is_sparse && Jc[1]==0 ? 0 : *p_data;
nnz = sp[ncol];
casadi_fill(y, nnz, v);
} else {
casadi_int tr = 0;
if (nrow!=p_nrow || ncol!=p_ncol) {
tr = nrow==p_ncol && ncol==p_nrow && (nrow==1 || ncol==1);
if (!tr) mexErrMsgIdAndTxt("Casadi:RuntimeError",
"\"from_mex\" failed: Dimension mismatch. "
"Expected %d-by-%d, got %d-by-%d instead.",
nrow, ncol, p_nrow, p_ncol);
}
if (is_sparse) {
if (tr) {
for (c=0; c<ncol; ++c)
for (k=colind[c]; k<colind[c+1]; ++k) w[row[k]+c*nrow]=0;
for (c=0; c<p_ncol; ++c)
for (k=Jc[c]; k<(casadi_int) Jc[c+1]; ++k) w[c+Ir[k]*p_ncol] = p_data[k];
for (c=0; c<ncol; ++c)
for (k=colind[c]; k<colind[c+1]; ++k) y[k] = w[row[k]+c*nrow];
} else {
for (c=0; c<ncol; ++c) {
for (k=colind[c]; k<colind[c+1]; ++k) w[row[k]]=0;
for (k=Jc[c]; k<(casadi_int) Jc[c+1]; ++k) w[Ir[k]]=p_data[k];
for (k=colind[c]; k<colind[c+1]; ++k) y[k]=w[row[k]];
}
}
} else {
for (c=0; c<ncol; ++c) {
for (k=colind[c]; k<colind[c+1]; ++k) {
y[k] = p_data[row[k]+c*nrow];
}
}
}
}
return y;
}
#endif
#define casadi_to_double(x) ((double) x)
#ifdef MATLAB_MEX_FILE
mxArray* casadi_to_mex(const casadi_int* sp, const casadi_real* x) {
casadi_int nrow, ncol, c, k;
#ifndef CASADI_MEX_NO_SPARSE
casadi_int nnz;
#endif
const casadi_int *colind, *row;
mxArray *p;
double *d;
#ifndef CASADI_MEX_NO_SPARSE
casadi_int i;
mwIndex *j;
#endif /* CASADI_MEX_NO_SPARSE */
nrow = *sp++;
ncol = *sp++;
colind = sp;
row = sp+ncol+1;
#ifndef CASADI_MEX_NO_SPARSE
nnz = sp[ncol];
if (nnz!=nrow*ncol) {
p = mxCreateSparse(nrow, ncol, nnz, mxREAL);
for (i=0, j=mxGetJc(p); i<=ncol; ++i) *j++ = *colind++;
for (i=0, j=mxGetIr(p); i<nnz; ++i) *j++ = *row++;
if (x) {
d = (double*)mxGetData(p);
for (i=0; i<nnz; ++i) *d++ = casadi_to_double(*x++);
}
return p;
}
#endif /* CASADI_MEX_NO_SPARSE */
p = mxCreateDoubleMatrix(nrow, ncol, mxREAL);
if (x) {
d = (double*)mxGetData(p);
for (c=0; c<ncol; ++c) {
for (k=colind[c]; k<colind[c+1]; ++k) {
d[row[k]+c*nrow] = casadi_to_double(*x++);
}
}
}
return p;
}
#endif
#ifndef CASADI_PRINTF
#ifdef MATLAB_MEX_FILE
#define CASADI_PRINTF mexPrintf
#else
#define CASADI_PRINTF printf
#endif
#endif
static const casadi_int casadi_s0[184] = {180, 1, 0, 180, 0, 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};
static const casadi_int casadi_s1[5] = {1, 1, 0, 1, 0};
static const casadi_int casadi_s2[44] = {40, 1, 0, 40, 0, 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};
/* cineq2_min_func:(i0[180],i1,i2)->(o0[40]) */
static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem) {
casadi_real a0, a1, a2;
a0=arg[1]? arg[1][0] : 0;
a1=arg[0]? arg[0][2] : 0;
a1=(a0-a1);
if (res[0]!=0) res[0][0]=a1;
a1=arg[2]? arg[2][0] : 0;
a2=arg[0]? arg[0][3] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][1]=a2;
a2=arg[0]? arg[0][11] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][2]=a2;
a2=arg[0]? arg[0][12] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][3]=a2;
a2=arg[0]? arg[0][20] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][4]=a2;
a2=arg[0]? arg[0][21] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][5]=a2;
a2=arg[0]? arg[0][29] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][6]=a2;
a2=arg[0]? arg[0][30] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][7]=a2;
a2=arg[0]? arg[0][38] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][8]=a2;
a2=arg[0]? arg[0][39] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][9]=a2;
a2=arg[0]? arg[0][47] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][10]=a2;
a2=arg[0]? arg[0][48] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][11]=a2;
a2=arg[0]? arg[0][56] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][12]=a2;
a2=arg[0]? arg[0][57] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][13]=a2;
a2=arg[0]? arg[0][65] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][14]=a2;
a2=arg[0]? arg[0][66] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][15]=a2;
a2=arg[0]? arg[0][74] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][16]=a2;
a2=arg[0]? arg[0][75] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][17]=a2;
a2=arg[0]? arg[0][83] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][18]=a2;
a2=arg[0]? arg[0][84] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][19]=a2;
a2=arg[0]? arg[0][92] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][20]=a2;
a2=arg[0]? arg[0][93] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][21]=a2;
a2=arg[0]? arg[0][101] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][22]=a2;
a2=arg[0]? arg[0][102] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][23]=a2;
a2=arg[0]? arg[0][110] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][24]=a2;
a2=arg[0]? arg[0][111] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][25]=a2;
a2=arg[0]? arg[0][119] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][26]=a2;
a2=arg[0]? arg[0][120] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][27]=a2;
a2=arg[0]? arg[0][128] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][28]=a2;
a2=arg[0]? arg[0][129] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][29]=a2;
a2=arg[0]? arg[0][137] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][30]=a2;
a2=arg[0]? arg[0][138] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][31]=a2;
a2=arg[0]? arg[0][146] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][32]=a2;
a2=arg[0]? arg[0][147] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][33]=a2;
a2=arg[0]? arg[0][155] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][34]=a2;
a2=arg[0]? arg[0][156] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][35]=a2;
a2=arg[0]? arg[0][164] : 0;
a2=(a0-a2);
if (res[0]!=0) res[0][36]=a2;
a2=arg[0]? arg[0][165] : 0;
a2=(a1-a2);
if (res[0]!=0) res[0][37]=a2;
a2=arg[0]? arg[0][173] : 0;
a0=(a0-a2);
if (res[0]!=0) res[0][38]=a0;
a0=arg[0]? arg[0][174] : 0;
a1=(a1-a0);
if (res[0]!=0) res[0][39]=a1;
return 0;
}
CASADI_SYMBOL_EXPORT int cineq2_min_func(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem){
return casadi_f0(arg, res, iw, w, mem);
}
CASADI_SYMBOL_EXPORT int cineq2_min_func_alloc_mem(void) {
return 0;
}
CASADI_SYMBOL_EXPORT int cineq2_min_func_init_mem(int mem) {
return 0;
}
CASADI_SYMBOL_EXPORT void cineq2_min_func_free_mem(int mem) {
}
CASADI_SYMBOL_EXPORT int cineq2_min_func_checkout(void) {
return 0;
}
CASADI_SYMBOL_EXPORT void cineq2_min_func_release(int mem) {
}
CASADI_SYMBOL_EXPORT void cineq2_min_func_incref(void) {
}
CASADI_SYMBOL_EXPORT void cineq2_min_func_decref(void) {
}
CASADI_SYMBOL_EXPORT casadi_int cineq2_min_func_n_in(void) { return 3;}
CASADI_SYMBOL_EXPORT casadi_int cineq2_min_func_n_out(void) { return 1;}
CASADI_SYMBOL_EXPORT casadi_real cineq2_min_func_default_in(casadi_int i){
switch (i) {
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const char* cineq2_min_func_name_in(casadi_int i){
switch (i) {
case 0: return "i0";
case 1: return "i1";
case 2: return "i2";
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const char* cineq2_min_func_name_out(casadi_int i){
switch (i) {
case 0: return "o0";
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const casadi_int* cineq2_min_func_sparsity_in(casadi_int i) {
switch (i) {
case 0: return casadi_s0;
case 1: return casadi_s1;
case 2: return casadi_s1;
default: return 0;
}
}
CASADI_SYMBOL_EXPORT const casadi_int* cineq2_min_func_sparsity_out(casadi_int i) {
switch (i) {
case 0: return casadi_s2;
default: return 0;
}
}
CASADI_SYMBOL_EXPORT int cineq2_min_func_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) {
if (sz_arg) *sz_arg = 3;
if (sz_res) *sz_res = 1;
if (sz_iw) *sz_iw = 0;
if (sz_w) *sz_w = 0;
return 0;
}
#ifdef MATLAB_MEX_FILE
void mex_cineq2_min_func(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {
casadi_int i;
casadi_real w[402];
casadi_int *iw = 0;
const casadi_real* arg[3] = {0};
casadi_real* res[1] = {0};
if (argc>3) mexErrMsgIdAndTxt("Casadi:RuntimeError","Evaluation of \"cineq2_min_func\" failed. Too many input arguments (%d, max 3)", argc);
if (resc>1) mexErrMsgIdAndTxt("Casadi:RuntimeError","Evaluation of \"cineq2_min_func\" failed. Too many output arguments (%d, max 1)", resc);
if (--argc>=0) arg[0] = casadi_from_mex(argv[0], w, casadi_s0, w+222);
if (--argc>=0) arg[1] = casadi_from_mex(argv[1], w+180, casadi_s1, w+222);
if (--argc>=0) arg[2] = casadi_from_mex(argv[2], w+181, casadi_s1, w+222);
--resc;
res[0] = w+182;
i = cineq2_min_func(arg, res, iw, w+222, 0);
if (i) mexErrMsgIdAndTxt("Casadi:RuntimeError","Evaluation of \"cineq2_min_func\" failed.");
if (res[0]) resv[0] = casadi_to_mex(casadi_s2, res[0]);
}
#endif
casadi_int main_cineq2_min_func(casadi_int argc, char* argv[]) {
casadi_int j;
casadi_real* a;
const casadi_real* r;
casadi_int flag;
casadi_int *iw = 0;
casadi_real w[225];
const casadi_real* arg[3];
casadi_real* res[1];
arg[0] = w+0;
arg[1] = w+180;
arg[2] = w+181;
res[0] = w+182;
a = w;
for (j=0; j<182; ++j) if (scanf("%lg", a++)<=0) return 2;
flag = cineq2_min_func(arg, res, iw, w+222, 0);
if (flag) return flag;
r = w+182;
for (j=0; j<40; ++j) CASADI_PRINTF("%g ", *r++);
CASADI_PRINTF("\n");
return 0;
}
#ifdef MATLAB_MEX_FILE
void mexFunction(int resc, mxArray *resv[], int argc, const mxArray *argv[]) {
char buf[16];
int buf_ok = argc > 0 && !mxGetString(*argv, buf, sizeof(buf));
if (!buf_ok) {
mex_cineq2_min_func(resc, resv, argc, argv);
return;
} else if (strcmp(buf, "cineq2_min_func")==0) {
mex_cineq2_min_func(resc, resv, argc-1, argv+1);
return;
}
mexErrMsgTxt("First input should be a command string. Possible values: 'cineq2_min_func'");
}
#endif
int main(int argc, char* argv[]) {
if (argc<2) {
/* name error */
} else if (strcmp(argv[1], "cineq2_min_func")==0) {
return main_cineq2_min_func(argc-2, argv+2);
}
fprintf(stderr, "First input should be a command string. Possible values: 'cineq2_min_func'\nNote: you may use function.generate_input to create a command string.\n");
return 1;
}
#ifdef __cplusplus
} /* extern "C" */
#endif