coin-or / qpOASES

Open-source C++ implementation of the recently proposed online active set strategy
GNU Lesser General Public License v2.1
365 stars 127 forks source link

SQProblem: Error when solving multiple identical QPs in a row #82

Open svigerske opened 4 years ago

svigerske commented 4 years ago

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.

biagio-trimarchi commented 6 months ago

@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.

svigerske commented 6 months ago

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.