00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00038 #include <iostream>
00039
00040 #include <qpOASES/SQProblem.hpp>
00041
00042
00043 using namespace qpOASES;
00044
00045
00046 QProblem* qp = 0;
00047 QProblemB* qpb = 0;
00048 SQProblem* sqp = 0;
00049
00050
00051 extern "C"
00052 {
00053 void qpoases( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00054 int *nV, int* nC, int* nWSR,
00055 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00056 );
00057
00058 void init( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00059 int* nV, int* nC, int* nWSR,
00060 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00061 );
00062 void initSB( real_t* H, real_t* g, real_t* lb, real_t* ub,
00063 int* nV, int* nWSR,
00064 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00065 );
00066 void initVM( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00067 int* nV, int* nC, int* nWSR,
00068 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00069 );
00070
00071 void hotstart( real_t* g, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00072 int* nWSR,
00073 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00074 );
00075 void hotstartSB( real_t* g, real_t* lb, real_t* ub,
00076 int* nWSR,
00077 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00078 );
00079 void hotstartVM( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00080 int* nWSR,
00081 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00082 );
00083
00084 void cleanupp( );
00085 void cleanupSB( );
00086 void cleanupVM( );
00087 }
00088
00089
00090
00091
00092
00093
00094 void transformA( real_t* A, int nV, int nC )
00095 {
00096 int i, j;
00097
00098 real_t* A_tmp = new real_t[nC*nV];
00099
00100 for( i=0; i<nV*nC; ++i )
00101 A_tmp[i] = A[i];
00102
00103 for( i=0; i<nC; ++i )
00104 for( j=0; j<nV; ++j )
00105 A[i*nV + j] = A_tmp[j*nC + i];
00106
00107 delete[] A_tmp;
00108
00109 return;
00110 }
00111
00112
00113
00114
00115
00116 int getStatus( returnValue returnvalue )
00117 {
00118 switch ( returnvalue )
00119 {
00120 case SUCCESSFUL_RETURN:
00121 return 0;
00122
00123 case RET_MAX_NWSR_REACHED:
00124 return 1;
00125
00126 case RET_INIT_FAILED_INFEASIBILITY:
00127 case RET_HOTSTART_STOPPED_INFEASIBILITY:
00128 return -2;
00129
00130 case RET_INIT_FAILED_UNBOUNDEDNESS:
00131 case RET_HOTSTART_STOPPED_UNBOUNDEDNESS:
00132 return -3;
00133
00134 default:
00135 return -1;
00136 }
00137 }
00138
00139
00140
00141
00142
00143 void qpoases( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00144 int *nV, int* nC, int* nWSR,
00145 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00146 )
00147 {
00148
00149 transformA( A, *nV,*nC );
00150
00151
00152 QProblem single_qp( *nV,*nC );
00153 single_qp.setPrintLevel( PL_LOW );
00154 returnValue returnvalue = single_qp.init( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
00155
00156
00157 single_qp.getPrimalSolution( x );
00158 *obj = single_qp.getObjVal( );
00159 *status = getStatus( returnvalue );
00160 *nWSRout = *nWSR;
00161 single_qp.getDualSolution( y );
00162
00163 return;
00164 }
00165
00166
00167
00168
00169
00170 void init( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00171 int* nV, int* nC, int* nWSR,
00172 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00173 )
00174 {
00175 cleanupp( );
00176
00177
00178 transformA( A, *nV,*nC );
00179
00180
00181 qp = new QProblem( *nV,*nC );
00182 qp->setPrintLevel( PL_LOW );
00183 returnValue returnvalue = qp->init( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
00184
00185
00186 qp->getPrimalSolution( x );
00187 *obj = qp->getObjVal( );
00188 *status = getStatus( returnvalue );
00189 *nWSRout = *nWSR;
00190 qp->getDualSolution( y );
00191
00192 return;
00193 }
00194
00195
00196
00197
00198
00199 void initSB( real_t* H, real_t* g, real_t* lb, real_t* ub,
00200 int* nV, int* nWSR,
00201 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00202 )
00203 {
00204 cleanupSB( );
00205
00206
00207 qpb = new QProblemB( *nV );
00208 qpb->setPrintLevel( PL_LOW );
00209 returnValue returnvalue = qpb->init( H,g,lb,ub, *nWSR,0 );
00210
00211
00212 qpb->getPrimalSolution( x );
00213 *obj = qpb->getObjVal( );
00214 *status = getStatus( returnvalue );
00215 *nWSRout = *nWSR;
00216 qpb->getDualSolution( y );
00217
00218 return;
00219 }
00220
00221
00222
00223
00224
00225 void initVM( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00226 int* nV, int* nC, int* nWSR,
00227 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00228 )
00229 {
00230 cleanupVM( );
00231
00232
00233 transformA( A, *nV,*nC );
00234
00235
00236 sqp = new SQProblem( *nV,*nC );
00237 sqp->setPrintLevel( PL_LOW );
00238 returnValue returnvalue = sqp->init( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
00239
00240
00241 sqp->getPrimalSolution( x );
00242 *obj = sqp->getObjVal( );
00243 *status = getStatus( returnvalue );
00244 *nWSRout = *nWSR;
00245 sqp->getDualSolution( y );
00246
00247 return;
00248 }
00249
00250
00251
00252
00253
00254 void hotstart( real_t* g, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00255 int* nWSR,
00256 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00257 )
00258 {
00259
00260 if ( qp == 0 )
00261 {
00262 *status = -1;
00263 return;
00264 }
00265
00266
00267 returnValue returnvalue = qp->hotstart( g,lb,ub,lbA,ubA, *nWSR,0 );
00268
00269
00270 qp->getPrimalSolution( x );
00271 *obj = qp->getObjVal( );
00272 *status = getStatus( returnvalue );
00273 *nWSRout = *nWSR;
00274 qp->getDualSolution( y );
00275
00276 return;
00277 }
00278
00279
00280
00281
00282
00283 void hotstartSB( real_t* g, real_t* lb, real_t* ub,
00284 int* nWSR,
00285 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00286 )
00287 {
00288
00289 if ( qpb == 0 )
00290 {
00291 *status = -1;
00292 return;
00293 }
00294
00295
00296 returnValue returnvalue = qpb->hotstart( g,lb,ub, *nWSR,0 );
00297
00298
00299 qpb->getPrimalSolution( x );
00300 *obj = qpb->getObjVal( );
00301 *status = getStatus( returnvalue );
00302 *nWSRout = *nWSR;
00303 qpb->getDualSolution( y );
00304
00305 return;
00306 }
00307
00308
00309
00310
00311
00312 void hotstartVM( real_t* H, real_t* g, real_t* A, real_t* lb, real_t* ub, real_t* lbA, real_t* ubA,
00313 int* nWSR,
00314 real_t* x, real_t* obj, int* status, int* nWSRout, real_t* y
00315 )
00316 {
00317
00318 if ( sqp == 0 )
00319 {
00320 *status = -1;
00321 return;
00322 }
00323
00324
00325 transformA( A, sqp->getNV( ),sqp->getNC( ) );
00326
00327
00328 returnValue returnvalue = sqp->hotstart( H,g,A,lb,ub,lbA,ubA, *nWSR,0 );
00329
00330
00331 sqp->getPrimalSolution( x );
00332 *obj = sqp->getObjVal( );
00333 *status = getStatus( returnvalue );
00334 *nWSRout = *nWSR;
00335 sqp->getDualSolution( y );
00336
00337 return;
00338 }
00339
00340
00341
00342
00343
00344 void cleanupp( )
00345 {
00346
00347 if ( qp != 0 )
00348 {
00349 delete qp;
00350 qp = 0;
00351 }
00352
00353 return;
00354 }
00355
00356
00357
00358
00359
00360 void cleanupSB( )
00361 {
00362 if ( qpb != 0 )
00363 {
00364 delete qpb;
00365 qpb = 0;
00366 }
00367
00368 return;
00369 }
00370
00371
00372
00373
00374
00375 void cleanupVM( )
00376 {
00377 if ( sqp != 0 )
00378 {
00379 delete sqp;
00380 sqp = 0;
00381 }
00382
00383 return;
00384 }
00385
00386
00387
00388
00389