[Clp] Save and restore an LP solution/basis?

John Forrest john.forrest at fastercoin.com
Sat Oct 9 06:11:55 EDT 2010


Francis,

It all seems rather odd.  Try various combinations of things such as
using the standalone solver to create the basis and then read it in with
your program and vice versa to see if you can narrow the problem down.

I used -

int main(int argc, const char *argv[])
{
     ClpSimplex  original;
     std::string mpsFileName;
     if (argc >= 2) mpsFileName = argv[1];
     else {
          exit(1);
     }
     int status = original.readMps(mpsFileName.c_str(), true);

     if (status) {
          fprintf(stdout, "Bad readMps %s\n", mpsFileName.c_str());
          exit(1);
     }
     original.primal();
     original.writeBasis("sav.bas");

     ClpSimplex  restore;
     status = restore.readMps(mpsFileName.c_str(), true);

     assert (!status);
     restore.readBasis("sav.bas");
     restore.primal();

     return 0;
}

The result with the netlib problem 25fv47 was -
Coin0001I At line 1 NAME          25FV47
Coin0001I At line 2 ROWS
Coin0001I At line 825 COLUMNS
Coin0001I At line 6774 RHS
Coin0001I At line 6919 ENDATA
Coin0002I Problem 25FV47 has 821 rows, 1571 columns and 10400 elements
Clp0027I Model was imported from /j/netlib/25fv47.mps in 0.016001
seconds
Clp0006I 0  Obj 0 Primal inf 13456.3 (201) Dual inf 8.31866e+13 (779)
Clp0006I 200  Obj 2292.38 Primal inf 6285.67 (213) Dual inf 6.11007e+11
(700)
Clp0006I 400  Obj 10294.8 Primal inf 3283.71 (140) Dual inf 1.69421e+12
(586)
Clp0006I 600  Obj 19127 Primal inf 1163.61 (101) Dual inf 8.3131e+11
(514)
Clp0006I 800  Obj 19982.5 Primal inf 78.2493 (50) Dual inf 7.47124e+10
(470)
Clp0006I 999  Obj 17909.4 Primal inf 11.0708 (13) Dual inf 1.96816e+10
(454)
Clp0006I 1199  Obj 10162.5 Dual inf 39893 (479)
Clp0006I 1399  Obj 7231.35 Dual inf 11930.1 (479)
Clp0006I 1599  Obj 6146.41 Dual inf 7529.46 (413)
Clp0006I 1799  Obj 5585.91 Dual inf 2121.01 (251)
Clp0006I 1968  Obj 5501.85
Clp0000I Optimal - objective value 5501.85
Coin0001I At line 1 NAME          25FV47
Coin0001I At line 2 ROWS
Coin0001I At line 825 COLUMNS
Coin0001I At line 6774 RHS
Coin0001I At line 6919 ENDATA
Coin0002I Problem 25FV47 has 821 rows, 1571 columns and 10400 elements
Clp0027I Model was imported from /j/netlib/25fv47.mps in 0.012001
seconds
Coin0001I At line 1 NAME          25FV47
Coin0001I At line 653 ENDATA
Clp0000I Optimal - objective value 5501.85

which is what I would expect.

I presume that in your real usage, the basis will be good but not
optimal for second problem.  I would recommend writeBasis(..,true,2) and
use primal(1) for second solve.

John Forrest






On Wed, 2010-10-06 at 13:27 -0400, Francis Carr wrote:
> I would like to save and restore an LP solution/basis.  According to my reading of the Clp API, the following seems like it *should* achieve this goal:
>   ClpSimplex original;
>   original.readMps(...);
>   original.primal(...);
>   original.writeBasis(someBasisFile);
> followed later by
>   ClpSimplex restore;
>   restore.readMps(...);
>   restore.readBasis(someBasisFile);
>   restore.primal(...);
> where I am expecting that final invocation of restore.primal(...) should *NOT* re-solve from scratch.
> 
> 
> But it doesn't work?  It always re-solves from scratch!  I have tried many variations:
>   various solvers (primal or dual or "initialSolve") with various options;
>   various options to writeBasis and readBasis;
>   replacing the basis functions with saveSolution/restoreSolution from CbcOrClpParam.cpp.
> Please, what am I doing wrong?
> 
> 
> I am using the current "stable" Clp, pulled yesterday from svn:
>   https://projects.coin-or.org/svn/Clp/stable/1.12
> The usual "configure; make" linux build went off without any problems, and "make test" was error-free.
> 
>  -- FC
> 
> _______________________________________________
> Clp mailing list
> Clp at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/clp
> 





More information about the Clp mailing list