SOLVED: Different results between glp_simplex() and gplsol

2024-04-11 Thread Edscott Wilson
Problem solved. Stupid mistakes are the hardest to find, at least for me.
A single column had a different bound specification in my call to
glp_simplex().
Different problems, different results. Same problem, same results.

Anyways, glpk is amazing.

Thank you all developers for such fine work!

-- 

Dr. Edscott Wilson Garcia
Reservoir Engineering
Mexican Petroleum Institute


Different results between glp_simplex() and gplsol

2024-04-11 Thread Edscott Wilson
Hello,

If I construct a matrix for a problem to feed glp_simplex() and run,
[code]
  glp_smcp parm;
  glp_init_smcp();
  int retval = glp_simplex(lp, );
  double *x = calloc(vectorSize(data)+1, sizeof(double));
  double z = glp_get_obj_val(lp);
  fprintf(stdout, "\nZ=%lf\n", z);
[/code]
I get the following:

GLPK Simplex Optimizer 5.0
15 rows, 17 columns, 33 non-zeros
  0: obj =   0.0e+00 inf =   1.168e+03 (4)
 13: obj =   2.72000e+01 inf =   1.743e+02 (1)
LP HAS NO PRIMAL FEASIBLE SOLUTION
Z=27.20

But if I use the same matrix information to generate a CPLEX format file
and run $ glpsol --lp  cplex.lp -o out, I get:

GLPSOL--GLPK LP/MIP Solver 5.0
Reading problem data from 'cplex.lp'...
15 rows, 17 columns, 33 non-zeros
36 lines were read
GLPK Simplex Optimizer 5.0
15 rows, 17 columns, 33 non-zeros
Preprocessing...
1 row, 2 columns, 2 non-zeros
Scaling...
 A: min|aij| =  1.000e+00  max|aij| =  8.218e+02  ratio =  8.218e+02
GM: min|aij| =  1.000e+00  max|aij| =  1.000e+00  ratio =  1.000e+00
EQ: min|aij| =  1.000e+00  max|aij| =  1.000e+00  ratio =  1.000e+00
Constructing initial basis...
Size of triangular part is 1
* 0: obj =   1.71400e+02 inf =   0.000e+00 (1)
* 1: obj =   2.72000e+01 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.0 Mb (40400 bytes)
Writing basic solution to 'out'...

And the optimal solution is Z=27.2

I suppose I am missing something in the call to glp_simplex(), but what?

This is the CPLEX format:

MINIMIZE Z :  + x11 + x12 + x13 + x14
SUBJECT TO
  r1 : + 821.80 x1 + 821.80 x2 + 821.80 x9 = 821.80
  r2 : + 174.30 x3 + 174.30 x4 + 174.30 x10 = 174.30
  r3 : + 27.20 x5 + 27.20 x6 = 27.20
  r4 : + 144.20 x7 + 144.20 x8 = 144.20
  r5 : + 821.80 x1 + 174.30 x3 - 27.20 x5 - 144.20 x7 +
1.00 x11 + 1.00 x13 - 1.00 x16 = 0.00
  r6 : + 821.80 x2 + 174.30 x4 - 27.20 x6 - 144.20 x8 +
1.00 x12 + 1.00 x14 - 1.00 x17 = 0.00
  r7 : - 28.00 x3 >= 0.00
  r8 : - 40.00 x4 >= 0.00
  r9 : - 7.20 x7 >= 0.00
  r10 : - 34.70 x11 >= 0.00
  r11 : - 46.70 x12 >= 0.00
  r12 : - 0.165000 x1 >= 0.00
  r13 : - 0.232000 x3 >= 0.00
  r14 : - 0.067000 x4 >= 0.00
  r15 : - 0.016000 x6 >= 0.00
BOUNDS
 0 <= x1 <= 1
 0 <= x2 <= 1
 0 <= x3 <= 1
 0 <= x4 <= 1
 0 <= x5 <= 1
 0 <= x6 <= 1
 0 <= x7 <= 1
 0 <= x8 <= 1
 0 <= x9 <= 1
 0 <= x10 <= 1
 0 <= x11
 0 <= x12
 0 <= x13
 0 <= x14
 0 <= x15
 0 <= x16
 0 <= x17
END

And this is the matrix information from which the CPLEX format is
constructed:
\* GLPK matrix:
\* ia[1]=1, ja[1]=1, ra[1]=821.80
\* ia[2]=1, ja[2]=2, ra[2]=821.80
\* ia[3]=1, ja[3]=9, ra[3]=821.80
\* ia[4]=2, ja[4]=3, ra[4]=174.30
\* ia[5]=2, ja[5]=4, ra[5]=174.30
\* ia[6]=2, ja[6]=10, ra[6]=174.30
\* ia[7]=3, ja[7]=5, ra[7]=27.20
\* ia[8]=3, ja[8]=6, ra[8]=27.20
\* ia[9]=4, ja[9]=7, ra[9]=144.20
\* ia[10]=4, ja[10]=8, ra[10]=144.20
\* ia[11]=5, ja[11]=15, ra[11]=0.00
\* ia[12]=5, ja[12]=1, ra[12]=821.80
\* ia[13]=5, ja[13]=3, ra[13]=174.30
\* ia[14]=5, ja[14]=11, ra[14]=1.00
\* ia[15]=5, ja[15]=13, ra[15]=1.00
\* ia[16]=5, ja[16]=5, ra[16]=-27.20
\* ia[17]=5, ja[17]=7, ra[17]=-144.20
\* ia[18]=5, ja[18]=16, ra[18]=-1.00
\* ia[19]=6, ja[19]=2, ra[19]=821.80
\* ia[20]=6, ja[20]=4, ra[20]=174.30
\* ia[21]=6, ja[21]=12, ra[21]=1.00
\* ia[22]=6, ja[22]=14, ra[22]=1.00
\* ia[23]=6, ja[23]=6, ra[23]=-27.20
\* ia[24]=6, ja[24]=8, ra[24]=-144.20
\* ia[25]=6, ja[25]=17, ra[25]=-1.00
\* ia[26]=7, ja[26]=3, ra[26]=-28.00
\* ia[27]=8, ja[27]=4, ra[27]=-40.00
\* ia[28]=9, ja[28]=7, ra[28]=-7.20
\* ia[29]=10, ja[29]=11, ra[29]=-34.70
\* ia[30]=11, ja[30]=12, ra[30]=-46.70
\* ia[31]=12, ja[31]=1, ra[31]=-0.165000
\* ia[32]=13, ja[32]=3, ra[32]=-0.232000
\* ia[33]=14, ja[33]=4, ra[33]=-0.067000
\* ia[34]=15, ja[34]=6, ra[34]=-0.016000

What am I missing in the glp_simplex call?  Or maybe I should just stick
with creating the cplex format and do an execlp()?

Any clues are warmly appreciated.




-- 

Dr. Edscott Wilson Garcia
Reservoir Engineering
Mexican Petroleum Institute