[Clp] Problem with basic optimization both in C++ and reading from mps

Andy Somogyi andy.somogyi at gmail.com
Fri Feb 20 03:29:03 EST 2015


Hi Guys, I’ve tried it both ways, and it never seems to change the objective using the command line clp, 

But the interesting thing is that if I hard-code it into C++ with the attached code, and flip the signs on the objective function, then it seems to work. So, the objective optimization is always a minimization in Clp?


Here is the output, first with the pos cooef, then with a neg cooef changed in the mps:

./clp exmip1.mps -primalsimplex
Coin LP version 1.16, build Feb 17 2015
command line - ./clp test.mps -primalsimplex
At line 20 NAME          EXAMPLE
At line 21 ROWS
At line 25 COLUMNS
At line 31 RHS
At line 35 BOUNDS
At line 41 ENDATA
Problem EXAMPLE has 2 rows, 4 columns and 6 elements
Model was imported from ./exmip1.mps in 0.000162 seconds
Presolve 0 (-2) rows, 0 (-4) columns and 0 (-6) elements
Empty problem - 0 rows, 0 columns and 0 elements
Optimal - objective value 0
After Postsolve, objective 0, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective 0 - 0 iterations time 0.002, Presolve 0.00
./clp exmip1.mps -primalsimplex
Coin LP version 1.16, build Feb 17 2015
command line - ./clp exmip1.mps -primalsimplex
At line 20 NAME          EXAMPLE
At line 21 ROWS
At line 25 COLUMNS
At line 31 RHS
At line 35 BOUNDS
At line 41 ENDATA
Problem EXAMPLE has 2 rows, 4 columns and 6 elements
Model was imported from ./test.mps in 0.000343 seconds
Presolve 0 (-2) rows, 0 (-4) columns and 0 (-6) elements
Empty problem - 0 rows, 0 columns and 0 elements
Optimal - objective value -1
After Postsolve, objective -1, infeasibilities - dual 0 (0), primal 0 (0)
Optimal objective -1 - 0 iterations time 0.002, Presolve 0.00


At first I hard-coded it into C++, with the following code, and same results, which are attached below. 

int main(int argc, const char *argv[])
{

    ClpSimplex  model;

/*
Maximize
objective1_objf:
+ 1.0 R2

Subject To
 A: +R1 +0R2 -X1 -X2 = 0
 B: 0R1 -R2  +X1 +X2 = 0
Bounds
 R1 <= 1.0
 0.0 <= R2 <= +inf
 0.0 <= X1 <= +inf
 0.0 <= X2 <= +inf

1  0 −1 −1
0 −1  1  1

 */


    int numberRows = 2;
    int numberColumns = 4;
    int numberElements = 6;
    // matrix data - column ordered
    int start[5] =       {0, 1, 2, 4, 6};
    int length[4] =      {1, 1, 2, 2};
    int rows[6] =        {0,   1,   0,  1,   0,  1 };
    double elements[6] = {1., -1., -1., 1., -1., 1.};
    CoinPackedMatrix matrix(true, numberRows, numberColumns, numberElements, elements, rows, start, length);


    for(int i = 0; i < numberRows; ++i) {
    	for(int j = 0; j < numberColumns; j++) {
    		printf("%i, %i, %f\n", i, j, matrix.getCoefficient(i, j));
    	}
    }

    // Have to flip the sign on the objective, is this right, seems to work???????
    double objective[4] = {0, -1, 0, 0};
    double rowLower[2] = {0., 0.};
    double rowUpper[2] = {0, 0};
    double colLower[4] = {0, 0, 0, 0};
    double colUpper[4] = {1., COIN_DBL_MAX, COIN_DBL_MAX, COIN_DBL_MAX};
    // load problem
    model.loadProblem(matrix, colLower, colUpper, objective,
                      rowLower, rowUpper);

    // Solve
    model.initialSolve();

    // Solve - primal as primal feasible
    model.primal(1);

    // Solution
    const double * solution = model.primalColumnSolution();
    for (int i = 0; i < numberColumns; i++)
              printf("Column %d has value %g\n", i, solution[i]);

}


And here is the output:

0, 0, 1.000000
0, 1, 0.000000
0, 2, -1.000000
0, 3, -1.000000
1, 0, 0.000000
1, 1, -1.000000
1, 2, 1.000000
1, 3, 1.000000
Coin0506I Presolve 0 (-2) rows, 0 (-4) columns and 0 (-6) elements
Clp3002W Empty problem - 0 rows, 0 columns and 0 elements
Clp0000I Optimal - objective value -1
Coin0511I After Postsolve, objective -1, infeasibilities - dual 0 (0), primal 0 (0)
Clp0032I Optimal objective -1 - 0 iterations time 0.002, Presolve 0.00
Clp0006I 0  Obj -1
Clp0000I Optimal - objective value -1
Column 0 has value 1
Column 1 has value 1
Column 2 has value 1
Column 3 has value 0


B


On Feb 20, 2015, at 3:13 AM, Babak Moazzez <bmoazzez at ucdavis.edu> wrote:

> In the MPS file you should change 
> 
>  R2        OBJ                 1.0   
> 
> to 
> 
>  R2        OBJ                - 1.0  .
> 
> MPS default is minimization! so this minimizes -R2 which is equivalent to Maximizing R2.
> 
> 
> On Thu, Feb 19, 2015 at 11:44 PM, Andy Somogyi <andy.somogyi at gmail.com> wrote:
> Hi All,
> 
> I’m trying to use Clp, works fine for the built-in examples, but I can’t seem to get this simple attached problem to work. I’ve tried hard-coding this in C++, following the modify.cpp example, and I’ve tried reading it form a mps file, using either the command line clp program, or direction into the ClpModel object via readMps.
> 
> It always results in a zero solution, but this problem has an analytic solution of [1, 1, 1, 0], and Mathematica finds this solution just fine if I import the mps and use NMinimise.
> 
> Any ideas why this simple problem won’t converge to the correct solution in Clp.
> 
> Thanks
> 
> Here is the mps:
> 
> ************************************************************************
> *
> *  Maximize
> *  objective1_objf:
> *  + 1.0 R2
> *
> * Subject To
> *  A: +R1      -X1 -X2 = 0
> *  B:     -R2  +X1 +X2 = 0
> *
> *  Bounds
> *  0.0 <= R1 <= 1.0
> *  0.0 <= R2 <= +inf
> *  0.0 <= X1 <= +inf
> *  0.0 <= X2 <= +inf
> *
> ************************************************************************
> NAME          EXAMPLE
> ROWS
>  N  OBJ
>  E  A
>  E  B
> COLUMNS
>     R1        A                  1.0
>     R2        OBJ                1.0   B                 -1.0
>     X1        A                 -1.0   B                  1.0
>     X2        A                 -1.0   B                  1.0
> 
> RHS
>     RHS1      A                  0
>     RHS1      B                  0
> 
> BOUNDS
>  LO BND1      R1                 0
>  UP BND1      R1                 1
>  LO BND1      R2                 0
>  LO BND1      X1                 0
>  LO BND1      X2                 0
> ENDATA
> 
> 
> _______________________________________________
> Clp mailing list
> Clp at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/clp
> 
> 
> 
> -- 
> Babak Moazzez
> Post Doctoral Scholar
> University of California Davis
> 
> Email: bmoazzez at ucdavis.edu
> Tel: (530) 752 5076

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/clp/attachments/20150220/abbe881e/attachment-0001.html>


More information about the Clp mailing list