Re: Multi problems in GMPL

2020-08-27 Thread Joao Pedro Pedroso
Dear Domingo,

I share the opinion that GMPL should remain a domain-specific
language, and the additions that are being proposed would fit better
in a general-purpose language.

This was the intention of the package python-glpk (discontinued after
some internal changes in glpk), which has been captured and extended
in AMPL's Python interface, AMPLPY:
   https://amplpy.readthedocs.io/en/latest/

Some examples there are similar to what you propose.

Cheers,

Joao Pedro



Re: Adding if/then/else statement to GMPL

2020-08-27 Thread Domingo Alvarez Duarte

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.17
price[45] = 0.416667
price[50] = 0.5
price[55] = 0.5
price[75] = 0.83
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.1 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.




Re: Adding if/then/else statement to GMPL

2020-08-27 Thread Domingo Alvarez Duarte

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.17
price[45] = 0.416667
price[50] = 0.5
price[55] = 0.5
price[75] = 0.83
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.1 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.




Re: Adding if/then/else statement to GMPL

2020-08-27 Thread Andrew Makhorin
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.17
> price[45] = 0.416667
> price[50] = 0.5
> price[55] = 0.5
> price[75] = 0.83
> 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.1 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.



Re: Adding if/then/else statement to GMPL

2020-08-27 Thread Domingo Alvarez Duarte

Hello !

I just finished adding the parsing code to parse this dummy model:

https://github.com/mingodad/GLPK/blob/local-set-param/examples/cut2.mod

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.17
price[45] = 0.416667
price[50] = 0.5
price[55] = 0.5
price[75] = 0.83
Model has been successfully generated
>Exit code: 0

=

Cheer !

On 24/8/20 17:02, Meketon, Marc wrote:

Since GMPL is a subset of AMPL, I would begin by looking at:
https://ampl.com/BOOK/CHAPTERS/16-script.pdf

As far as examples, the classic 'cutting stock' problem is a good one.  The 
AMPL site has two different iterative approaches:
https://ampl.com/BOOK/EXAMPLES/EXAMPLES2/cut.mod

https://ampl.com/BOOK/EXAMPLES/EXAMPLES2/cut.run

and

https://ampl.com/BOOK/EXAMPLES/EXAMPLES2/cut2.mod

https://ampl.com/BOOK/EXAMPLES/EXAMPLES2/cut2.run

and the data file is at:
https://ampl.com/BOOK/EXAMPLES/EXAMPLES2/cut.dat


-Original Message-
From: Domingo Alvarez Duarte 
Sent: Monday, August 24, 2020 10:34 AM
To: Meketon, Marc ; Andrew Makhorin 
; help-glpk@gnu.org
Subject: Re: Adding if/then/else statement to GMPL

Hello Meketon !

Could you share your view of how it would be expressed (an ideal model
sample) ?

If you want to talk about it, maybe I'll be interested in implement it !

Can you share a collection of models data to be used as base for the 
test/implementation ?

Cheers !

On 24/8/20 16:00, Meketon, Marc wrote:

I've always felt that GMPL needed if-then-else, for-loops, 'let' statements and 
the ability to re-solve to be a true modeling language.  And Andrew has always 
disagreed.

Many of the models that I create ultimately are 'iterative' where I need to 
take the results of one model and use it to setup another model.  To me, that 
is also modeling.  GMPL doesn't have it.

So often, I use GMPL for an initial model - it is a wonderful language, and I 
find it faster to code than alternatives.  But then when I 'get it right' I 
have to re-code it in PYOMO or PULP or write directly to an 'lp' file within a 
Python or C# or other language script.

Having the ability to run, adjust variables, add/take away constraints, re-run 
would be extremely useful, and make GMPL more of a one-stop modeling language.

-Original Message-
From: Help-glpk
 On Behalf Of
Andrew Makhorin
Sent: Sunday, August 23, 2020 2:56 PM
To: Domingo Alvarez Duarte ; help-glpk@gnu.org
Subject: Re: Adding if/then/else statement to GMPL

On Sun, 2020-08-23 at 15:36 +0200, Domingo Alvarez Duarte wrote:

Hello !

Also I've added the break/continue statements here
https://github.com/mingodad/GLPK/commit/9d70a37b16bd377722eeb3880fcf8
6
bb3b812118


Again any comment/suggestion is welcome !

Cheers !




Please note that GNU MathProg is a *modeling* language; it is not a 
general-purpose programming language. If you need to produce a non-trivial 
solution report (since all such-like statements are allowed only on the 
post-solving stage), it would be more practical to write the solution to a 
temporary file and then process it with a separate program.





This e-mail and any attachments may be confidential or legally privileged. If 
you received this message in error or are not the intended recipient, you 
should destroy the e-mail message and any attachments or copies, and you are 
prohibited from retaining, distributing, disclosing or using any information 
contained herein. Please inform us of the erroneous delivery by return e-mail. 
Thank you for your cooperation.


This e-mail and any attachments may be confidential or legally privileged. If 
you received this message in error or are not the intended recipient, you 
should destroy the e-mail message and any attachments or copies, and you are 
prohibited from retaining, distributing, disclosing or using any information 
contained herein. Please inform us of the erroneous delivery by return e-mail. 
Thank you for your cooperation.