qpOASES-3.0beta/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-2011 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/machine.h>
42 #include <scilab/sciprint.h>
43 /*#include "os_specific/link.h"*/
44 
45 
46 extern int int_init( char* fname );
47 extern int int_initSB( char* fname );
48 extern int int_initVM( char* fname );
49 
50 extern int int_solve( char* fname );
51 extern int int_solveSB( char* fname );
52 extern int int_solveVM( char* fname );
53 
54 extern int int_cleanup( char* fname );
55 extern int int_cleanupSB( char* fname );
56 extern int int_cleanupVM( char* fname );
57 
58 extern int int_qpOASES( char* fname );
59 
60 
61 typedef int (*gate_function) ( char* );
62 extern int sci_gateway( char* name, gate_function f );
63 extern int C2F(qpOASESgateway)();
64 
65 
66 /* forward declaration of C++ routines */
67 void qpoases( double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
68  int *nV, int* nC, int* nWSR,
69  double* x, double* obj, int* status, int* nWSRout, double* y
70  );
71 
72 void init( double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
73  int *nV, int* nC, int* nWSR,
74  double* x, double* obj, int* status, int* nWSRout, double* y
75  );
76 void initSB( double* H, double* g, double* lb, double* ub,
77  int *nV, int* nWSR,
78  double* x, double* obj, int* status, int* nWSRout, double* y
79  );
80 void initVM( double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
81  int *nV, int* nC, int* nWSR,
82  double* x, double* obj, int* status, int* nWSRout, double* y
83  );
84 
85 void hotstart( double* g, double* lb, double* ub, double* lbA, double* ubA,
86  int* nWSR,
87  double* x, double* obj, int* status, int* nWSRout, double* y
88  );
89 void hotstartSB( double* g, double* lb, double* ub,
90  int* nWSR,
91  double* x, double* obj, int* status, int* nWSRout, double* y
92  );
93 void hotstartVM( double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
94  int* nWSR,
95  double* x, double* obj, int* status, int* nWSRout, double* y
96  );
97 
98 void cleanupp( );
99 void cleanupSB( );
100 void cleanupVM( );
101 
102 
103 /* global variables containing dimensions of matrices
104  * (also used to check whether qpOASES object were initialised) */
105 int qp_rowsH = -1;
106 int qp_rowsA = -1;
107 int qpb_rowsH = -1;
108 int sqp_rowsH = -1;
109 int sqp_rowsA = -1;
110 
111 
112 /*
113  * i n t _ q p O A S E S
114  */
115 int int_qpOASES( char* fname )
116 {
117  static int H, H_rows, H_cols;
118  static int A, A_rows, A_cols;
119  static int g, g_rows, g_cols;
120  static int lb, lb_rows, lb_cols;
121  static int ub, ub_rows, ub_cols;
122  static int lbA, lbA_rows, lbA_cols;
123  static int ubA, ubA_rows, ubA_cols;
124  static int nWSR, nWSR_rows, nWSR_cols;
125 
126  static int obj, x, y, status, nWSRout;
127 
128 
129  static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
130 
131  CheckRhs( minrhs,maxrhs );
132  CheckLhs( minlhs,maxlhs );
133 
134 
135  /* check dimensions */
136  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
137  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
138  {
139  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
140  Error( 999 );
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  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
148  Error( 999 );
149  return 0;
150  }
151 
152  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
153  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
154  {
155  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
156  Error( 999 );
157  return 0;
158  }
159 
160  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
161  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
162  {
163  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
164  Error( 999 );
165  return 0;
166  }
167 
168  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
169  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
170  {
171  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
172  Error( 999 );
173  return 0;
174  }
175 
176  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
177  if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
178  {
179  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
180  Error( 999 );
181  return 0;
182  }
183 
184  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
185  if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
186  {
187  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
188  Error( 999 );
189  return 0;
190  }
191 
192  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
193  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
194  {
195  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
196  Error( 999 );
197  return 0;
198  }
199 
200 
201  y_size = H_rows + A_rows;
202 
203  CreateVar( 9,"d", &H_rows,&one,&x );
204  CreateVar( 10,"d", &one,&one,&obj );
205  CreateVar( 11,"i", &one,&one,&status );
206  CreateVar( 12,"i", &one,&one,&nWSRout );
207  CreateVar( 13,"d", &y_size,&one,&y );
208 
209 
210  /* call interfaced qpOASES routines with appropriate arguments */
211  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
212  {
213  qpoases( stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
214  &H_rows,&A_rows,istk(nWSR),
215  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
216  );
217  }
218  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
219  {
220  qpoases( stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
221  &H_rows,&A_rows,istk(nWSR),
222  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
223  );
224  }
225  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
226  {
227  qpoases( stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
228  &H_rows,&A_rows,istk(nWSR),
229  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
230  );
231  }
232  else
233  {
234  qpoases( stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
235  &H_rows,&A_rows,istk(nWSR),
236  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
237  );
238  }
239 
240  LhsVar(1) = 9;
241  LhsVar(2) = 10;
242  LhsVar(3) = 11;
243  LhsVar(4) = 12;
244  LhsVar(5) = 13;
245 
246  return 0;
247 }
248 
249 
250 /*
251  * i n t _ i n i t
252  */
253 int int_init( char* fname )
254 {
255  static int H, H_rows, H_cols;
256  static int A, A_rows, A_cols;
257  static int g, g_rows, g_cols;
258  static int lb, lb_rows, lb_cols;
259  static int ub, ub_rows, ub_cols;
260  static int lbA, lbA_rows, lbA_cols;
261  static int ubA, ubA_rows, ubA_cols;
262  static int nWSR, nWSR_rows, nWSR_cols;
263 
264  static int obj, x, y, status, nWSRout;
265 
266 
267  static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
268 
269  CheckRhs( minrhs,maxrhs );
270  CheckLhs( minlhs,maxlhs );
271 
272 
273  /* check dimensions */
274  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
275  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
276  {
277  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
278  Error( 999 );
279  return 0;
280  }
281 
282  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
283  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
284  {
285  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
286  Error( 999 );
287  return 0;
288  }
289 
290  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
291  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
292  {
293  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
294  Error( 999 );
295  return 0;
296  }
297 
298  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
299  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
300  {
301  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
302  Error( 999 );
303  return 0;
304  }
305 
306  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
307  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
308  {
309  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
310  Error( 999 );
311  return 0;
312  }
313 
314  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
315  if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
316  {
317  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
318  Error( 999 );
319  return 0;
320  }
321 
322  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
323  if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
324  {
325  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
326  Error( 999 );
327  return 0;
328  }
329 
330  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
331  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
332  {
333  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
334  Error( 999 );
335  return 0;
336  }
337 
338 
339  y_size = H_rows + A_rows;
340 
341  CreateVar( 9,"d", &H_rows,&one,&x );
342  CreateVar( 10,"d", &one,&one,&obj );
343  CreateVar( 11,"i", &one,&one,&status );
344  CreateVar( 12,"i", &one,&one,&nWSRout );
345  CreateVar( 13,"d", &y_size,&one,&y );
346 
347 
348  qp_rowsH = H_rows;
349  qp_rowsA = A_rows;
350 
351 
352  /* call interfaced qpOASES routines with appropriate arguments */
353  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
354  {
355  init( stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
356  &H_rows,&A_rows,istk(nWSR),
357  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
358  );
359  }
360  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
361  {
362  init( stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
363  &H_rows,&A_rows,istk(nWSR),
364  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
365  );
366  }
367  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
368  {
369  init( stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
370  &H_rows,&A_rows,istk(nWSR),
371  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
372  );
373  }
374  else
375  {
376  init( stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
377  &H_rows,&A_rows,istk(nWSR),
378  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
379  );
380  }
381 
382  LhsVar(1) = 9;
383  LhsVar(2) = 10;
384  LhsVar(3) = 11;
385  LhsVar(4) = 12;
386  LhsVar(5) = 13;
387 
388  return 0;
389 }
390 
391 
392 /*
393  * i n t _ i n i t S B
394  */
395 int int_initSB( char* fname )
396 {
397  static int H, H_rows, H_cols;
398  static int g, g_rows, g_cols;
399  static int lb, lb_rows, lb_cols;
400  static int ub, ub_rows, ub_cols;
401  static int nWSR, nWSR_rows, nWSR_cols;
402 
403  static int obj, x, y, status, nWSRout;
404 
405 
406  static int minlhs = 1, maxlhs = 5, minrhs = 5, maxrhs = 5, one = 1;
407 
408  CheckRhs( minrhs,maxrhs );
409  CheckLhs( minlhs,maxlhs );
410 
411 
412  /* check dimensions */
413  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
414  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
415  {
416  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
417  Error( 999 );
418  return 0;
419  }
420 
421  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
422  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
423  {
424  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
425  Error( 999 );
426  return 0;
427  }
428 
429  GetRhsVar( 3,"d", &lb_rows,&lb_cols,&lb);
430  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
431  {
432  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
433  Error( 999 );
434  return 0;
435  }
436 
437  GetRhsVar( 4,"d", &ub_rows,&ub_cols,&ub);
438  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
439  {
440  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
441  Error( 999 );
442  return 0;
443  }
444 
445  GetRhsVar( 5,"i", &nWSR_rows,&nWSR_cols,&nWSR);
446  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
447  {
448  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
449  Error( 999 );
450  return 0;
451  }
452 
453 
454  CreateVar( 9,"d", &H_rows,&one,&x );
455  CreateVar( 10,"d", &one,&one,&obj );
456  CreateVar( 11,"i", &one,&one,&status );
457  CreateVar( 12,"i", &one,&one,&nWSRout );
458  CreateVar( 13,"d", &H_rows,&one,&y );
459 
460 
461  qpb_rowsH = H_rows;
462 
463 
464  /* call interfaced qpOASES routines with appropriate arguments */
465  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
466  {
467  initSB( stk(H),stk(g),stk(lb),stk(ub),
468  &H_rows,istk(nWSR),
469  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
470  );
471  }
472  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
473  {
474  initSB( stk(H),stk(g),0,stk(ub),
475  &H_rows,istk(nWSR),
476  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
477  );
478  }
479  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
480  {
481  initSB( stk(H),stk(g),stk(lb),0,
482  &H_rows,istk(nWSR),
483  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
484  );
485  }
486  else
487  {
488  initSB( stk(H),stk(g),0,0,
489  &H_rows,istk(nWSR),
490  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
491  );
492  }
493 
494  LhsVar(1) = 9;
495  LhsVar(2) = 10;
496  LhsVar(3) = 11;
497  LhsVar(4) = 12;
498  LhsVar(5) = 13;
499 
500  return 0;
501 }
502 
503 
504 /*
505  * i n t _ i n i t V M
506  */
507 int int_initVM( char* fname )
508 {
509  static int H, H_rows, H_cols;
510  static int A, A_rows, A_cols;
511  static int g, g_rows, g_cols;
512  static int lb, lb_rows, lb_cols;
513  static int ub, ub_rows, ub_cols;
514  static int lbA, lbA_rows, lbA_cols;
515  static int ubA, ubA_rows, ubA_cols;
516  static int nWSR, nWSR_rows, nWSR_cols;
517 
518  static int obj, x, y, status, nWSRout;
519 
520 
521  static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
522 
523  CheckRhs( minrhs,maxrhs );
524  CheckLhs( minlhs,maxlhs );
525 
526 
527  /* check dimensions */
528  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
529  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
530  {
531  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
532  Error( 999 );
533  return 0;
534  }
535 
536  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
537  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
538  {
539  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
540  Error( 999 );
541  return 0;
542  }
543 
544  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
545  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
546  {
547  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
548  Error( 999 );
549  return 0;
550  }
551 
552  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb );
553  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
554  {
555  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
556  Error( 999 );
557  return 0;
558  }
559 
560  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub );
561  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
562  {
563  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
564  Error( 999 );
565  return 0;
566  }
567 
568  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA );
569  if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
570  {
571  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
572  Error( 999 );
573  return 0;
574  }
575 
576  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA );
577  if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
578  {
579  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
580  Error( 999 );
581  return 0;
582  }
583 
584  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR) ;
585  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
586  {
587  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
588  Error( 999 );
589  return 0;
590  }
591 
592 
593  y_size = H_rows + A_rows;
594 
595  CreateVar( 9,"d", &H_rows,&one,&x );
596  CreateVar( 10,"d", &one,&one,&obj );
597  CreateVar( 11,"i", &one,&one,&status );
598  CreateVar( 12,"i", &one,&one,&nWSRout );
599  CreateVar( 13,"d", &y_size,&one,&y );
600 
601 
602  sqp_rowsH = H_rows;
603  sqp_rowsA = A_rows;
604 
605 
606  /* call interfaced qpOASES routines with appropriate arguments */
607  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
608  {
609  initVM( stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
610  &H_rows,&A_rows,istk(nWSR),
611  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
612  );
613  }
614  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
615  {
616  initVM( stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
617  &H_rows,&A_rows,istk(nWSR),
618  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
619  );
620  }
621  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
622  {
623  initVM( stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
624  &H_rows,&A_rows,istk(nWSR),
625  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
626  );
627  }
628  else
629  {
630  initVM( stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
631  &H_rows,&A_rows,istk(nWSR),
632  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
633  );
634  }
635 
636  LhsVar(1) = 9;
637  LhsVar(2) = 10;
638  LhsVar(3) = 11;
639  LhsVar(4) = 12;
640  LhsVar(5) = 13;
641 
642  return 0;
643 }
644 
645 
646 /*
647  * i n t _ h o t s t a r t
648  */
649 int int_hotstart( char* fname )
650 {
651  static int g, g_rows, g_cols;
652  static int lb, lb_rows, lb_cols;
653  static int ub, ub_rows, ub_cols;
654  static int lbA, lbA_rows, lbA_cols;
655  static int ubA, ubA_rows, ubA_cols;
656  static int nWSR, nWSR_rows, nWSR_cols;
657 
658  static int obj, x, y, status, nWSRout;
659 
660 
661  static int minlhs = 1, maxlhs = 5, minrhs = 6, maxrhs = 6, one = 1, y_size;
662 
663  CheckRhs( minrhs,maxrhs );
664  CheckLhs( minlhs,maxlhs );
665 
666 
667  if ( ( qp_rowsH == -1 ) || ( qp_rowsA == -1 ) )
668  {
669  sciprint( "ERROR (qpOASES): QP not initialised!\n" );
670  Error( 999 );
671  return 0;
672  }
673 
674  /* check dimensions */
675  GetRhsVar( 1,"d", &g_rows,&g_cols,&g );
676  if ( !( ( ( g_rows == qp_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qp_rowsH ) ) ) )
677  {
678  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
679  Error( 999 );
680  return 0;
681  }
682 
683  GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb );
684  if ( !( ( ( lb_rows == qp_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
685  {
686  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
687  Error( 999 );
688  return 0;
689  }
690 
691  GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub );
692  if ( !( ( ( ub_rows == qp_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
693  {
694  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
695  Error( 999 );
696  return 0;
697  }
698 
699  GetRhsVar( 4,"d", &lbA_rows,&lbA_cols,&lbA );
700  if ( ( lbA_rows != qp_rowsA ) || ( lbA_cols != 1 ) )
701  {
702  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
703  Error( 999 );
704  return 0;
705  }
706 
707  GetRhsVar( 5,"d", &ubA_rows,&ubA_cols,&ubA );
708  if ( ( ubA_rows != qp_rowsA ) || ( ubA_cols != 1 ) )
709  {
710  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
711  Error( 999 );
712  return 0;
713  }
714 
715  GetRhsVar( 6,"i", &nWSR_rows,&nWSR_cols,&nWSR );
716  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
717  {
718  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
719  Error( 999 );
720  return 0;
721  }
722 
723 
724  y_size = qp_rowsH + qp_rowsA;
725 
726  CreateVar( 7,"d", &qp_rowsH,&one,&x );
727  CreateVar( 8,"d", &one,&one,&obj );
728  CreateVar( 9,"i", &one,&one,&status );
729  CreateVar( 10,"i", &one,&one,&nWSRout );
730  CreateVar( 11,"d", &y_size,&one,&y );
731 
732 
733  /* call interfaced qpOASES routines with appropriate arguments */
734  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
735  {
736  hotstart( stk(g),stk(lb),stk(ub),stk(lbA),stk(ubA),
737  istk(nWSR),
738  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
739  );
740  }
741  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
742  {
743  hotstart( stk(g),0,stk(ub),stk(lbA),stk(ubA),
744  istk(nWSR),
745  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
746  );
747  }
748  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
749  {
750  hotstart( stk(g),stk(lb),0,stk(lbA),stk(ubA),
751  istk(nWSR),
752  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
753  );
754  }
755  else
756  {
757  hotstart( stk(g),0,0,stk(lbA),stk(ubA),
758  istk(nWSR),
759  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
760  );
761  }
762 
763 
764  LhsVar(1) = 7;
765  LhsVar(2) = 8;
766  LhsVar(3) = 9;
767  LhsVar(4) = 10;
768  LhsVar(5) = 11;
769 
770  return 0;
771 }
772 
773 
774 /*
775  * i n t _ h o t s t a r t S B
776  */
777 int int_hotstartSB( char* fname )
778 {
779  static int g, g_rows, g_cols;
780  static int lb, lb_rows, lb_cols;
781  static int ub, ub_rows, ub_cols;
782  static int nWSR, nWSR_rows, nWSR_cols;
783 
784  static int obj, x, y, status, nWSRout;
785 
786 
787  static int minlhs = 1, maxlhs = 5, minrhs = 4, maxrhs = 4, one = 1;
788 
789  CheckRhs( minrhs,maxrhs );
790  CheckLhs( minlhs,maxlhs );
791 
792 
793  if ( qpb_rowsH == -1 )
794  {
795  sciprint( "ERROR (qpOASES): QP not initialised!\n" );
796  Error( 999 );
797  return 0;
798  }
799 
800  /* check dimensions */
801  GetRhsVar( 1,"d", &g_rows,&g_cols,&g );
802  if ( !( ( ( g_rows == qpb_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qpb_rowsH ) ) ) )
803  {
804  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
805  Error( 999 );
806  return 0;
807  }
808 
809  GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb );
810  if ( !( ( ( lb_rows == qpb_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
811  {
812  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
813  Error( 999 );
814  return 0;
815  }
816 
817  GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub );
818  if ( !( ( ( ub_rows == qpb_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
819  {
820  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
821  Error( 999 );
822  return 0;
823  }
824 
825  GetRhsVar( 4,"i", &nWSR_rows,&nWSR_cols,&nWSR );
826  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
827  {
828  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
829  Error( 999 );
830  return 0;
831  }
832 
833 
834  CreateVar( 5,"d", &qpb_rowsH,&one,&x );
835  CreateVar( 6,"d", &one,&one,&obj );
836  CreateVar( 7,"i", &one,&one,&status );
837  CreateVar( 8,"i", &one,&one,&nWSRout );
838  CreateVar( 9,"d", &qpb_rowsH,&one,&y );
839 
840 
841  /* call interfaced qpOASES routines with appropriate arguments */
842  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
843  {
844  hotstartSB( stk(g),stk(lb),stk(ub),
845  istk(nWSR),
846  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
847  );
848  }
849  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
850  {
851  hotstartSB( stk(g),0,stk(ub),
852  istk(nWSR),
853  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
854  );
855  }
856  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
857  {
858  hotstartSB( stk(g),stk(lb),0,
859  istk(nWSR),
860  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
861  );
862  }
863  else
864  {
865  hotstartSB( stk(g),0,0,
866  istk(nWSR),
867  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
868  );
869  }
870 
871 
872  LhsVar(1) = 5;
873  LhsVar(2) = 6;
874  LhsVar(3) = 7;
875  LhsVar(4) = 8;
876  LhsVar(5) = 9;
877 
878  return 0;
879 }
880 
881 
882 /*
883  * i n t _ h o t s t a r t V M
884  */
885 int int_hotstartVM( char* fname )
886 {
887  static int H, H_rows, H_cols;
888  static int A, A_rows, A_cols;
889  static int g, g_rows, g_cols;
890  static int lb, lb_rows, lb_cols;
891  static int ub, ub_rows, ub_cols;
892  static int lbA, lbA_rows, lbA_cols;
893  static int ubA, ubA_rows, ubA_cols;
894  static int nWSR, nWSR_rows, nWSR_cols;
895 
896  static int obj, x, y, status, nWSRout;
897 
898 
899  static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
900 
901  CheckRhs( minrhs,maxrhs );
902  CheckLhs( minlhs,maxlhs );
903 
904 
905  if ( ( sqp_rowsH == -1 ) || ( sqp_rowsA == -1 ) )
906  {
907  sciprint( "ERROR (qpOASES): QP not initialised!\n" );
908  Error( 999 );
909  return 0;
910  }
911 
912  /* check dimensions */
913  GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
914  if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
915  {
916  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
917  Error( 999 );
918  return 0;
919  }
920 
921  GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
922  if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
923  {
924  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
925  Error( 999 );
926  return 0;
927  }
928 
929  GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
930  if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
931  {
932  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
933  Error( 999 );
934  return 0;
935  }
936 
937  GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
938  if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
939  {
940  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
941  Error( 999 );
942  return 0;
943  }
944 
945  GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
946  if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
947  {
948  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
949  Error( 999 );
950  return 0;
951  }
952 
953  GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
954  if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
955  {
956  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
957  Error( 999 );
958  return 0;
959  }
960 
961  GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
962  if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
963  {
964  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
965  Error( 999 );
966  return 0;
967  }
968 
969  GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
970  if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
971  {
972  sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
973  Error( 999 );
974  return 0;
975  }
976 
977  /* have matrices same dimension as last QP? */
978  if ( ( sqp_rowsH != H_rows ) || ( sqp_rowsA != A_rows ) )
979  {
980  sciprint( "ERROR (qpOASES): Incompatible matrix dimensions!\n" );
981  Error( 999 );
982  return 0;
983  }
984 
985 
986  y_size = H_rows + A_rows;
987 
988  CreateVar( 9,"d", &H_rows,&one,&x );
989  CreateVar( 10,"d", &one,&one,&obj );
990  CreateVar( 11,"i", &one,&one,&status );
991  CreateVar( 12,"i", &one,&one,&nWSRout );
992  CreateVar( 13,"d", &y_size,&one,&y );
993 
994 
995  /* call interfaced qpOASES routines with appropriate arguments */
996  if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
997  {
998  hotstartVM( stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
999  istk(nWSR),
1000  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
1001  );
1002  }
1003  else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
1004  {
1005  hotstartVM( stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
1006  istk(nWSR),
1007  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
1008  );
1009  }
1010  else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
1011  {
1012  hotstartVM( stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
1013  istk(nWSR),
1014  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
1015  );
1016  }
1017  else
1018  {
1019  hotstartVM( stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
1020  istk(nWSR),
1021  stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
1022  );
1023  }
1024 
1025 
1026  LhsVar(1) = 9;
1027  LhsVar(2) = 10;
1028  LhsVar(3) = 11;
1029  LhsVar(4) = 12;
1030  LhsVar(5) = 13;
1031 
1032  return 0;
1033 }
1034 
1035 
1036 /*
1037  * i n t _ c l e a n u p
1038  */
1039 int int_cleanup( char* fname )
1040 {
1041  const int minlhs = 1, maxlhs = 1, minrhs = 0, maxrhs = 0;
1042 
1043  CheckRhs( minrhs,maxrhs );
1044  CheckLhs( minlhs,maxlhs );
1045 
1046  cleanupp( );
1047  qp_rowsH = -1;
1048  qp_rowsA = -1;
1049 
1050  return 0;
1051 }
1052 
1053 
1054 /*
1055  * i n t _ c l e a n u p S B
1056  */
1057 int int_cleanupSB( char* fname )
1058 {
1059  const int minlhs = 1, maxlhs = 1, minrhs = 0, maxrhs = 0;
1060 
1061  CheckRhs( minrhs,maxrhs );
1062  CheckLhs( minlhs,maxlhs );
1063 
1064  cleanupSB( );
1065  qpb_rowsH = -1;
1066 
1067  return 0;
1068 }
1069 
1070 
1071 /*
1072  * i n t _ c l e a n u p V M
1073  */
1074 int int_cleanupVM( char* fname )
1075 {
1076  const int minlhs = 1, maxlhs = 1, minrhs = 0, maxrhs = 0;
1077 
1078  CheckRhs( minrhs,maxrhs );
1079  CheckLhs( minlhs,maxlhs );
1080 
1081  cleanupVM( );
1082  sqp_rowsH = -1;
1083  sqp_rowsA = -1;
1084 
1085  return 0;
1086 }
1087 
1088 
1089 /*
1090  * q p O A S E S g a t e w a y
1091  */
1092 int C2F(qpOASESgateway)( )
1093 {
1094  gate_function function[] = { int_qpOASES,
1098  };
1099  char* name[] = { "qpOASES",
1100  "qpOASES_init", "qpOASES_initSB", "qpOASES_initVM",
1101  "qpOASES_hotstart", "qpOASES_hotstartSB", "qpOASES_hotstartVM",
1102  "qpOASES_cleanup", "qpOASES_cleanupSB", "qpOASES_cleanupVM"
1103  };
1104 
1105  Rhs = Max( 0,Rhs );
1106  sci_gateway( name[Fin-1],function[Fin-1] );
1107 
1108  return 0;
1109 }
1110 
1111 
1112 /*
1113  * end of file
1114  */
int sci_gateway(char *name, gate_function f)
int int_solveSB(char *fname)
def Error(filename, linenum, category, confidence, message)
Definition: cpplint.py:980
void hotstartSB(double *g, double *lb, double *ub, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)
void hotstart(double *g, double *lb, double *ub, double *lbA, double *ubA, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)
int int_solveVM(char *fname)
int int_solve(char *fname)
void hotstartVM(double *H, double *g, double *A, double *lb, double *ub, double *lbA, double *ubA, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)
void init(double *H, double *g, double *A, double *lb, double *ub, double *lbA, double *ubA, int *nV, int *nC, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)
void initVM(double *H, double *g, double *A, double *lb, double *ub, double *lbA, double *ubA, int *nV, int *nC, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)
void qpoases(double *H, double *g, double *A, double *lb, double *ub, double *lbA, double *ubA, int *nV, int *nC, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)
void initSB(double *H, double *g, double *lb, double *ub, int *nV, int *nWSR, double *x, double *obj, int *status, int *nWSRout, double *y)


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