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

Francis Carr fcarr at itasoftware.com
Thu Oct 14 11:43:29 EDT 2010


----- "John Forrest" <john.forrest at fastercoin.com> wrote:
> 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.

Hmmm.  I think I may be creating a ClpSimplex instance that is,
somehow, only partially initialized?



I wrote a function "read_GLPK" that will read a file in GLPK's
DIMACS-based format and create a ClpSimplex instance.  Here is my
"main" function to test it:

|  ClpSimplex *read_GLPK(const char *filename, int & errorCode);
|  
|  int main(int argc, const char *argv[])
|  {
|    ClpSimplex *original = NULL;
|    int errorCode;
|   
|    std::cout << "-- Read and solve the problem." << std::endl;
|    original = read_GLPK(argv[1], errorCode);
|    original->primal();
|    original->writeBasis("sav.bas");
|   
|    std::cout << "-- Re-read the problem." << std::endl;
|    ClpSimplex *restore = NULL;
|    restore = read_GLPK(argv[1], errorCode);
|   
|    std::cout << "-- Restore the basis (first time)." << std::endl;
|    restore->readBasis("sav.bas");
|    restore->primal(1);
|   
|    std::cout << "-- Restore the basis (second time)." << std::endl;
|    restore->readBasis("sav.bas");
|    restore->primal(1);
|   
|    return 0;
|  }

(For this email, I removed some error-checking --- the complete
source-code is attached.)


What I observe is that the *first* "readBasis" leads to a re-solve,
while the *second* "readBasis" does not.  For example, I used GLPK to
convert 25fv47.mps into GLPK's format, and got the following:

|  -- Read and solve the problem.
|  Clp0006I 0  Obj 0 Primal inf 14357 (201) Dual inf 2.064e+14 (781)
|  Clp0006I 200  Obj 299.743 Primal inf 7998.02 (228) Dual inf 1.16854e+12 (801)
|  ...
|  Clp0006I 1175  Obj 7421.59 Primal inf 4.6816 (12) Dual inf 3.5957e+09 (478)
|  Clp0006I 1375  Obj 7358.98 Dual inf 39496.5 (477)
|  ...
|  Clp0006I 2175  Obj 5502.31 Dual inf 30.4686 (49)
|  Clp0006I 2196  Obj 5501.85
|  Clp0000I Optimal - objective value 5501.85
|   
|  -- Re-read the problem.
|   
|  -- Restore the basis (first time).
|  Coin0001I At line 1 NAME          25FV47
|  Coin0001I At line 654 ENDATA
|  Clp0006I 0  Obj 0 Primal inf 14357 (201) Dual inf 2.04913e+14 (783)
|  Clp0029I End of values pass after 17 iterations
|  Clp0006I 17  Obj 587.772 Primal inf 14167.9 (204) Dual inf 2.04817e+14 (736)
|  ...
|  Clp0006I 1017  Obj 9398.74 Primal inf 9.57172 (26) Dual inf 5.64677e+12 (463)
|  Clp0006I 1217  Obj 9094.83 Dual inf 320319 (482)
|  ...
|  Clp0006I 1969  Obj 5512.93 Dual inf 452.358 (209)
|  Clp0006I 2036  Obj 5501.85
|  Clp0000I Optimal - objective value 5501.85
|   
|  -- Restore the basis (second time).
|  Coin0001I At line 1 NAME          25FV47
|  Coin0001I At line 654 ENDATA
|  Clp0006I 0  Obj 5501.85 Dual inf 4360.55 (241)
|  Clp0029I End of values pass after 18 iterations
|  Clp0006I 18  Obj 5501.85 Dual inf 1540.43 (14)
|  Clp0006I 23  Obj 5501.85
|  Clp0000I Optimal - objective value 5501.85

I have gotten similar results for other LP instances, including
25fv47-flipped.glp (this is just 25fv47.mps, but with all objective
coeff's negated, and maximized instead of minimized), and
efronDice.glp (a tiny LP that computes a variant of Efron's dice,
http://mathworld.wolfram.com/EfronsDice.html).



Almost all of the function "read_GLPK" is devoted to parsing and
error-checking an LP problem in GLPK's format.  Just a tiny piece
(lines 297--320) actually creates a ClpSimplex instance.  Please could
I ask you to examine that tiny piece?  I would be happy to contribute
this code to COIN-Clp.

 -- FC
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_basis.cpp
Type: text/x-c++src
Size: 9839 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 25fv47.glp
Type: application/octet-stream
Size: 216563 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 25fv47-flipped.mps
Type: application/octet-stream
Size: 366915 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 25fv47-flipped.glp
Type: application/octet-stream
Size: 217853 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: efronDice.mod
Type: audio/x-mod
Size: 545 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment.mod>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: efronDice.mps
Type: application/octet-stream
Size: 1465 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: efronDice.glp
Type: application/octet-stream
Size: 667 bytes
Desc: not available
URL: <http://list.coin-or.org/pipermail/clp/attachments/20101014/31b8cf8d/attachment-0004.obj>


More information about the Clp mailing list