qpOASES-3.2.0/interfaces/scilab/qpOASESinterface.c
Go to the documentation of this file.
1 /*
2  * This file is part of qpOASES.
3  *
4  * qpOASES -- An Implementation of the Online Active Set Strategy.
5  * Copyright (C) 2007-2015 by Hans Joachim Ferreau, Andreas Potschka,
6  * Christian Kirches et al. All rights reserved.
7  *
8  * qpOASES is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * qpOASES is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with qpOASES; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  */
23 
24 
37 #include <stdio.h>
38 #include <string.h>
39 
40 #include <scilab/stack-c.h>
41 #include <scilab/Scierror.h>
42 
43 #include "../c/qpOASES_wrapper.h"
44 
45 
46 
47 extern int interface_qpOASES( char* fname );
48 
49 extern int interface_QProblem_init( char* fname );
50 extern int interface_QProblemB_init( char* fname );
51 extern int interface_SQProblem_init( char* fname );
52 
53 extern int interface_QProblem_hotstart( char* fname );
54 extern int interface_QProblemB_hotstart( char* fname );
55 extern int interface_SQProblem_hotstart( char* fname );
56 
57 extern int interface_QProblem_cleanup( char* fname );
58 extern int interface_QProblemB_cleanup( char* fname );
59 extern int interface_SQProblem_cleanup( char* fname );
60 
61 
62 typedef int (*gate_function) ( char* );
63 extern int sci_gateway( char* name, gate_function f );
64 extern int C2F(qpOASESgateway)();
65 
66 
67 /* forward declaration of C++ routines */
69  int_t *nV, int_t* nC, int_t* nWSR,
70  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
71  );
72 
74  int_t *nV, int_t* nC, int_t* nWSR,
75  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
76  );
78  int_t *nV, int_t* nWSR,
79  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
80  );
82  int_t *nV, int_t* nC, int_t* nWSR,
83  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
84  );
85 
87  int_t* nWSR,
88  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
89  );
91  int_t* nWSR,
92  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
93  );
95  int_t* nWSR,
96  real_t* x, real_t* obj, int_t* status, int_t* nWSRout, real_t* y
97  );
98 
99 void sci_QProblem_cleanup( );
100 void sci_QProblemB_cleanup( );
101 void sci_SQProblem_cleanup( );
102 
103 
104 /* global variables containing dimensions of matrices
105  * (also used to check whether qpOASES object were initialised) */
106 static int_t qp_rowsH = -1;
107 static int_t qp_rowsA = -1;
108 static int_t qpb_rowsH = -1;
109 static int_t sqp_rowsH = -1;
110 static int_t sqp_rowsA = -1;
111 
112 
113 /*
114  * i n t e r f a c e _ q p O A S E S
115  */
116 int interface_qpOASES( char* fname )
117 {
118  int_t H, H_rows, H_cols;
119  int_t g, g_rows, g_cols;
120  int_t A, A_rows, A_cols;
121  int_t lb, lb_rows, lb_cols;
122  int_t ub, ub_rows, ub_cols;
123  int_t lbA, lbA_rows, lbA_cols;
124  int_t ubA, ubA_rows, ubA_cols;
125  int_t nWSR, nWSR_rows, nWSR_cols;
126 
127  int_t x, obj, status, nWSRout, y;
128 
129 
130  int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
131 
132  CheckRhs( minrhs,maxrhs );
133  CheckLhs( minlhs,maxlhs );
134 
135 
136  /* check dimensions */
137  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
138  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
139  {
140  Scierror( 111,"ERROR (qpOASES): Dimension mismatch!\n" );
141  return 0;
142  }
143 
144  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
145  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
146  {
147  Scierror( 112,"ERROR (qpOASES): Dimension mismatch!\n" );
148  return 0;
149  }
150 
151  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
152  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
153  {
154  Scierror( 113,"ERROR (qpOASES): Dimension mismatch!\n" );
155  return 0;
156  }
157 
158  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
159  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
160  {
161  Scierror( 114,"ERROR (qpOASES): Dimension mismatch!\n" );
162  return 0;
163  }
164 
165  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
166  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
167  {
168  Scierror( 115,"ERROR (qpOASES): Dimension mismatch!\n" );
169  return 0;
170  }
171 
172  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
173  if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) )
174  {
175  Scierror( 116,"ERROR (qpOASES): Dimension mismatch!\n" );
176  return 0;
177  }
178 
179  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
180  if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) )
181  {
182  Scierror( 117,"ERROR (qpOASES): Dimension mismatch!\n" );
183  return 0;
184  }
185 
186  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
187  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
188  {
189  Scierror( 118,"ERROR (qpOASES): Dimension mismatch!\n" );
190  return 0;
191  }
192 
193 
194  y_size = H_rows + A_rows;
195 
196  CreateVar( 9,"d", &H_rows,&one,&x );
197  CreateVar( 10,"d", &one,&one,&obj );
198  CreateVar( 11,"i", &one,&one,&status );
199  CreateVar( 12,"i", &one,&one,&nWSRout );
200  CreateVar( 13,"d", &y_size,&one,&y );
201 
202 
203  /* call interfaced qpOASES routines with appropriate arguments */
204  sci_qpOASES( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0,
205  &H_rows,&A_rows,istk(nWSR),
206  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
207  );
208 
209  LhsVar(1) = 9;
210  LhsVar(2) = 10;
211  LhsVar(3) = 11;
212  LhsVar(4) = 12;
213  LhsVar(5) = 13;
214 
215  return 0;
216 }
217 
218 
219 /*
220  * i n t e r f a c e _ Q P r o b l e m _ i n i t
221  */
222 int interface_QProblem_init( char* fname )
223 {
224  int_t H, H_rows, H_cols;
225  int_t g, g_rows, g_cols;
226  int_t A, A_rows, A_cols;
227  int_t lb, lb_rows, lb_cols;
228  int_t ub, ub_rows, ub_cols;
229  int_t lbA, lbA_rows, lbA_cols;
230  int_t ubA, ubA_rows, ubA_cols;
231  int_t nWSR, nWSR_rows, nWSR_cols;
232 
233  int_t x, obj, status, nWSRout, y;
234 
235 
236  int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
237 
238  CheckRhs( minrhs,maxrhs );
239  CheckLhs( minlhs,maxlhs );
240 
241 
242  /* check dimensions */
243  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
244  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
245  {
246  Scierror( 211,"ERROR (qpOASES): Dimension mismatch!\n" );
247  return 0;
248  }
249 
250  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
251  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
252  {
253  Scierror( 212,"ERROR (qpOASES): Dimension mismatch!\n" );
254  return 0;
255  }
256 
257  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
258  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
259  {
260  Scierror( 213,"ERROR (qpOASES): Dimension mismatch!\n" );
261  return 0;
262  }
263 
264  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
265  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
266  {
267  Scierror( 214,"ERROR (qpOASES): Dimension mismatch!\n" );
268  return 0;
269  }
270 
271  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
272  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
273  {
274  Scierror( 215,"ERROR (qpOASES): Dimension mismatch!\n" );
275  return 0;
276  }
277 
278  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
279  if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) )
280  {
281  Scierror( 216,"ERROR (qpOASES): Dimension mismatch!\n" );
282  return 0;
283  }
284 
285  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
286  if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) )
287  {
288  Scierror( 217,"ERROR (qpOASES): Dimension mismatch!\n" );
289  return 0;
290  }
291 
292  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
293  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
294  {
295  Scierror( 218,"ERROR (qpOASES): Dimension mismatch!\n" );
296  return 0;
297  }
298 
299 
300  y_size = H_rows + A_rows;
301 
302  CreateVar( 9,"d", &H_rows,&one,&x );
303  CreateVar( 10,"d", &one,&one,&obj );
304  CreateVar( 11,"i", &one,&one,&status );
305  CreateVar( 12,"i", &one,&one,&nWSRout );
306  CreateVar( 13,"d", &y_size,&one,&y );
307 
308 
309  qp_rowsH = H_rows;
310  qp_rowsA = A_rows;
311 
312 
313  /* call interfaced qpOASES routines with appropriate arguments */
314  sci_QProblem_init( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0,
315  &H_rows,&A_rows,istk(nWSR),
316  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
317  );
318 
319  LhsVar(1) = 9;
320  LhsVar(2) = 10;
321  LhsVar(3) = 11;
322  LhsVar(4) = 12;
323  LhsVar(5) = 13;
324 
325  return 0;
326 }
327 
328 
329 /*
330  * i n t e r f a c e _ Q P r o b l e m B _ i n i t
331  */
332 int interface_QProblemB_init( char* fname )
333 {
334  int_t H, H_rows, H_cols;
335  int_t g, g_rows, g_cols;
336  int_t lb, lb_rows, lb_cols;
337  int_t ub, ub_rows, ub_cols;
338  int_t nWSR, nWSR_rows, nWSR_cols;
339 
340  int_t x, obj, status, nWSRout, y;
341 
342 
343  int minlhs = 1, maxlhs = 5, minrhs = 5, maxrhs = 5, one = 1;
344 
345  CheckRhs( minrhs,maxrhs );
346  CheckLhs( minlhs,maxlhs );
347 
348 
349  /* check dimensions */
350  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
351  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
352  {
353  Scierror( 221,"ERROR (qpOASES): Dimension mismatch!\n" );
354  return 0;
355  }
356 
357  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
358  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
359  {
360  Scierror( 222,"ERROR (qpOASES): Dimension mismatch!\n" );
361  return 0;
362  }
363 
364  GetRhsVar( 3,"d", &lb_rows,&lb_cols,&lb);
365  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
366  {
367  Scierror( 223,"ERROR (qpOASES): Dimension mismatch!\n" );
368  return 0;
369  }
370 
371  GetRhsVar( 4,"d", &ub_rows,&ub_cols,&ub);
372  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
373  {
374  Scierror( 224,"ERROR (qpOASES): Dimension mismatch!\n" );
375  return 0;
376  }
377 
378  GetRhsVar( 5,"i", &nWSR_rows,&nWSR_cols,&nWSR);
379  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
380  {
381  Scierror( 225,"ERROR (qpOASES): Dimension mismatch!\n" );
382  return 0;
383  }
384 
385 
386  CreateVar( 9,"d", &H_rows,&one,&x );
387  CreateVar( 10,"d", &one,&one,&obj );
388  CreateVar( 11,"i", &one,&one,&status );
389  CreateVar( 12,"i", &one,&one,&nWSRout );
390  CreateVar( 13,"d", &H_rows,&one,&y );
391 
392 
393  qpb_rowsH = H_rows;
394 
395 
396  /* call interfaced qpOASES routines with appropriate arguments */
397  sci_QProblemB_init( stk(H),stk(g), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0,
398  &H_rows,istk(nWSR),
399  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
400  );
401 
402  LhsVar(1) = 9;
403  LhsVar(2) = 10;
404  LhsVar(3) = 11;
405  LhsVar(4) = 12;
406  LhsVar(5) = 13;
407 
408  return 0;
409 }
410 
411 
412 /*
413  * i n t e r f a c e _ S Q P r o b l e m _ i n i t
414  */
415 int interface_SQProblem_init( char* fname )
416 {
417  int_t H, H_rows, H_cols;
418  int_t g, g_rows, g_cols;
419  int_t A, A_rows, A_cols;
420  int_t lb, lb_rows, lb_cols;
421  int_t ub, ub_rows, ub_cols;
422  int_t lbA, lbA_rows, lbA_cols;
423  int_t ubA, ubA_rows, ubA_cols;
424  int_t nWSR, nWSR_rows, nWSR_cols;
425 
426  int_t x, obj, status, nWSRout, y;
427 
428 
429  int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
430 
431  CheckRhs( minrhs,maxrhs );
432  CheckLhs( minlhs,maxlhs );
433 
434 
435  /* check dimensions */
436  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
437  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
438  {
439  Scierror( 231,"ERROR (qpOASES): Dimension mismatch!\n" );
440  return 0;
441  }
442 
443  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
444  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
445  {
446  Scierror( 232,"ERROR (qpOASES): Dimension mismatch!\n" );
447  return 0;
448  }
449 
450  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
451  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
452  {
453  Scierror( 233,"ERROR (qpOASES): Dimension mismatch!\n" );
454  return 0;
455  }
456 
457  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb );
458  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
459  {
460  Scierror( 234,"ERROR (qpOASES): Dimension mismatch!\n" );
461  return 0;
462  }
463 
464  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub );
465  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
466  {
467  Scierror( 235,"ERROR (qpOASES): Dimension mismatch!\n" );
468  return 0;
469  }
470 
471  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA );
472  if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) )
473  {
474  Scierror( 236,"ERROR (qpOASES): Dimension mismatch!\n" );
475  return 0;
476  }
477 
478  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA );
479  if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) )
480  {
481  Scierror( 237,"ERROR (qpOASES): Dimension mismatch!\n" );
482  return 0;
483  }
484 
485  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR) ;
486  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
487  {
488  Scierror( 238,"ERROR (qpOASES): Dimension mismatch!\n" );
489  return 0;
490  }
491 
492 
493  y_size = H_rows + A_rows;
494 
495  CreateVar( 9,"d", &H_rows,&one,&x );
496  CreateVar( 10,"d", &one,&one,&obj );
497  CreateVar( 11,"i", &one,&one,&status );
498  CreateVar( 12,"i", &one,&one,&nWSRout );
499  CreateVar( 13,"d", &y_size,&one,&y );
500 
501 
502  sqp_rowsH = H_rows;
503  sqp_rowsA = A_rows;
504 
505 
506  /* call interfaced qpOASES routines with appropriate arguments */
507  sci_SQProblem_init( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0,
508  &H_rows,&A_rows,istk(nWSR),
509  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
510  );
511 
512  LhsVar(1) = 9;
513  LhsVar(2) = 10;
514  LhsVar(3) = 11;
515  LhsVar(4) = 12;
516  LhsVar(5) = 13;
517 
518  return 0;
519 }
520 
521 
522 /*
523  * i n t e r f a c e _ Q P r o b l e m _ h o t s t a r t
524  */
525 int interface_QProblem_hotstart( char* fname )
526 {
527  int_t g, g_rows, g_cols;
528  int_t lb, lb_rows, lb_cols;
529  int_t ub, ub_rows, ub_cols;
530  int_t lbA, lbA_rows, lbA_cols;
531  int_t ubA, ubA_rows, ubA_cols;
532  int_t nWSR, nWSR_rows, nWSR_cols;
533 
534  int_t x, obj, status, nWSRout, y;
535 
536 
537  int minlhs = 1, maxlhs = 5, minrhs = 6, maxrhs = 6, one = 1, y_size;
538 
539  CheckRhs( minrhs,maxrhs );
540  CheckLhs( minlhs,maxlhs );
541 
542 
543  if ( ( qp_rowsH == -1 ) || ( qp_rowsA == -1 ) )
544  {
545  Scierror( 311,"ERROR (qpOASES): Need to call qpOASES_init first!\n" );
546  return 0;
547  }
548 
549  /* check dimensions */
550  GetRhsVar( 1,"d", &g_rows,&g_cols,&g );
551  if ( !( ( ( g_rows == qp_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qp_rowsH ) ) ) )
552  {
553  Scierror( 312,"ERROR (qpOASES): Dimension mismatch!\n" );
554  return 0;
555  }
556 
557  GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb );
558  if ( !( ( ( lb_rows == qp_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
559  {
560  Scierror( 313,"ERROR (qpOASES): Dimension mismatch!\n" );
561  return 0;
562  }
563 
564  GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub );
565  if ( !( ( ( ub_rows == qp_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
566  {
567  Scierror( 314,"ERROR (qpOASES): Dimension mismatch!\n" );
568  return 0;
569  }
570 
571  GetRhsVar( 4,"d", &lbA_rows,&lbA_cols,&lbA );
572  if ( !( ( ( lbA_rows == qp_rowsA ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) )
573  {
574  Scierror( 315,"ERROR (qpOASES): Dimension mismatch!\n" );
575  return 0;
576  }
577 
578  GetRhsVar( 5,"d", &ubA_rows,&ubA_cols,&ubA );
579  if ( !( ( ( ubA_rows == qp_rowsA ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) )
580  {
581  Scierror( 316,"ERROR (qpOASES): Dimension mismatch!\n" );
582  return 0;
583  }
584 
585  GetRhsVar( 6,"i", &nWSR_rows,&nWSR_cols,&nWSR );
586  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
587  {
588  Scierror( 317,"ERROR (qpOASES): Dimension mismatch!\n" );
589  return 0;
590  }
591 
592 
593  y_size = qp_rowsH + qp_rowsA;
594 
595  CreateVar( 7,"d", &qp_rowsH,&one,&x );
596  CreateVar( 8,"d", &one,&one,&obj );
597  CreateVar( 9,"i", &one,&one,&status );
598  CreateVar( 10,"i", &one,&one,&nWSRout );
599  CreateVar( 11,"d", &y_size,&one,&y );
600 
601 
602  /* call interfaced qpOASES routines with appropriate arguments */
603  sci_QProblem_hotstart( stk(g), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0,
604  istk(nWSR),
605  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
606  );
607 
608  LhsVar(1) = 7;
609  LhsVar(2) = 8;
610  LhsVar(3) = 9;
611  LhsVar(4) = 10;
612  LhsVar(5) = 11;
613 
614  return 0;
615 }
616 
617 
618 /*
619  * i n t e r f a c e _ Q P r o b l e m B _ h o t s t a r t
620  */
622 {
623  int_t g, g_rows, g_cols;
624  int_t lb, lb_rows, lb_cols;
625  int_t ub, ub_rows, ub_cols;
626  int_t nWSR, nWSR_rows, nWSR_cols;
627 
628  int_t x, obj, status, nWSRout, y;
629 
630 
631  int minlhs = 1, maxlhs = 5, minrhs = 4, maxrhs = 4, one = 1;
632 
633  CheckRhs( minrhs,maxrhs );
634  CheckLhs( minlhs,maxlhs );
635 
636 
637  if ( qpb_rowsH == -1 )
638  {
639  Scierror( 321,"ERROR (qpOASES): Need to call qpOASES_initSB first!\n" );
640  return 0;
641  }
642 
643  /* check dimensions */
644  GetRhsVar( 1,"d", &g_rows,&g_cols,&g );
645  if ( !( ( ( g_rows == qpb_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qpb_rowsH ) ) ) )
646  {
647  Scierror( 322,"ERROR (qpOASES): Dimension mismatch!\n" );
648  return 0;
649  }
650 
651  GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb );
652  if ( !( ( ( lb_rows == qpb_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
653  {
654  Scierror( 323,"ERROR (qpOASES): Dimension mismatch!\n" );
655  return 0;
656  }
657 
658  GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub );
659  if ( !( ( ( ub_rows == qpb_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
660  {
661  Scierror( 324,"ERROR (qpOASES): Dimension mismatch!\n" );
662  return 0;
663  }
664 
665  GetRhsVar( 4,"i", &nWSR_rows,&nWSR_cols,&nWSR );
666  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
667  {
668  Scierror( 325,"ERROR (qpOASES): Dimension mismatch!\n" );
669  return 0;
670  }
671 
672 
673  CreateVar( 5,"d", &qpb_rowsH,&one,&x );
674  CreateVar( 6,"d", &one,&one,&obj );
675  CreateVar( 7,"i", &one,&one,&status );
676  CreateVar( 8,"i", &one,&one,&nWSRout );
677  CreateVar( 9,"d", &qpb_rowsH,&one,&y );
678 
679 
680  /* call interfaced qpOASES routines with appropriate arguments */
681  sci_QProblemB_hotstart( stk(g), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0,
682  istk(nWSR),
683  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
684  );
685 
686  LhsVar(1) = 5;
687  LhsVar(2) = 6;
688  LhsVar(3) = 7;
689  LhsVar(4) = 8;
690  LhsVar(5) = 9;
691 
692  return 0;
693 }
694 
695 
696 /*
697  * i n t e r f a c e _ S Q P r o b l e m _ h o t s t a r t
698  */
700 {
701  int_t H, H_rows, H_cols;
702  int_t g, g_rows, g_cols;
703  int_t A, A_rows, A_cols;
704  int_t lb, lb_rows, lb_cols;
705  int_t ub, ub_rows, ub_cols;
706  int_t lbA, lbA_rows, lbA_cols;
707  int_t ubA, ubA_rows, ubA_cols;
708  int_t nWSR, nWSR_rows, nWSR_cols;
709 
710  int_t obj, x, y, status, nWSRout;
711 
712 
713  int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
714 
715  CheckRhs( minrhs,maxrhs );
716  CheckLhs( minlhs,maxlhs );
717 
718 
719  if ( ( sqp_rowsH == -1 ) || ( sqp_rowsA == -1 ) )
720  {
721  Scierror( 331,"ERROR (qpOASES): Need to call qpOASES_initVM first!\n" );
722  return 0;
723  }
724 
725  /* check dimensions */
726  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
727  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
728  {
729  Scierror( 332,"ERROR (qpOASES): Dimension mismatch!\n" );
730  return 0;
731  }
732 
733  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
734  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
735  {
736  Scierror( 333,"ERROR (qpOASES): Dimension mismatch!\n" );
737  return 0;
738  }
739 
740  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
741  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
742  {
743  Scierror( 334,"ERROR (qpOASES): Dimension mismatch!\n" );
744  return 0;
745  }
746 
747  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
748  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
749  {
750  Scierror( 335,"ERROR (qpOASES): Dimension mismatch!\n" );
751  return 0;
752  }
753 
754  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
755  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
756  {
757  Scierror( 399,"ERROR (qpOASES): Dimension mismatch!\n" );
758  return 0;
759  }
760 
761  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
762  if ( !( ( ( lbA_rows == A_rows ) && ( lbA_cols == 1 ) ) || ( ( lbA_rows == 0 ) && ( lbA_cols == 0 ) ) ) )
763  {
764  Scierror( 336,"ERROR (qpOASES): Dimension mismatch!\n" );
765  return 0;
766  }
767 
768  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
769  if ( !( ( ( ubA_rows == A_rows ) && ( ubA_cols == 1 ) ) || ( ( ubA_rows == 0 ) && ( ubA_cols == 0 ) ) ) )
770  {
771  Scierror( 337,"ERROR (qpOASES): Dimension mismatch!\n" );
772  return 0;
773  }
774 
775  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
776  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
777  {
778  Scierror( 338,"ERROR (qpOASES): Dimension mismatch!\n" );
779  return 0;
780  }
781 
782  /* have matrices same dimension as last QP? */
783  if ( ( sqp_rowsH != H_rows ) || ( sqp_rowsA != A_rows ) )
784  {
785  Scierror( 339,"ERROR (qpOASES): Dimension mismatch!\n" );
786  return 0;
787  }
788 
789 
790  y_size = H_rows + A_rows;
791 
792  CreateVar( 9,"d", &H_rows,&one,&x );
793  CreateVar( 10,"d", &one,&one,&obj );
794  CreateVar( 11,"i", &one,&one,&status );
795  CreateVar( 12,"i", &one,&one,&nWSRout );
796  CreateVar( 13,"d", &y_size,&one,&y );
797 
798 
799  /* call interfaced qpOASES routines with appropriate arguments */
800  sci_SQProblem_hotstart( stk(H),stk(g),stk(A), (lb_rows!=0) ? stk(lb) : 0, (ub_rows!=0) ? stk(ub) : 0, (lbA_rows!=0) ? stk(lbA) : 0, (ubA_rows!=0) ? stk(ubA) : 0,
801  istk(nWSR),
802  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
803  );
804 
805  LhsVar(1) = 9;
806  LhsVar(2) = 10;
807  LhsVar(3) = 11;
808  LhsVar(4) = 12;
809  LhsVar(5) = 13;
810 
811  return 0;
812 }
813 
814 
815 /*
816  * i n t e r f a c e _ Q P r o b l e m _ c l e a n u p
817  */
818 int interface_QProblem_cleanup( char* fname )
819 {
820  const int minlhs = 0, maxlhs = 1, minrhs = 0, maxrhs = 0;
821 
822  CheckRhs( minrhs,maxrhs );
823  CheckLhs( minlhs,maxlhs );
824 
826  qp_rowsH = -1;
827  qp_rowsA = -1;
828 
829  return 0;
830 }
831 
832 
833 /*
834  * i n t e r f a c e _ Q P r o b l e m B _ c l e a n u p
835  */
836 int interface_QProblemB_cleanup( char* fname )
837 {
838  const int minlhs = 0, maxlhs = 1, minrhs = 0, maxrhs = 0;
839 
840  CheckRhs( minrhs,maxrhs );
841  CheckLhs( minlhs,maxlhs );
842 
844  qpb_rowsH = -1;
845 
846  return 0;
847 }
848 
849 
850 /*
851  * i n t e r f a c e _ S Q P r o b l e m _ c l e a n u p
852  */
853 int interface_SQProblem_cleanup( char* fname )
854 {
855  const int minlhs = 0, maxlhs = 1, minrhs = 0, maxrhs = 0;
856 
857  CheckRhs( minrhs,maxrhs );
858  CheckLhs( minlhs,maxlhs );
859 
861  sqp_rowsH = -1;
862  sqp_rowsA = -1;
863 
864  return 0;
865 }
866 
867 
868 /*
869  * q p O A S E S g a t e w a y
870  */
871 int C2F(qpOASESgateway)( )
872 {
873  gate_function function[] = { interface_qpOASES,
877  };
878  char* name[] = { "qpOASES",
879  "qpOASES_init", "qpOASES_initSB", "qpOASES_initVM",
880  "qpOASES_hotstart", "qpOASES_hotstartSB", "qpOASES_hotstartVM",
881  "qpOASES_cleanup", "qpOASES_cleanupSB", "qpOASES_cleanupVM"
882  };
883 
884  Rhs = Max( 0,Rhs );
885  sci_gateway( name[Fin-1],function[Fin-1] );
886 
887  return 0;
888 }
889 
890 
891 /*
892  * end of file
893  */
int interface_QProblemB_init(char *fname)
int interface_QProblemB_hotstart(char *fname)
void sci_QProblem_hotstart(real_t *g, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
void sci_QProblemB_hotstart(real_t *g, real_t *lb, real_t *ub, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
void sci_QProblem_init(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int_t *nV, int_t *nC, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
int interface_QProblem_hotstart(char *fname)
int sci_gateway(char *name, gate_function f)
int interface_SQProblem_hotstart(char *fname)
int interface_QProblemB_cleanup(char *fname)
void sci_QProblemB_init(real_t *H, real_t *g, real_t *lb, real_t *ub, int_t *nV, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
int interface_QProblem_cleanup(char *fname)
int interface_SQProblem_init(char *fname)
void sci_SQProblem_init(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int_t *nV, int_t *nC, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
int interface_QProblem_init(char *fname)
double real_t
Definition: AD_test.c:10
void sci_SQProblem_hotstart(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
void sci_qpOASES(real_t *H, real_t *g, real_t *A, real_t *lb, real_t *ub, real_t *lbA, real_t *ubA, int_t *nV, int_t *nC, int_t *nWSR, real_t *x, real_t *obj, int_t *status, int_t *nWSRout, real_t *y)
int interface_SQProblem_cleanup(char *fname)


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:35:01