qpOASESinterface.c
Go to the documentation of this file.
00001 /*
00002  *      This file is part of qpOASES.
00003  *
00004  *      qpOASES -- An Implementation of the Online Active Set Strategy.
00005  *      Copyright (C) 2007-2011 by Hans Joachim Ferreau, Andreas Potschka,
00006  *      Christian Kirches et al. All rights reserved.
00007  *
00008  *      qpOASES is free software; you can redistribute it and/or
00009  *      modify it under the terms of the GNU Lesser General Public
00010  *      License as published by the Free Software Foundation; either
00011  *      version 2.1 of the License, or (at your option) any later version.
00012  *
00013  *      qpOASES is distributed in the hope that it will be useful,
00014  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  *      See the GNU Lesser General Public License for more details.
00017  *
00018  *      You should have received a copy of the GNU Lesser General Public
00019  *      License along with qpOASES; if not, write to the Free Software
00020  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  */
00023 
00024 
00037 #include <stdio.h>
00038 #include <string.h>
00039 
00040 #include <scilab/stack-c.h>
00041 #include <scilab/machine.h>
00042 #include <scilab/sciprint.h>
00043 /*#include "os_specific/link.h"*/
00044 
00045 
00046 extern int int_init(   char* fname );
00047 extern int int_initSB( char* fname );
00048 extern int int_initVM( char* fname );
00049 
00050 extern int int_solve(   char* fname );
00051 extern int int_solveSB( char* fname );
00052 extern int int_solveVM( char* fname );
00053 
00054 extern int int_cleanup(   char* fname );
00055 extern int int_cleanupSB( char* fname );
00056 extern int int_cleanupVM( char* fname );
00057 
00058 extern int int_qpOASES( char* fname );
00059 
00060 
00061 typedef int (*gate_function) ( char* );
00062 extern int sci_gateway( char* name, gate_function f );
00063 extern int C2F(qpOASESgateway)();
00064 
00065 
00066 /* forward declaration of C++ routines */
00067 void qpoases(   double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
00068                                 int *nV, int* nC, int* nWSR,
00069                                 double* x, double* obj, int* status, int* nWSRout, double* y
00070                                 );
00071 
00072 void init(              double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
00073                                 int *nV, int* nC, int* nWSR,
00074                                 double* x, double* obj, int* status, int* nWSRout, double* y
00075                                 );
00076 void initSB(    double* H, double* g, double* lb, double* ub,
00077                                 int *nV, int* nWSR,
00078                                 double* x, double* obj, int* status, int* nWSRout, double* y
00079                                 );
00080 void initVM(    double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
00081                                 int *nV, int* nC, int* nWSR,
00082                                 double* x, double* obj, int* status, int* nWSRout, double* y
00083                                 );
00084 
00085 void hotstart(          double* g, double* lb, double* ub, double* lbA, double* ubA,
00086                                         int* nWSR,
00087                                         double* x, double* obj, int* status, int* nWSRout, double* y
00088                                         );
00089 void hotstartSB(        double* g, double* lb, double* ub,
00090                                         int* nWSR,
00091                                         double* x, double* obj, int* status, int* nWSRout, double* y
00092                                         );
00093 void hotstartVM(        double* H, double* g, double* A, double* lb, double* ub, double* lbA, double* ubA,
00094                                         int* nWSR,
00095                                         double* x, double* obj, int* status, int* nWSRout, double* y
00096                                         );
00097 
00098 void cleanupp( );
00099 void cleanupSB( );
00100 void cleanupVM( );
00101 
00102 
00103 /* global variables containing dimensions of matrices
00104  * (also used to check whether qpOASES object were initialised) */
00105 int qp_rowsH = -1;
00106 int qp_rowsA = -1;
00107 int qpb_rowsH = -1;
00108 int sqp_rowsH = -1;
00109 int sqp_rowsA = -1;
00110 
00111 
00112 /*
00113  *      i n t _ q p O A S E S
00114  */
00115 int int_qpOASES( char* fname )
00116 {
00117         static int H, H_rows, H_cols;
00118         static int A, A_rows, A_cols;
00119         static int g, g_rows, g_cols;
00120         static int lb, lb_rows, lb_cols;
00121         static int ub, ub_rows, ub_cols;
00122         static int lbA, lbA_rows, lbA_cols;
00123         static int ubA, ubA_rows, ubA_cols;
00124         static int nWSR, nWSR_rows, nWSR_cols;
00125 
00126         static int obj, x, y, status, nWSRout;
00127 
00128 
00129         static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
00130 
00131         CheckRhs( minrhs,maxrhs );
00132         CheckLhs( minlhs,maxlhs );
00133 
00134 
00135         /* check dimensions */
00136         GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
00137         if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
00138         {
00139                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00140                 Error( 999 );
00141                 return 0;
00142         }
00143 
00144         GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
00145         if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
00146         {
00147                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00148                 Error( 999 );
00149                 return 0;
00150         }
00151 
00152         GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
00153         if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
00154         {
00155                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00156                 Error( 999 );
00157                 return 0;
00158         }
00159 
00160         GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
00161         if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00162         {
00163                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00164                 Error( 999 );
00165                 return 0;
00166         }
00167 
00168         GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
00169         if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00170         {
00171                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00172                 Error( 999 );
00173                 return 0;
00174         }
00175 
00176         GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
00177         if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
00178         {
00179                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00180                 Error( 999 );
00181                 return 0;
00182         }
00183 
00184         GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
00185         if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
00186         {
00187                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00188                 Error( 999 );
00189                 return 0;
00190         }
00191 
00192         GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
00193         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00194         {
00195                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00196                 Error( 999 );
00197                 return 0;
00198         }
00199 
00200 
00201         y_size = H_rows + A_rows;
00202 
00203         CreateVar(  9,"d", &H_rows,&one,&x );
00204         CreateVar( 10,"d", &one,&one,&obj );
00205         CreateVar( 11,"i", &one,&one,&status );
00206         CreateVar( 12,"i", &one,&one,&nWSRout );
00207         CreateVar( 13,"d", &y_size,&one,&y );
00208 
00209 
00210         /* call interfaced qpOASES routines with appropriate arguments */
00211         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00212         {
00213                 qpoases(        stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
00214                                         &H_rows,&A_rows,istk(nWSR),
00215                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00216                                         );
00217         }
00218         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
00219         {
00220                 qpoases(        stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
00221                                         &H_rows,&A_rows,istk(nWSR),
00222                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00223                                         );
00224         }
00225         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
00226         {
00227                 qpoases(        stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
00228                                         &H_rows,&A_rows,istk(nWSR),
00229                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00230                                         );
00231         }
00232         else
00233         {
00234                 qpoases(        stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
00235                                         &H_rows,&A_rows,istk(nWSR),
00236                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00237                                         );
00238         }
00239 
00240         LhsVar(1) = 9;
00241         LhsVar(2) = 10;
00242         LhsVar(3) = 11;
00243         LhsVar(4) = 12;
00244         LhsVar(5) = 13;
00245 
00246         return 0;
00247 }
00248 
00249 
00250 /*
00251  *      i n t _ i n i t
00252  */
00253 int int_init( char* fname )
00254 {
00255         static int H, H_rows, H_cols;
00256         static int A, A_rows, A_cols;
00257         static int g, g_rows, g_cols;
00258         static int lb, lb_rows, lb_cols;
00259         static int ub, ub_rows, ub_cols;
00260         static int lbA, lbA_rows, lbA_cols;
00261         static int ubA, ubA_rows, ubA_cols;
00262         static int nWSR, nWSR_rows, nWSR_cols;
00263 
00264         static int obj, x, y, status, nWSRout;
00265 
00266 
00267         static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
00268 
00269         CheckRhs( minrhs,maxrhs );
00270         CheckLhs( minlhs,maxlhs );
00271 
00272 
00273         /* check dimensions */
00274         GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
00275         if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
00276         {
00277                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00278                 Error( 999 );
00279                 return 0;
00280         }
00281 
00282         GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
00283         if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
00284         {
00285                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00286                 Error( 999 );
00287                 return 0;
00288         }
00289 
00290         GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
00291         if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
00292         {
00293                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00294                 Error( 999 );
00295                 return 0;
00296         }
00297 
00298         GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
00299         if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00300         {
00301                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00302                 Error( 999 );
00303                 return 0;
00304         }
00305 
00306         GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
00307         if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00308         {
00309                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00310                 Error( 999 );
00311                 return 0;
00312         }
00313 
00314         GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
00315         if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
00316         {
00317                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00318                 Error( 999 );
00319                 return 0;
00320         }
00321 
00322         GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
00323         if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
00324         {
00325                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00326                 Error( 999 );
00327                 return 0;
00328         }
00329 
00330         GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
00331         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00332         {
00333                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00334                 Error( 999 );
00335                 return 0;
00336         }
00337 
00338 
00339         y_size = H_rows + A_rows;
00340 
00341         CreateVar(  9,"d", &H_rows,&one,&x );
00342         CreateVar( 10,"d", &one,&one,&obj );
00343         CreateVar( 11,"i", &one,&one,&status );
00344         CreateVar( 12,"i", &one,&one,&nWSRout );
00345         CreateVar( 13,"d", &y_size,&one,&y );
00346 
00347 
00348         qp_rowsH = H_rows;
00349         qp_rowsA = A_rows;
00350 
00351 
00352         /* call interfaced qpOASES routines with appropriate arguments */
00353         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00354         {
00355                 init(   stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
00356                                 &H_rows,&A_rows,istk(nWSR),
00357                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00358                                 );
00359         }
00360         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
00361         {
00362                 init(   stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
00363                                 &H_rows,&A_rows,istk(nWSR),
00364                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00365                                 );
00366         }
00367         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
00368         {
00369                 init(   stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
00370                                 &H_rows,&A_rows,istk(nWSR),
00371                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00372                                 );
00373         }
00374         else
00375         {
00376                 init(   stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
00377                                 &H_rows,&A_rows,istk(nWSR),
00378                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00379                                 );
00380         }
00381 
00382         LhsVar(1) = 9;
00383         LhsVar(2) = 10;
00384         LhsVar(3) = 11;
00385         LhsVar(4) = 12;
00386         LhsVar(5) = 13;
00387 
00388         return 0;
00389 }
00390 
00391 
00392 /*
00393  *      i n t _ i n i t S B
00394  */
00395 int int_initSB( char* fname )
00396 {
00397         static int H, H_rows, H_cols;
00398         static int g, g_rows, g_cols;
00399         static int lb, lb_rows, lb_cols;
00400         static int ub, ub_rows, ub_cols;
00401         static int nWSR, nWSR_rows, nWSR_cols;
00402 
00403         static int obj, x, y, status, nWSRout;
00404 
00405 
00406         static int minlhs = 1, maxlhs = 5, minrhs = 5, maxrhs = 5, one = 1;
00407 
00408         CheckRhs( minrhs,maxrhs );
00409         CheckLhs( minlhs,maxlhs );
00410 
00411 
00412         /* check dimensions */
00413         GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
00414         if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
00415         {
00416                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00417                 Error( 999 );
00418                 return 0;
00419         }
00420 
00421         GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
00422         if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
00423         {
00424                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00425                 Error( 999 );
00426                 return 0;
00427         }
00428 
00429         GetRhsVar( 3,"d", &lb_rows,&lb_cols,&lb);
00430         if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00431         {
00432                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00433                 Error( 999 );
00434                 return 0;
00435         }
00436 
00437         GetRhsVar( 4,"d", &ub_rows,&ub_cols,&ub);
00438         if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00439         {
00440                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00441                 Error( 999 );
00442                 return 0;
00443         }
00444 
00445         GetRhsVar( 5,"i", &nWSR_rows,&nWSR_cols,&nWSR);
00446         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00447         {
00448                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00449                 Error( 999 );
00450                 return 0;
00451         }
00452 
00453 
00454         CreateVar(  9,"d", &H_rows,&one,&x );
00455         CreateVar( 10,"d", &one,&one,&obj );
00456         CreateVar( 11,"i", &one,&one,&status );
00457         CreateVar( 12,"i", &one,&one,&nWSRout );
00458         CreateVar( 13,"d", &H_rows,&one,&y );
00459 
00460 
00461         qpb_rowsH = H_rows;
00462 
00463 
00464         /* call interfaced qpOASES routines with appropriate arguments */
00465         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00466         {
00467                 initSB( stk(H),stk(g),stk(lb),stk(ub),
00468                                 &H_rows,istk(nWSR),
00469                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00470                                 );
00471         }
00472         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
00473         {
00474                 initSB( stk(H),stk(g),0,stk(ub),
00475                                 &H_rows,istk(nWSR),
00476                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00477                                 );
00478         }
00479         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
00480         {
00481                 initSB( stk(H),stk(g),stk(lb),0,
00482                                 &H_rows,istk(nWSR),
00483                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00484                                 );
00485         }
00486         else
00487         {
00488                 initSB( stk(H),stk(g),0,0,
00489                                 &H_rows,istk(nWSR),
00490                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00491                                 );
00492         }
00493 
00494         LhsVar(1) = 9;
00495         LhsVar(2) = 10;
00496         LhsVar(3) = 11;
00497         LhsVar(4) = 12;
00498         LhsVar(5) = 13;
00499 
00500         return 0;
00501 }
00502 
00503 
00504 /*
00505  *      i n t _ i n i t V M
00506  */
00507 int int_initVM( char* fname )
00508 {
00509         static int H, H_rows, H_cols;
00510         static int A, A_rows, A_cols;
00511         static int g, g_rows, g_cols;
00512         static int lb, lb_rows, lb_cols;
00513         static int ub, ub_rows, ub_cols;
00514         static int lbA, lbA_rows, lbA_cols;
00515         static int ubA, ubA_rows, ubA_cols;
00516         static int nWSR, nWSR_rows, nWSR_cols;
00517 
00518         static int obj, x, y, status, nWSRout;
00519 
00520 
00521         static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
00522 
00523         CheckRhs( minrhs,maxrhs );
00524         CheckLhs( minlhs,maxlhs );
00525 
00526 
00527         /* check dimensions */
00528         GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
00529         if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
00530         {
00531                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00532                 Error( 999 );
00533                 return 0;
00534         }
00535 
00536         GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
00537         if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
00538         {
00539                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00540                 Error( 999 );
00541                 return 0;
00542         }
00543 
00544         GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
00545         if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
00546         {
00547                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00548                 Error( 999 );
00549                 return 0;
00550         }
00551 
00552         GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb );
00553         if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00554         {
00555                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00556                 Error( 999 );
00557                 return 0;
00558         }
00559 
00560         GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub );
00561         if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00562         {
00563                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00564                 Error( 999 );
00565                 return 0;
00566         }
00567 
00568         GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA );
00569         if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
00570         {
00571                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00572                 Error( 999 );
00573                 return 0;
00574         }
00575 
00576         GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA );
00577         if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
00578         {
00579                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00580                 Error( 999 );
00581                 return 0;
00582         }
00583 
00584         GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR) ;
00585         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00586         {
00587                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00588                 Error( 999 );
00589                 return 0;
00590         }
00591 
00592 
00593         y_size = H_rows + A_rows;
00594 
00595         CreateVar(  9,"d", &H_rows,&one,&x );
00596         CreateVar( 10,"d", &one,&one,&obj );
00597         CreateVar( 11,"i", &one,&one,&status );
00598         CreateVar( 12,"i", &one,&one,&nWSRout );
00599         CreateVar( 13,"d", &y_size,&one,&y );
00600 
00601 
00602         sqp_rowsH = H_rows;
00603         sqp_rowsA = A_rows;
00604 
00605 
00606         /* call interfaced qpOASES routines with appropriate arguments */
00607         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00608         {
00609                 initVM( stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
00610                                 &H_rows,&A_rows,istk(nWSR),
00611                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00612                                 );
00613         }
00614         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
00615         {
00616                 initVM( stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
00617                                 &H_rows,&A_rows,istk(nWSR),
00618                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00619                                 );
00620         }
00621         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
00622         {
00623                 initVM( stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
00624                                 &H_rows,&A_rows,istk(nWSR),
00625                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00626                                 );
00627         }
00628         else
00629         {
00630                 initVM( stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
00631                                 &H_rows,&A_rows,istk(nWSR),
00632                                 stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00633                                 );
00634         }
00635 
00636         LhsVar(1) = 9;
00637         LhsVar(2) = 10;
00638         LhsVar(3) = 11;
00639         LhsVar(4) = 12;
00640         LhsVar(5) = 13;
00641 
00642         return 0;
00643 }
00644 
00645 
00646 /*
00647  *      i n t _ h o t s t a r t
00648  */
00649 int int_hotstart( char* fname )
00650 {
00651         static int g, g_rows, g_cols;
00652         static int lb, lb_rows, lb_cols;
00653         static int ub, ub_rows, ub_cols;
00654         static int lbA, lbA_rows, lbA_cols;
00655         static int ubA, ubA_rows, ubA_cols;
00656         static int nWSR, nWSR_rows, nWSR_cols;
00657 
00658         static int obj, x, y, status, nWSRout;
00659 
00660 
00661         static int minlhs = 1, maxlhs = 5, minrhs = 6, maxrhs = 6, one = 1, y_size;
00662 
00663         CheckRhs( minrhs,maxrhs );
00664         CheckLhs( minlhs,maxlhs );
00665 
00666 
00667         if ( ( qp_rowsH == -1 ) || ( qp_rowsA == -1 ) )
00668         {
00669                 sciprint( "ERROR (qpOASES): QP not initialised!\n" );
00670                 Error( 999 );
00671                 return 0;
00672         }
00673 
00674         /* check dimensions */
00675         GetRhsVar( 1,"d", &g_rows,&g_cols,&g );
00676         if ( !( ( ( g_rows == qp_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qp_rowsH ) ) ) )
00677         {
00678                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00679                 Error( 999 );
00680                 return 0;
00681         }
00682 
00683         GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb );
00684         if ( !( ( ( lb_rows == qp_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00685         {
00686                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00687                 Error( 999 );
00688                 return 0;
00689         }
00690 
00691         GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub );
00692         if ( !( ( ( ub_rows == qp_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00693         {
00694                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00695                 Error( 999 );
00696                 return 0;
00697         }
00698 
00699         GetRhsVar( 4,"d", &lbA_rows,&lbA_cols,&lbA );
00700         if ( ( lbA_rows != qp_rowsA ) || ( lbA_cols != 1 ) )
00701         {
00702                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00703                 Error( 999 );
00704                 return 0;
00705         }
00706 
00707         GetRhsVar( 5,"d", &ubA_rows,&ubA_cols,&ubA );
00708         if ( ( ubA_rows != qp_rowsA ) || ( ubA_cols != 1 ) )
00709         {
00710                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00711                 Error( 999 );
00712                 return 0;
00713         }
00714 
00715         GetRhsVar( 6,"i", &nWSR_rows,&nWSR_cols,&nWSR );
00716         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00717         {
00718                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00719                 Error( 999 );
00720                 return 0;
00721         }
00722 
00723 
00724         y_size = qp_rowsH + qp_rowsA;
00725 
00726         CreateVar(  7,"d", &qp_rowsH,&one,&x );
00727         CreateVar(  8,"d", &one,&one,&obj );
00728         CreateVar(  9,"i", &one,&one,&status );
00729         CreateVar( 10,"i", &one,&one,&nWSRout );
00730         CreateVar( 11,"d", &y_size,&one,&y );
00731 
00732 
00733         /* call interfaced qpOASES routines with appropriate arguments */
00734         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00735         {
00736                 hotstart(       stk(g),stk(lb),stk(ub),stk(lbA),stk(ubA),
00737                                         istk(nWSR),
00738                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00739                                         );
00740         }
00741         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
00742         {
00743                 hotstart(       stk(g),0,stk(ub),stk(lbA),stk(ubA),
00744                                         istk(nWSR),
00745                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00746                                         );
00747         }
00748         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
00749         {
00750                 hotstart(       stk(g),stk(lb),0,stk(lbA),stk(ubA),
00751                                         istk(nWSR),
00752                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00753                                         );
00754         }
00755         else
00756         {
00757                 hotstart(       stk(g),0,0,stk(lbA),stk(ubA),
00758                                         istk(nWSR),
00759                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00760                                         );
00761         }
00762 
00763 
00764         LhsVar(1) = 7;
00765         LhsVar(2) = 8;
00766         LhsVar(3) = 9;
00767         LhsVar(4) = 10;
00768         LhsVar(5) = 11;
00769 
00770         return 0;
00771 }
00772 
00773 
00774 /*
00775  *      i n t _ h o t s t a r t S B
00776  */
00777 int int_hotstartSB( char* fname )
00778 {
00779         static int g, g_rows, g_cols;
00780         static int lb, lb_rows, lb_cols;
00781         static int ub, ub_rows, ub_cols;
00782         static int nWSR, nWSR_rows, nWSR_cols;
00783 
00784         static int obj, x, y, status, nWSRout;
00785 
00786 
00787         static int minlhs = 1, maxlhs = 5, minrhs = 4, maxrhs = 4, one = 1;
00788 
00789         CheckRhs( minrhs,maxrhs );
00790         CheckLhs( minlhs,maxlhs );
00791 
00792 
00793         if ( qpb_rowsH == -1 )
00794         {
00795                 sciprint( "ERROR (qpOASES): QP not initialised!\n" );
00796                 Error( 999 );
00797                 return 0;
00798         }
00799 
00800         /* check dimensions */
00801         GetRhsVar( 1,"d", &g_rows,&g_cols,&g );
00802         if ( !( ( ( g_rows == qpb_rowsH ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == qpb_rowsH ) ) ) )
00803         {
00804                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00805                 Error( 999 );
00806                 return 0;
00807         }
00808 
00809         GetRhsVar( 2,"d", &lb_rows,&lb_cols,&lb );
00810         if ( !( ( ( lb_rows == qpb_rowsH ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00811         {
00812                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00813                 Error( 999 );
00814                 return 0;
00815         }
00816 
00817         GetRhsVar( 3,"d", &ub_rows,&ub_cols,&ub );
00818         if ( !( ( ( ub_rows == qpb_rowsH ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00819         {
00820                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00821                 Error( 999 );
00822                 return 0;
00823         }
00824 
00825         GetRhsVar( 4,"i", &nWSR_rows,&nWSR_cols,&nWSR );
00826         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00827         {
00828                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00829                 Error( 999 );
00830                 return 0;
00831         }
00832 
00833 
00834         CreateVar( 5,"d", &qpb_rowsH,&one,&x );
00835         CreateVar( 6,"d", &one,&one,&obj );
00836         CreateVar( 7,"i", &one,&one,&status );
00837         CreateVar( 8,"i", &one,&one,&nWSRout );
00838         CreateVar( 9,"d", &qpb_rowsH,&one,&y );
00839 
00840 
00841         /* call interfaced qpOASES routines with appropriate arguments */
00842         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00843         {
00844                 hotstartSB(     stk(g),stk(lb),stk(ub),
00845                                         istk(nWSR),
00846                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00847                                         );
00848         }
00849         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
00850         {
00851                 hotstartSB(     stk(g),0,stk(ub),
00852                                         istk(nWSR),
00853                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00854                                         );
00855         }
00856         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
00857         {
00858                 hotstartSB(     stk(g),stk(lb),0,
00859                                         istk(nWSR),
00860                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00861                                         );
00862         }
00863         else
00864         {
00865                 hotstartSB(     stk(g),0,0,
00866                                         istk(nWSR),
00867                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
00868                                         );
00869         }
00870 
00871 
00872         LhsVar(1) = 5;
00873         LhsVar(2) = 6;
00874         LhsVar(3) = 7;
00875         LhsVar(4) = 8;
00876         LhsVar(5) = 9;
00877 
00878         return 0;
00879 }
00880 
00881 
00882 /*
00883  *      i n t _ h o t s t a r t V M
00884  */
00885 int int_hotstartVM( char* fname )
00886 {
00887         static int H, H_rows, H_cols;
00888         static int A, A_rows, A_cols;
00889         static int g, g_rows, g_cols;
00890         static int lb, lb_rows, lb_cols;
00891         static int ub, ub_rows, ub_cols;
00892         static int lbA, lbA_rows, lbA_cols;
00893         static int ubA, ubA_rows, ubA_cols;
00894         static int nWSR, nWSR_rows, nWSR_cols;
00895 
00896         static int obj, x, y, status, nWSRout;
00897 
00898 
00899         static int minlhs = 1, maxlhs = 5, minrhs = 8, maxrhs = 8, one = 1, y_size;
00900 
00901         CheckRhs( minrhs,maxrhs );
00902         CheckLhs( minlhs,maxlhs );
00903 
00904 
00905         if ( ( sqp_rowsH == -1 ) || ( sqp_rowsA == -1 ) )
00906         {
00907                 sciprint( "ERROR (qpOASES): QP not initialised!\n" );
00908                 Error( 999 );
00909                 return 0;
00910         }
00911 
00912         /* check dimensions */
00913         GetRhsVar( 1,"d", &H_rows,&H_cols,&H );
00914         if ( ( H_rows != H_cols ) || ( H_rows < 1 ) )
00915         {
00916                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00917                 Error( 999 );
00918                 return 0;
00919         }
00920 
00921         GetRhsVar( 2,"d", &g_rows,&g_cols,&g );
00922         if ( !( ( ( g_rows == H_rows ) && ( g_cols == 1 ) ) || ( ( g_rows == 1 ) && ( g_cols == H_rows ) ) ) )
00923         {
00924                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00925                 Error( 999 );
00926                 return 0;
00927         }
00928 
00929         GetRhsVar( 3,"d", &A_rows,&A_cols,&A );
00930         if ( ( A_cols != H_rows ) || ( A_rows < 1 ) )
00931         {
00932                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00933                 Error( 999 );
00934                 return 0;
00935         }
00936 
00937         GetRhsVar( 4,"d", &lb_rows,&lb_cols,&lb);
00938         if ( !( ( ( lb_rows == H_rows ) && ( lb_cols == 1 ) ) || ( ( lb_rows == 0 ) && ( lb_cols == 0 ) ) ) )
00939         {
00940                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00941                 Error( 999 );
00942                 return 0;
00943         }
00944 
00945         GetRhsVar( 5,"d", &ub_rows,&ub_cols,&ub);
00946         if ( !( ( ( ub_rows == H_rows ) && ( ub_cols == 1 ) ) || ( ( ub_rows == 0 ) && ( ub_cols == 0 ) ) ) )
00947         {
00948                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00949                 Error( 999 );
00950                 return 0;
00951         }
00952 
00953         GetRhsVar( 6,"d", &lbA_rows,&lbA_cols,&lbA);
00954         if ( ( lbA_rows != A_rows ) || ( lbA_cols != 1 ) )
00955         {
00956                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00957                 Error( 999 );
00958                 return 0;
00959         }
00960 
00961         GetRhsVar( 7,"d", &ubA_rows,&ubA_cols,&ubA);
00962         if ( ( ubA_rows != A_rows ) || ( ubA_cols != 1 ) )
00963         {
00964                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00965                 Error( 999 );
00966                 return 0;
00967         }
00968 
00969         GetRhsVar( 8,"i", &nWSR_rows,&nWSR_cols,&nWSR);
00970         if ( ( nWSR_rows != nWSR_cols ) || ( nWSR_cols != 1 ) )
00971         {
00972                 sciprint( "ERROR (qpOASES): Dimension mismatch!\n" );
00973                 Error( 999 );
00974                 return 0;
00975         }
00976 
00977         /* have matrices same dimension as last QP? */
00978         if ( ( sqp_rowsH != H_rows ) || ( sqp_rowsA != A_rows ) )
00979         {
00980                 sciprint( "ERROR (qpOASES): Incompatible matrix dimensions!\n" );
00981                 Error( 999 );
00982                 return 0;
00983         }
00984 
00985 
00986         y_size = H_rows + A_rows;
00987 
00988         CreateVar(  9,"d", &H_rows,&one,&x );
00989         CreateVar( 10,"d", &one,&one,&obj );
00990         CreateVar( 11,"i", &one,&one,&status );
00991         CreateVar( 12,"i", &one,&one,&nWSRout );
00992         CreateVar( 13,"d", &y_size,&one,&y );
00993 
00994 
00995         /* call interfaced qpOASES routines with appropriate arguments */
00996         if ( ( lb_rows != 0 ) && ( ub_rows != 0 ) )
00997         {
00998                 hotstartVM(     stk(H),stk(g),stk(A),stk(lb),stk(ub),stk(lbA),stk(ubA),
00999                                         istk(nWSR),
01000                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
01001                                         );
01002         }
01003         else if ( ( lb_rows == 0 ) && ( ub_rows != 0 ) )
01004         {
01005                 hotstartVM(     stk(H),stk(g),stk(A),0,stk(ub),stk(lbA),stk(ubA),
01006                                         istk(nWSR),
01007                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
01008                                         );
01009         }
01010         else if ( ( lb_rows != 0 ) && ( ub_rows == 0 ) )
01011         {
01012                 hotstartVM(     stk(H),stk(g),stk(A),stk(lb),0,stk(lbA),stk(ubA),
01013                                         istk(nWSR),
01014                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
01015                                         );
01016         }
01017         else
01018         {
01019                 hotstartVM(     stk(H),stk(g),stk(A),0,0,stk(lbA),stk(ubA),
01020                                         istk(nWSR),
01021                                         stk(x),stk(obj),istk(status),istk(nWSRout),stk(y)
01022                                         );
01023         }
01024 
01025 
01026         LhsVar(1) = 9;
01027         LhsVar(2) = 10;
01028         LhsVar(3) = 11;
01029         LhsVar(4) = 12;
01030         LhsVar(5) = 13;
01031 
01032         return 0;
01033 }
01034 
01035 
01036 /*
01037  *      i n t _ c l e a n u p
01038  */
01039 int int_cleanup( char* fname )
01040 {
01041         const int minlhs = 1, maxlhs = 1, minrhs = 0, maxrhs = 0;
01042 
01043         CheckRhs( minrhs,maxrhs );
01044         CheckLhs( minlhs,maxlhs );
01045 
01046         cleanupp( );
01047         qp_rowsH = -1;
01048         qp_rowsA = -1;
01049 
01050         return 0;
01051 }
01052 
01053 
01054 /*
01055  *      i n t _ c l e a n u p S B
01056  */
01057 int int_cleanupSB( char* fname )
01058 {
01059         const int minlhs = 1, maxlhs = 1, minrhs = 0, maxrhs = 0;
01060 
01061         CheckRhs( minrhs,maxrhs );
01062         CheckLhs( minlhs,maxlhs );
01063 
01064         cleanupSB( );
01065         qpb_rowsH = -1;
01066 
01067         return 0;
01068 }
01069 
01070 
01071 /*
01072  *      i n t _ c l e a n u p V M
01073  */
01074 int int_cleanupVM( char* fname )
01075 {
01076         const int minlhs = 1, maxlhs = 1, minrhs = 0, maxrhs = 0;
01077 
01078         CheckRhs( minrhs,maxrhs );
01079         CheckLhs( minlhs,maxlhs );
01080 
01081         cleanupVM( );
01082         sqp_rowsH = -1;
01083         sqp_rowsA = -1;
01084 
01085         return 0;
01086 }
01087 
01088 
01089 /*
01090  *      q p O A S E S g a t e w a y
01091  */
01092 int C2F(qpOASESgateway)( )
01093 {
01094         gate_function function[] = {    int_qpOASES,
01095                                                                         int_init, int_initSB, int_initVM,
01096                                                                         int_hotstart, int_hotstartSB, int_hotstartVM,
01097                                                                         int_cleanup, int_cleanupSB, int_cleanupVM
01098                                                                         };
01099         char* name[] = {        "qpOASES",
01100                                                 "qpOASES_init", "qpOASES_initSB", "qpOASES_initVM",
01101                                                 "qpOASES_hotstart", "qpOASES_hotstartSB", "qpOASES_hotstartVM",
01102                                                 "qpOASES_cleanup", "qpOASES_cleanupSB", "qpOASES_cleanupVM"
01103                                                 };
01104 
01105         Rhs = Max( 0,Rhs );
01106         sci_gateway( name[Fin-1],function[Fin-1] );
01107 
01108         return 0;
01109 }
01110 
01111 
01112 /*
01113  *      end of file
01114  */


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:59:50