qpOASES icon indicating copy to clipboard operation
qpOASES copied to clipboard

SQProblem: Error when solving multiple identical QPs in a row

Open svigerske opened this issue 5 years ago • 2 comments

Issue created by migration from Trac.

Original creator: hebel

Original creation time: 2018-01-30 18:28:28

Assignee: ferreau

Version: 3.2.1

When using the SQProblem class, it may still happen that one wants to solve multiple identical QPs in a row. However, currently, it seems that the solution of the subsequent QPs is then terminated with an error. This can be reproduced by adding some lines to the source file "example1a.cpp", namely, replacing

	example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );

by

        example.init( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
	real_t optimizer[2];
	example.hotstart( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
	example.getPrimalSolution( optimizer );
	printf( "\nxOpt = [ %e, %e ];  objVal = %e\n\n", optimizer[0],optimizer[1],example.getObjVal() );
	example.hotstart( H,g,A,lb,ub,lbA,ubA, nWSR,0 );
	example.getPrimalSolution( optimizer );
	printf( "\nxOpt = [ %e, %e ];  objVal = %e\n\n", optimizer[0],optimizer[1],example.getObjVal() );

This generates the output (g++ 6.3.0; Debian Stretch)

####################   qpOASES  --  QP NO.   1   #####################

    Iter   |    StepLength    |       Info       |   nFX   |   nAC    
 ----------+------------------+------------------+---------+--------- 
       0   |   5.833333e-01   |   ADD CON    0   |     1   |     1   
       1   |   1.000000e+00   |    QP SOLVED     |     1   |     1   


####################   qpOASES  --  QP NO.   2   #####################

    Iter   |    StepLength    |       Info       |   nFX   |   nAC    
 ----------+------------------+------------------+---------+--------- 
       0   |   1.000000e+00   |    QP SOLVED     |     1   |     1   

xOpt = [ 5.000000e-01, -1.500000e+00 ];  objVal = -6.250000e-02

ERROR:  Maximum number of working set recalculations performed

xOpt = [ 5.000000e-01, -1.500000e+00 ];  objVal = 1.000000e+20

->ERROR:  Unable to perform homotopy as previous QP is not solved

xOpt = [ 0.000000e+00, 0.000000e+00 ];  objVal = 1.000000e+20

Crucially, in the end, also the optimizer has a wrong value. If the old value would still be present, the above issue would not be a real problem, apart from the misleading error message.

On the present test computer, this behavior is both observable with versions 3.2.0 and 3.2.1. At the same time, when compiling with aggressive optimization options, in the context of a larger program and the above situation, QPoases even seems to crash, providing an error relating to a division by zero during Cholesky factorization (similar to an older ticket by another user).

As a side note, it seems that the static and dynamic libraries as compiled with (the zipped) version 3.2.1 seem to miss some functions (similar to an older ticket by another user), while it works fine with version 3.2.0.

svigerske avatar Feb 23 '20 07:02 svigerske

@svigerske I know that the post is 3 years old, but I faced the same problem, so if anyone stumbles upon this issue, she will find the solution.

This is not a bug, the problem is that the variable nWSR will contain the number of active set recalculation performed (in you case 1) after the function has been called, so if you do not set the variable again it will perform only the iteration 0. This behavior is documented on the official manual.

Between each call of the init function (or hotstart) you need assign the variable again.

biagio-trimarchi avatar Jan 08 '24 11:01 biagio-trimarchi

It's actually 6 years old. I'm shown as creator of the issue, because I migrated the issues from the Trac system to GitHub. I assume the qpOASES will eventually take care of it and maybe close it.

svigerske avatar Jan 09 '24 07:01 svigerske