Re: GMPL/GLPK display objective function value

2020-08-29 Thread Domingo Alvarez Duarte

Hello !

This is one proposal to return the correct value of objective function 
with constant "shift" term in GMPL.


https://github.com/mingodad/GLPK/commit/3e50da7d0c53ca377c6f796d267129809c4526bf

I'm not convinced that the way GLPK/GMPL is dealing with this issue is 
correct.


Cheers !

On 28/8/20 20:40, Domingo Alvarez Duarte wrote:

Hello !

While trying to implement multi solve statements I found that in GMPL 
the display of an objective function after solving do not show the 
optimal value.


GLPSOL warnings:

knapsack-3.glpsol:38: warning: unexpected end of file; missing end 
statement inserted


But it shows conflicting values in the output solution:

...

Objective:  Reduced_Cost = -0.47 (MINimum)

...

1 Reduced_Cost B   -1.46667

...

GMPL displays:

...

Reduced_Cost.val = -1.47

...

AMPL:

=

# 
# KNAPSACK SUBPROBLEM FOR CUTTING STOCK
# 
param roll_width > 0; # width of raw rolls

set WIDTHS;     # set of widths to be cut

param price {WIDTHS} default 0.0;

var Use {WIDTHS} /*integer*/ >= 0;

minimize Reduced_Cost:
   1 - sum {i in WIDTHS} price[i] * Use[i];

subject to Width_Limit:
   sum {i in WIDTHS} i * Use[i] <= roll_width;

data;
param roll_width := 110 ;

set WIDTHS :=
 20
 45
 50
 55
 75;
param price :=
    [20] 0.2
    [45] 0.5
    [50] 0.5
    [55] 0.5
    [75] 1
;

solve;

display Reduced_Cost;

=

AMPL output:

=

myampl-ng knapsack-3.ampl
MINOS 5.51: optimal solution found.
1 iterations, objective -0.47
Reduced_Cost = -0.47

=

GLPSOL

=

# 
# KNAPSACK SUBPROBLEM FOR CUTTING STOCK
# 
param roll_width > 0; # width of raw rolls

set WIDTHS;     # set of widths to be cut

param price {WIDTHS} default 0.0;

var Use {WIDTHS} /*integer*/ >= 0;

minimize Reduced_Cost:
   1 - sum {i in WIDTHS} price[i] * Use[i];

subject to Width_Limit:
   sum {i in WIDTHS} i * Use[i] <= roll_width;

solve;

display Reduced_Cost;

data;
param roll_width := 110 ;

set WIDTHS :=
 20
 45
 50
 55
 75;
param price :=
    [20] 0.2
    [45] 0.5
    [50] 0.5
    [55] 0.5
    [75] 1
;

=

GLPSOL output:

=

myglpsol -m knapsack-3.glpsol -o knapsack-3.sol
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
 -m knapsack-3.glpsol -o knapsack-3.sol
Reading model section from knapsack-3.glpsol...
Reading data section from knapsack-3.glpsol...
knapsack-3.glpsol:38: warning: unexpected end of file; missing end 
statement inserted

38 lines were read
Generating Reduced_Cost...
Generating Width_Limit...
Model has been successfully generated
glp_mpl_build_prob: row Reduced_Cost; constant term 1 ignored
GLPK Simplex Optimizer, v4.65
2 rows, 5 columns, 10 non-zeros
Preprocessing...
1 row, 5 columns, 5 non-zeros
Scaling...
 A: min|aij| =  2.000e+01  max|aij| =  7.500e+01  ratio = 3.750e+00
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.0e+00 inf =   0.000e+00 (5)
* 1: obj =  -4.7e-01 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (110318 bytes)
Display statement at line 20
Reduced_Cost.val = -1.47
Model has been successfully processed
Writing basic solution to 'knapsack-3.sol'...

=

knapsack-3.sol

=

Problem:    knapsack
Rows:   2
Columns:    5
Non-zeros:  10
Status: OPTIMAL
Objective:  Reduced_Cost = -0.47 (MINimum)

   No.   Row name   St   Activity Lower bound   Upper bound Marginal
--  -- - - - 
-

 1 Reduced_Cost B   -1.46667
 2 Width_Limit  NU   110 110    -0.013

   No. Column name  St   Activity Lower bound   Upper bound Marginal
--  -- - - - 
-

 1 Use[20]  NL 0 0   0.067
 2 Use[45]  NL 0 0 0.1
 3 Use[50]  NL 0 0    0.17
 4 Use[55]  NL 0 0    0.23
 5 Use[75]  B    1.46667 0

Karush-Kuhn-Tucker optimality conditions:

KKT.PE: max.abs.err = 1.42e-14 on row 2
    max.rel.err = 6.43e-17 on row 2
    High quality

KKT.PB: max.abs.err = 0.00e+00 on row 0
    max.rel.err = 0.00e+00 on row 0
    High quality

KKT.DE: max.abs.err = 0.00e+00 on column 0
    max.rel.err = 0.00e+00 on column 0
    High quality

KKT.DB: max.abs.err = 0.00e+00 on row 0
    max.rel.err = 0.00e+00 on row 0
    High quality

End of output

=


Cheers !





Re: GMPL/GLPK display objective function value

2020-08-29 Thread Domingo Alvarez Duarte

Hello again !

My bad, I've got really confused, the second result is correct and 
expected with the removed "shift" term.


Sorry by the noise !

Cheers !

On 29/8/20 12:25, Domingo Alvarez Duarte wrote:

Hello again !

Doing more tests with this now I've got confused again, I commented 
out the "shift" term in the objective function and was expecting to 
get the same objective function but it's giving a conflicting result, 
doesn't it should have the same line in the "Objective" solution in 
both cases ?




Objective:  Reduced_Cost = -0.47 (MINimum)

Objective:  Reduced_Cost = -1.46667 (MINimum)



AMPL



# 
# KNAPSACK SUBPROBLEM FOR CUTTING STOCK
# 
param roll_width > 0; # width of raw rolls

set WIDTHS;     # set of widths to be cut

param price {WIDTHS} default 0.0;

var Use {WIDTHS} /*integer*/ >= 0;

minimize Reduced_Cost:
   /*1*/ - sum {i in WIDTHS} price[i] * Use[i];

subject to Width_Limit:
   sum {i in WIDTHS} i * Use[i] <= roll_width;

data;
param roll_width := 110 ;

set WIDTHS :=
 20
 45
 50
 55
 75;
param price :=
    [20] 0.2
    [45] 0.5
    [50] 0.5
    [55] 0.5
    [75] 1
;

solve;

display Reduced_Cost, Reduced_Cost.val;



AMPL output:



myampl-ng knapsack-3.ampl
MINOS 5.51: optimal solution found.
1 iterations, objective -1.46667
Reduced_Cost = -1.46667
Reduced_Cost = -1.46667



GLPSOL



# 
# KNAPSACK SUBPROBLEM FOR CUTTING STOCK
# 
param roll_width > 0; # width of raw rolls

set WIDTHS;     # set of widths to be cut

param price {WIDTHS} default 0.0;

var Use {WIDTHS} /*integer*/ >= 0;

minimize Reduced_Cost:
   /*1*/ -sum {i in WIDTHS} price[i] * Use[i];

subject to Width_Limit:
   sum {i in WIDTHS} i * Use[i] <= roll_width;

solve;

display Reduced_Cost;

data;
param roll_width := 110 ;

set WIDTHS :=
 20
 45
 50
 55
 75;
param price :=
    [20] 0.2
    [45] 0.5
    [50] 0.5
    [55] 0.5
    [75] 1
;



GLPSOL output:



myglpsol -m knapsack-3.glpsol
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
 -m knapsack-3.glpsol
Reading model section from knapsack-3.glpsol...
Reading data section from knapsack-3.glpsol...
knapsack-3.glpsol:38: warning: unexpected end of file; missing end 
statement inserted

38 lines were read
Generating Reduced_Cost...
Generating Width_Limit...
Model has been successfully generated
GLPK Simplex Optimizer, v4.65
2 rows, 5 columns, 10 non-zeros
Preprocessing...
1 row, 5 columns, 5 non-zeros
Scaling...
 A: min|aij| =  2.000e+01  max|aij| =  7.500e+01  ratio = 3.750e+00
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 =   0.0e+00 inf =   0.000e+00 (5)
* 1: obj =  -1.46667e+00 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (110318 bytes)
Display statement at line 20
Reduced_Cost.val = -1.47
Model has been successfully processed



GLPSOL solution:



Problem:    knapsack
Rows:   2
Columns:    5
Non-zeros:  10
Status: OPTIMAL
Objective:  Reduced_Cost = -1.46667 (MINimum)

   No.   Row name   St   Activity Lower bound   Upper bound Marginal
--  -- - - - 
-

 1 Reduced_Cost B   -1.46667
 2 Width_Limit  NU   110 110    -0.013

   No. Column name  St   Activity Lower bound   Upper bound Marginal
--  -- - - - 
-

 1 Use[20]  NL 0 0   0.067
 2 Use[45]  NL 0 0 0.1
 3 Use[50]  NL 0 0    0.17
 4 Use[55]  NL 0 0    0.23
 5 Use[75]  B    1.46667 0

Karush-Kuhn-Tucker optimality conditions:

KKT.PE: max.abs.err = 1.42e-14 on row 2
    max.rel.err = 6.43e-17 on row 2
    High quality

KKT.PB: max.abs.err = 0.00e+00 on row 0
    max.rel.err = 0.00e+00 on row 0
    High quality

KKT.DE: max.abs.err = 0.00e+00 on column 0
    max.rel.err = 0.00e+00 on column 0
    High quality

KKT.DB: max.abs.err = 0.00e+00 on row 0
    max.rel.err = 0.00e+00 on row 0
    High quality

End of output



Cheers !

On 29/8/20 11:32, Domingo Alvarez Duarte wrote:

Hello Andrew !

Again thank you very much for your help !

After replying to your comments I reviewed again the wikibook link 
(https://en.wikibooks.org/wiki/GLPK/Troubleshooting#Objective_shift_term_ignored_when_exported) 
and realized that somehow I've got lost because of the of the 
misleading AMPL result and both 

Re: GMPL/GLPK display objective function value

2020-08-29 Thread Domingo Alvarez Duarte

Hello again !

Doing more tests with this now I've got confused again, I commented out 
the "shift" term in the objective function and was expecting to get the 
same objective function but it's giving a conflicting result, doesn't it 
should have the same line in the "Objective" solution in both cases ?




Objective:  Reduced_Cost = -0.47 (MINimum)

Objective:  Reduced_Cost = -1.46667 (MINimum)



AMPL



# 
# KNAPSACK SUBPROBLEM FOR CUTTING STOCK
# 
param roll_width > 0; # width of raw rolls

set WIDTHS;     # set of widths to be cut

param price {WIDTHS} default 0.0;

var Use {WIDTHS} /*integer*/ >= 0;

minimize Reduced_Cost:
   /*1*/ - sum {i in WIDTHS} price[i] * Use[i];

subject to Width_Limit:
   sum {i in WIDTHS} i * Use[i] <= roll_width;

data;
param roll_width := 110 ;

set WIDTHS :=
 20
 45
 50
 55
 75;
param price :=
    [20] 0.2
    [45] 0.5
    [50] 0.5
    [55] 0.5
    [75] 1
;

solve;

display Reduced_Cost, Reduced_Cost.val;



AMPL output:



myampl-ng knapsack-3.ampl
MINOS 5.51: optimal solution found.
1 iterations, objective -1.46667
Reduced_Cost = -1.46667
Reduced_Cost = -1.46667



GLPSOL



# 
# KNAPSACK SUBPROBLEM FOR CUTTING STOCK
# 
param roll_width > 0; # width of raw rolls

set WIDTHS;     # set of widths to be cut

param price {WIDTHS} default 0.0;

var Use {WIDTHS} /*integer*/ >= 0;

minimize Reduced_Cost:
   /*1*/ -sum {i in WIDTHS} price[i] * Use[i];

subject to Width_Limit:
   sum {i in WIDTHS} i * Use[i] <= roll_width;

solve;

display Reduced_Cost;

data;
param roll_width := 110 ;

set WIDTHS :=
 20
 45
 50
 55
 75;
param price :=
    [20] 0.2
    [45] 0.5
    [50] 0.5
    [55] 0.5
    [75] 1
;



GLPSOL output:



myglpsol -m knapsack-3.glpsol
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
 -m knapsack-3.glpsol
Reading model section from knapsack-3.glpsol...
Reading data section from knapsack-3.glpsol...
knapsack-3.glpsol:38: warning: unexpected end of file; missing end 
statement inserted

38 lines were read
Generating Reduced_Cost...
Generating Width_Limit...
Model has been successfully generated
GLPK Simplex Optimizer, v4.65
2 rows, 5 columns, 10 non-zeros
Preprocessing...
1 row, 5 columns, 5 non-zeros
Scaling...
 A: min|aij| =  2.000e+01  max|aij| =  7.500e+01  ratio = 3.750e+00
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 =   0.0e+00 inf =   0.000e+00 (5)
* 1: obj =  -1.46667e+00 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (110318 bytes)
Display statement at line 20
Reduced_Cost.val = -1.47
Model has been successfully processed



GLPSOL solution:



Problem:    knapsack
Rows:   2
Columns:    5
Non-zeros:  10
Status: OPTIMAL
Objective:  Reduced_Cost = -1.46667 (MINimum)

   No.   Row name   St   Activity Lower bound   Upper bound Marginal
--  -- - - - 
-

 1 Reduced_Cost B   -1.46667
 2 Width_Limit  NU   110 110    -0.013

   No. Column name  St   Activity Lower bound   Upper bound Marginal
--  -- - - - 
-

 1 Use[20]  NL 0 0   0.067
 2 Use[45]  NL 0 0 0.1
 3 Use[50]  NL 0 0    0.17
 4 Use[55]  NL 0 0    0.23
 5 Use[75]  B    1.46667 0

Karush-Kuhn-Tucker optimality conditions:

KKT.PE: max.abs.err = 1.42e-14 on row 2
    max.rel.err = 6.43e-17 on row 2
    High quality

KKT.PB: max.abs.err = 0.00e+00 on row 0
    max.rel.err = 0.00e+00 on row 0
    High quality

KKT.DE: max.abs.err = 0.00e+00 on column 0
    max.rel.err = 0.00e+00 on column 0
    High quality

KKT.DB: max.abs.err = 0.00e+00 on row 0
    max.rel.err = 0.00e+00 on row 0
    High quality

End of output



Cheers !

On 29/8/20 11:32, Domingo Alvarez Duarte wrote:

Hello Andrew !

Again thank you very much for your help !

After replying to your comments I reviewed again the wikibook link 
(https://en.wikibooks.org/wiki/GLPK/Troubleshooting#Objective_shift_term_ignored_when_exported) 
and realized that somehow I've got lost because of the of the 
misleading AMPL result and both solvers report of the objective value.


Also I think that like in the exported LP file we get a comment about 
the constant term, the solution file also somehow should have a 
comment about it.


So in this

Re: GMPL/GLPK display objective function value

2020-08-29 Thread Domingo Alvarez Duarte

Hello Andrew !

Again thank you very much for your help !

After replying to your comments I reviewed again the wikibook link 
(https://en.wikibooks.org/wiki/GLPK/Troubleshooting#Objective_shift_term_ignored_when_exported) 
and realized that somehow I've got lost because of the of the misleading 
AMPL result and both solvers report of the objective value.


Also I think that like in the exported LP file we get a comment about 
the constant term, the solution file also somehow should have a comment 
about it.


So in this case AMPL has a bug.

I think that this function (and similares) should have a return value 
that could tell about this:




void glp_mpl_build_prob(glp_tran *tran, glp_prob *prob)

to

int glp_mpl_build_prob(glp_tran *tran, glp_prob *prob)

{

int ret = 0;

...

if (mpl_get_row_c0(tran, i) != 0.0) {
    xprintf("glp_mpl_build_prob: row %s; constant term %.12g ig"
   "nored\n",
   mpl_get_row_name(tran, i), mpl_get_row_c0(tran, i));

            ret = WARNING_CONST_TERM_IGNORED;

}

...

return ret;

}



Cheers !

On 29/8/20 11:01, Domingo Alvarez Duarte wrote:

Hello Andrew !

Thanks for reply !

The problem is that the GMPL is not informed/knows anything about the 
warning/divergence in the results and goes blindly.


Te exit code of glpsol also doesn't reflect anything that could be 
detected, only by visual inspection of the output or redirect the 
output and scan it for possible warnings.


Somehow GMPL should have a way to acknowledge situations like these.

===

>Exit code: 0

===

Cheers !

On 29/8/20 0:46, Andrew Makhorin wrote:

While trying to implement multi solve statements I found that in GMPL
the display of an objective function after solving do not show the
optimal value.

BTW, glpsol warns about that:

[...]
38 lines were read
Generating Reduced_Cost...
Generating Width_Limit...
Model has been successfully generated
glp_mpl_build_prob: row Reduced_Cost; constant term 1 ignored
[...]




Re: GMPL/GLPK display objective function value

2020-08-29 Thread Domingo Alvarez Duarte

Hello Andrew !

Thanks for reply !

The problem is that the GMPL is not informed/knows anything about the 
warning/divergence in the results and goes blindly.


Te exit code of glpsol also doesn't reflect anything that could be 
detected, only by visual inspection of the output or redirect the output 
and scan it for possible warnings.


Somehow GMPL should have a way to acknowledge situations like these.

===

>Exit code: 0

===

Cheers !

On 29/8/20 0:46, Andrew Makhorin wrote:

While trying to implement multi solve statements I found that in GMPL
the display of an objective function after solving do not show the
optimal value.

BTW, glpsol warns about that:

[...]
38 lines were read
Generating Reduced_Cost...
Generating Width_Limit...
Model has been successfully generated
glp_mpl_build_prob: row Reduced_Cost; constant term 1 ignored
[...]




Re: GMPL/GLPK display objective function value

2020-08-28 Thread Andrew Makhorin
> While trying to implement multi solve statements I found that in GMPL
> the display of an objective function after solving do not show the
> optimal value. 

BTW, glpsol warns about that:

[...]
38 lines were read
Generating Reduced_Cost...
Generating Width_Limit...
Model has been successfully generated
glp_mpl_build_prob: row Reduced_Cost; constant term 1 ignored
[...]



Re: GMPL/GLPK display objective function value

2020-08-28 Thread Andrew Makhorin
> While trying to implement multi solve statements I found that in GMPL 
> the display of an objective function after solving do not show the 
> optimal value.

Please see
http://en.wikibooks.org/wiki/GLPK/Troubleshooting#Objective_shift_term_ignored_when_exported