Re: GMPL/GLPK display objective function value

Domingo Alvarez Duarte <[email protected]> Sat, 29 Aug 2020 12:45:03 +0200
Newsgroups gmane.comp.gnu.glpk
Message-ID <[email protected]>
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.4666666667 (MINimum)
>
> Objective:  Reduced_Cost = -1.466666667 (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.466666667
> 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.000000000e+00 inf =   0.000e+00 (5)
> *     1: obj =  -1.466666667e+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.46666666666667
> Model has been successfully processed
>
> ====
>
> GLPSOL solution:
>
> ====
>
> Problem:    knapsack
> Rows:       2
> Columns:    5
> Non-zeros:  10
> Status:     OPTIMAL
> Objective:  Reduced_Cost = -1.466666667 (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 !
>
> 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 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
>>>> [...]