Re: Adding if/then/else statement to GMPL
Domingo Alvarez Duarte <[email protected]> Thu, 27 Aug 2020 12:12:02 +0200
| Newsgroups | gmane.comp.gnu.glpk |
|---|---|
| Message-ID | <[email protected]> |
Hello Andrew !
After replying to your last email I came with this possible solution to
allow multiple solve statements in GMPL:
https://github.com/mingodad/GLPK/commit/b80bcd86f1a78eba753e919a56fb9b976934b237
Cheers !
On 27/8/20 11:44, Domingo Alvarez Duarte wrote:
> Hello Andrew !
>
> Thanks for reply !
>
> You are right in respect to the original implementation, one possible
> way to have multiple solve statements working is to pause the
> execution return a code that would tell the caller to generate the
> problem, solve it, postsolve and then continue the execution from that
> point (glpsol is somehow already doing it but is not looping back to
> see if there is more solve statements to execute).
>
> Anyone can contribute to make this work !
>
> Pseudo code:
>
> =====
>
> /* generate the model */
> while ((ret = glp_mpl_generate(csa->tran, csa->out_dpy)) ==
> GMPL_SOLVE)
> {
> if (glp_mpl_generate(csa->tran, csa->out_dpy)) goto err2;
> /* build the problem instance from the model */
> glp_mpl_build_prob(csa->tran, csa->prob);
> ...
> glp_simplex(csa->prob, &csa->smcp);
> ...
> glp_intopt(csa->prob, &csa->iocp);
> ...
> ret = glp_mpl_postsolve(csa->tran, csa->prob, GLP_SOL);
> //resume the execution
> }
> =====
>
> Cheers !
>
> On 27/8/20 11:25, Andrew Makhorin wrote:
>> On Thu, 2020-08-27 at 11:01 +0200, Domingo Alvarez Duarte wrote:
>>> Hello !
>>>
>>> I just finished adding the parsing code to parse this dummy model:
>>>
>>> https://github.com/mingodad/GLPK/blob/local-set-param/examples/cut2.mo
>>> d
>>>
>>> On that branch I've added let/repeat/problem and relaxed the only one
>>> solve requirement, only the parsing is done (although corner cases
>>> can
>>> be missing).
>>>
>>> Any comment/suggestion/help is welcome !
>>>
>>> =====
>>>
>>> ./glpsol --genonly -m cut2.mod
>>> >./glpsol --genonly -m cut2.mod
>>> GLPSOL: GLPK LP/MIP Solver, v4.65
>>> Parameter(s) specified in the command line:
>>> --genonly -m cut2.mod
>>> Reading model section from cut2.mod...
>>> Reading data section from cut2.mod...
>>> 135 lines were read
>>> Checking (line 14)...
>>> Generating Number...
>>> Generating Fill...
>>> Generating Reduced_Cost...
>>> Generating Width_Limit...
>>> Display statement at line 46
>>> problem Cutting_Opt: Cut, Number, Fill;
>>> problem Pattern_Gen: Use, Reduced_Cost, Width_Limit;
>>> problem Mix: Cut, Reduced_Cost;
>>> Display statement at line 58
>>> price[20] = 0.166667
>>> price[45] = 0.416667
>>> price[50] = 0.5
>>> price[55] = 0.5
>>> price[75] = 0.833333
>>> Model has been successfully generated
>>> >Exit code: 0
>>>
>>> =====
>>>
>>> Cheer !
>>>
>>>
>>> repeat {
>>> solve Cutting_Opt;
>>> let {i in WIDTHS} price[i] := Fill[i].dual;
>>> display price;
>>>
>>> solve Pattern_Gen;
>>> if Reduced_Cost < -0.00001 then {
>>> let nPAT := nPAT + 1;
>>> let {i in WIDTHS} nbr[i,nPAT] := Use[i];
>>> display Use;
>>> }
>>> else break;
>>> }
>> I don't think that the solve statement is executed more than once.
>> Internally the solve statement is not a real statement (like display),
>> i.e. it doesn't "call" a solver; it is just a marker that separates the
>> main part and the post-solving part of the model.