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.4666666667 (MINimum)
...
1 Reduced_Cost B -1.46667
...
GMPL displays:
...
Reduced_Cost.val = -1.46666666666667
...
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.4666666667
Reduced_Cost = -0.466667
=====
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.000000000e+00 inf = 0.000e+00 (5)
* 1: obj = -4.666666667e-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.46666666666667
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.4666666667 (MINimum)
No. Row name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- -------------
-------------
1 Reduced_Cost B -1.46667
2 Width_Limit NU 110 110 -0.0133333
No. Column name St Activity Lower bound Upper bound Marginal
------ ------------ -- ------------- ------------- -------------
-------------
1 Use[20] NL 0 0 0.0666667
2 Use[45] NL 0 0 0.1
3 Use[50] NL 0 0 0.166667
4 Use[55] NL 0 0 0.233333
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 !