36 #define SOLVE_SPARSE 0 40 #include <qpOASES.hpp> 49 double *vals,
int *iRow,
int *jCol,
50 double *vals_hbf,
int *iRow_hbf,
int *jCol_hbf )
55 for( k=0; k<n+1; k++ )
57 for( k=0; k<nnz; k++ )
64 for( k=0; k<nnz; k++ )
72 for( k=n-1; k>-1; k-- )
73 jCol_hbf[k] = jCol_hbf[k+1] - jCol_hbf[k];
76 for( k=0; k<nnz; k++ )
82 vals_hbf[ii] = vals[k];
88 for( k=n-1; k>0; k-- )
89 jCol_hbf[k] = jCol_hbf[k-1];
111 char *fname =
"prob/OUTSDIF.d";
117 int e_order = 0, l_order = 0, v_order = 0;
127 double *hesDense, *jacDense;
129 #if SOLVE_SCHUR || SOLVE_SPARSE 132 double *hesVal, *jacVal;
133 int *hesIndCol, *hesIndRow;
134 int *jacIndCol, *jacIndRow;
146 FORTRAN_open( &funit, fname, &ierr );
148 printf(
"Error opening file OUTSDIF.d.\nAborting.\n");
153 CUTEST_cdimen( &status, &funit, &nVar, &nCon );
155 printf(
"** CUTEst error, status = %d, aborting\n", status);
162 xInit =
new double[nVar];
163 yInit =
new double[nCon];
164 lb =
new double[nVar];
165 ub =
new double[nVar];
166 lbA =
new double[nCon];
167 ubA =
new double[nCon];
168 isEq =
new logical[nCon];
169 isLinear =
new logical[nCon];
171 CUTEST_csetup( &status, &funit, &iout, &io_buffer,
172 &nVar, &nCon, xInit, lb, ub,
173 yInit, lbA, ubA, isEq, isLinear,
174 &e_order, &l_order, &v_order );
176 printf(
"** CUTEst_csetup: error, status = %d, aborting\n", status);
182 g =
new double[nVar];
183 double *xZero =
new double[nVar];
184 for(
int k=0; k<nVar; k++ ) xZero[k] = 0.0;
185 CUTEST_cofg( &status, &nVar, xZero, &obj, g, &grad );
187 printf(
"** CUTEst_cofg: error, status = %d, aborting\n", status);
191 double *cVal =
new double[nCon];
192 #if SOLVE_SPARSE || SOLVE_SCHUR 195 double *J_val =
new double[lj];
196 int *J_var =
new int[lj];
197 int *J_fun =
new int[lj];
202 CUTEST_ccfsg( &status, &nVar, &nCon, xZero, cVal, &nnzj, &lj, J_val, J_var, J_fun, &grad );
204 printf(
"** CUTEst_ccfsg: error, status = %d, aborting\n", status);
208 for(
int k=0; k<nCon; k++ )
210 lbA[k] = ubA[k] = -cVal[k];
212 jacIndCol =
new int[nVar+1];
213 jacIndRow =
new int[nnzj];
214 jacVal =
new double[nnzj];
215 convertTripletToHbf( nCon, nVar, nnzj, J_val, J_fun, J_var, jacVal, jacIndRow, jacIndCol );
224 double *
H_val =
new double[lh];
225 int *H_col =
new int[lh];
226 int *H_row =
new int[lh];
227 CUTEST_csh( &status, &nVar, &nCon, xInit, yInit, &nnzh, &lh, H_val, H_row, H_col );
229 printf(
"** CUTEst_csh: error, status = %d, aborting\n", status);
234 for(
int k=0; k<nnzh; k++ )
235 if( H_row[k] != H_col[k] )
237 H_val[nnzh+count] = H_val[k];
238 H_col[nnzh+count] = H_row[k];
239 H_row[nnzh+count] = H_col[k];
244 hesIndCol =
new int[nVar+1];
245 hesIndRow =
new int[nnzh];
246 hesVal =
new double[nnzh];
247 convertTripletToHbf( nVar, nVar, nnzh, H_val, H_row, H_col, hesVal, hesIndRow, hesIndCol );
259 jacDense =
new double[nCon*nVar];
260 CUTEST_ccfg( &status, &nVar, &nCon, xZero, cVal, &trans, &nVar, &nCon, jacDense, &grad );
264 hesDense =
new double[nVar*nVar];
265 CUTEST_cdh( &status, &nVar, &nCon, xInit, yInit, &nVar, hesDense );
267 printf(
"** CUTEst_cdh: error, status = %d, aborting\n", status);
289 #if SOLVE_SCHUR || SOLVE_SPARSE 295 double *
xOpt =
new double[nVar];
296 double *yOpt =
new double[nVar+nCon];
301 A_d =
new DenseMatrix( nCon, nVar, nVar, jacDense );
302 H_d =
new SymDenseMat( nVar, nVar, nVar, hesDense );
304 #if SOLVE_SCHUR || SOLVE_SPARSE 305 A_s =
new SparseMatrix( nCon, nVar, jacIndRow, jacIndCol, jacVal );
306 H_s =
new SymSparseMat( nVar, nVar, hesIndRow, hesIndCol, hesVal );
312 double eps = 2.0e-16;
313 for(
int k=0; k<nVar; k++ )
315 if(
getAbs( xInit[k] - lb[k] ) < eps )
317 else if(
getAbs( xInit[k] - ub[k] ) < eps )
325 for(
int k=0; k<nCon; k++ )
327 if(
getAbs( cVal[k] - lbA[k] ) < eps )
329 else if(
getAbs( cVal[k] - ubA[k] ) < eps )
355 double maxTime = 100000;
369 opts.enableEqualities =
BT_TRUE;
385 opts.numRefinementSteps = 3;
389 opts.enableInertiaCorrection =
BT_TRUE;
390 opts.rcondSMin = 1.0e-14;
396 struct timeval startTime;
397 struct timeval endTime;
399 gettimeofday(&startTime, NULL);
401 printf(
"\n----------Begin Standard version with dense matrices----------\n" );
406 for(
int k=0; k<nVar; k++ )
411 for(
int k=0; k<nCon; k++ ) yOpt[k+nVar] = yInit[k];
414 ret = qpDense.
init( H_d, g, A_d, lb, ub, lbA, ubA, nWSR, &time, xOpt, yOpt, &bOpt, &cOpt );
417 printf(
"\n-----------End Standard version with dense matrices-----------\n" );
421 printf(
"\n----------Begin Schur complement version----------\n" );
426 for(
int k=0; k<nVar; k++ )
431 for(
int k=0; k<nCon; k++ ) yOpt[k+nVar] = yInit[k];
435 ret = qpSchur.
init( H_s, g, A_s, lb, ub, lbA, ubA, nWSR, &time );
438 printf(
"\n\n-----------End Schur complement version-----------\n" );
442 printf(
"\n----------Begin Standard version with sparse matrices----------\n" );
447 for(
int k=0; k<nVar; k++ )
452 for(
int k=0; k<nCon; k++ ) yOpt[k+nVar] = yInit[k];
455 ret = qpSparse.
init( H_s, g, A_s, lb, ub, lbA, ubA, nWSR, &time, xOpt, yOpt, &bOpt, &cOpt );
458 printf(
"\n-----------End Standard version with sparse matrices-----------\n" );
460 gettimeofday(&endTime, NULL);
462 elapsedTime = (endTime.tv_sec*1000000 + (endTime.tv_usec)) -
463 (startTime.tv_sec*1000000 + (startTime.tv_usec));
464 printf(
"Took %g seconds.\n", elapsedTime/1000000.0 );
479 #if SOLVE_SCHUR || SOLVE_SPARSE #define USING_NAMESPACE_QPOASES
returnValue setType(int i, SubjectToType value)
Interfaces matrix-vector operations tailored to symmetric sparse matrices.
returnValue init(const real_t *const _H, const real_t *const _g, const real_t *const _A, const real_t *const _lb, const real_t *const _ub, const real_t *const _lbA, const real_t *const _ubA, int &nWSR, const real_t *const yOpt=0, real_t *const cputime=0)
Manages working sets of constraints.
Implements the online active set strategy for QPs with varying matrices.
Allows to pass back messages to the calling function.
Interfaces matrix-vector operations tailored to symmetric dense matrices.
returnValue setOptions(const Options &_options)
Interfaces matrix-vector operations tailored to general dense matrices.
Interfaces matrix-vector operations tailored to general sparse matrices.
Provides a generic way to set and pass user-specified options.
int convertTripletToHbf(int m, int n, int nnz, double *vals, int *iRow, int *jCol, double *vals_hbf, int *iRow_hbf, int *jCol_hbf)
returnValue setStatus(int i, SubjectToStatus value)
Manages working sets of bounds (= box constraints).
Implements the online active set strategy for QPs with varying, sparse matrices.