Re: Adding if/then/else statement to GMPL

2020-08-30 Thread Domingo Alvarez Duarte

Hello !

With this commit 
https://github.com/mingodad/GLPK/commit/2d445283a68c96fe64f0d7e5b26d9cd7e5cf6acf 
it now solve all original problems and also is able to solve 
examples/cut-fix-size.mod that shows what new GMPL extensions I've done 
(still as a prof of concept that need more work) and is usable with caution.


The 'let' update propagation is not done properly, but if we preallocate 
parameter/set dimensions we can work by changing the predicate filters 
({j in PATTERNS : j <= nPAT_top}).


Also to overwrite the type of solver to be used the syntax of solve is 
"solve[.lp/mip/ip] [problem name];".


Would be nice if anyone could provide examples of problems that they 
want to be able to express in GMPL to test/improve/extend the 
implementation.


Again any comment/suggestion/help is welcome !




problem Cutting_Opt;
# 

param nPAT integer >= 0, default 0;
param nPAT_top integer >= 0, default 0;
param roll_width;

set PATTERNS := 1..nPAT;
set WIDTHS;

param orders {WIDTHS} > 0;
param nbr {WIDTHS,PATTERNS} integer >= 0;

let nPAT := 2 * card(WIDTHS);
let nPAT_top := 0;
for {i in WIDTHS} {
   let nPAT_top := nPAT_top + 1;
   let nbr[i,nPAT_top] := floor (roll_width/i);
   let {i2 in WIDTHS: i2 <> i} nbr[i2,nPAT_top] := 0;
}
#display nPAT, nPAT_top;
#display nbr;

check {j in PATTERNS : j <= nPAT_top}: sum {i in WIDTHS} i * nbr[i,j] <= 
roll_width;


var Cut {PATTERNS} integer >= 0;

minimize Number: sum {j in PATTERNS : j <= nPAT_top} Cut[j];

subject to Fill {i in WIDTHS}:
   sum {j in PATTERNS : j <= nPAT_top} nbr[i,j] * Cut[j] >= orders[i];


problem Pattern_Gen;
# 

param price {WIDTHS} default 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;

problem Mix : Cut, Reduced_Cost;

problem Pattern_Gen;

if nPAT > 0 then {
    problem Mix;
    #problem Mix2; #problem creation not allowed here
}

display Cutting_Opt, Pattern_Gen, Mix;

repeat {
#for {1..4} {
   solve.lp Cutting_Opt;
   let {i in WIDTHS} price[i] := Fill[i].dual;
   #display price;

   solve/*.mip*/ Pattern_Gen;
   display Reduced_Cost, Use;
   if Reduced_Cost < -0.1 and nPAT_top <= nPAT then
   {
  let nPAT_top := nPAT_top + 1;
  let {i in WIDTHS} nbr[i,nPAT_top] := Use[i];
  #display nPAT;
   }
   else break;
}

check {j in PATTERNS : j <= nPAT_top}: sum {i in WIDTHS} i * nbr[i,j] <= 
roll_width;


solve/*.mip*/ Cutting_Opt;
display Cut;
#solve Pattern_Gen;

data;

param roll_width := 110;
set WIDTHS :=
 20
 45
 50
 55
 75;
param orders :=
 [20] 48
 [45] 35
 [50] 24
 [55] 10
 [75] 8;
end;



Cheers !

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, Domi

Re: Adding if/then/else statement to GMPL

2020-08-29 Thread Andrew Makhorin
On Sat, 2020-08-29 at 15:29 +0200, Domingo Alvarez Duarte wrote:
> Hello !
> 
> With this commit I'm close for a proof of concept of GMPL with multi 
> problem, multi solve, repeat and let statements.
> 
> The let needs work for the dependence hell when update a parameter.
> 
> The multi solve statements is implemented as calling a user provided 
> callaback (see in examples/glpsol.c for a crude example).
> 
> https://github.com/mingodad/GLPK/commit/65655c05fc8e315b3e43b98a1f2324
> 66614a0b46
> 
> It compiles and run examples/cut2.mod on an infinite loop due to 
> problems with propagation of updates with 'let' statement.
> 
> Ideally it should be compatible with existing models (not yet fully 
> implemented/checked).
> 
> Any comment/suggestion/help is welcome !

What about this:

   ...
   var z;
   ...
   if (z >= 0)
  s.t. foo: sum{j in J} x[j] >= 0;
   else
  s.t. bar: sum{j in J} x[j] <= 1;
   ...
   solve;
   ...

;)

> 
> Cheers !
> 
> 



Re: Adding if/then/else statement to GMPL

2020-08-29 Thread Domingo Alvarez Duarte

Hello !

With this commit I'm close for a proof of concept of GMPL with multi 
problem, multi solve, repeat and let statements.


The let needs work for the dependence hell when update a parameter.

The multi solve statements is implemented as calling a user provided 
callaback (see in examples/glpsol.c for a crude example).


https://github.com/mingodad/GLPK/commit/65655c05fc8e315b3e43b98a1f232466614a0b46

It compiles and run examples/cut2.mod on an infinite loop due to 
problems with propagation of updates with 'let' statement.


Ideally it should be compatible with existing models (not yet fully 
implemented/checked).


Any comment/suggestion/help is welcome !

Cheers !

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.




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, >smcp);
         ...
         glp_intopt(csa->prob, >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, >smcp);
         ...
         glp_intopt(csa->prob, >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 !

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.




Re: Adding if/then/else statement to GMPL

2020-08-25 Thread Heinrich Schuchardt
Am 25. August 2020 20:17:06 MESZ schrieb Domingo Alvarez Duarte 
:
>Hello Heinrich !
>
>Here is better example from examples/shikaku.mod:
>

Just another example where the existing if-then-else expression can be used to 
shorten the code.

Anyway comparing a binary to =1 is not a good idea in GLPK. You should use > .5.

Best regards

Heinrich

>With if/then/else:
>
>=
>
>/* Output solution graphically */
>printf "\nSolution:\n";
>for { row in rows1 } {
>     for { col in cols1 } {
>     if (sum{(i,j,k,l,m,n) in B:
>     col >= l and col <= n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1} 1) > 0 then
>     {
>     if (sum{(i,j,k,l,m,n) in B:
>     row >= k and row <= m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1} 1) > 0 then printf "+";
>     else printf "-";
>     }
>     else
>     {
>     if (sum{(i,j,k,l,m,n) in B:
>     row >= k and row <= m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1} 1) > 0 then printf "|";
>     else printf " ";
>     }
>
>     if (sum{(i,j,k,l,m,n) in B:
>     col >= l and col < n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1} 1) > 0 then printf "---";
>     else printf "   ";
>     }
>     printf "\n";
>
>     for { col in cols: (sum{ s in rows: s = row } 1) = 1 } {
>     if (sum{(i,j,k,l,m,n) in B:
>     row >= k and row < m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1} 1) > 0 then printf "|";
>     else printf " ";
>    if (sum{ (i,j) in V: i = row and j = col} 1) > 0 then printf " 
>%2d", givens[row,col];
>     else printf "  .";
>     }
>     if (sum{ r in rows: r = row } 1) = 1 then printf "|\n";
>}
>
>=
>
>Original:
>
>=
>
>/* Output solution graphically */
>printf "\nSolution:\n";
>for { row in rows1 } {
>     for { col in cols1 } {
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     col >= l and col <= n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1}) > 0 and
>     card({(i,j,k,l,m,n) in B:
>     row >= k and row <= m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1}) > 0} "+";
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     col >= l and col <= n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1}) = 0 and
>     card({(i,j,k,l,m,n) in B:
>     row >= k and row <= m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1}) > 0} "|";
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     row >= k and row <= m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1}) = 0 and
>     card({(i,j,k,l,m,n) in B:
>     col >= l and col <= n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1}) > 0} "-";
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     row >= k and row <= m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1}) = 0 and
>     card({(i,j,k,l,m,n) in B:
>     col >= l and col <= n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1}) = 0} " ";
>
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     col >= l and col < n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1}) > 0} "---";
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     col >= l and col < n and (row = k or row = m) and
>     x[i,j,k,l,m,n] = 1}) = 0} "   ";
>     }
>     printf "\n";
>
>     for { (col,p) in { cols, 1 }: card({ s in rows: s = row }) = 1 } {
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     row >= k and row < m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1}) > 0} "|";
>     printf{0..0: card({(i,j,k,l,m,n) in B:
>     row >= k and row < m and (col = l or col = n) and
>     x[i,j,k,l,m,n] = 1}) = 0} " ";
>     printf{0..0: card({ (i,j) in V: i = row and j = col}) > 0} " 
>%2d", givens[row,col];
>    printf{0..0: card({ (i,j) in V: i = row and j = col}) = 0} " 
>.";
>     }
>     printf{0..0: card({ r in rows: r = row }) = 1} "|\n";
>}
>
>=
>
>Cheers !
>On 24/8/20 16:59, Heinrich Schuchardt wrote:
>> On 24.08.20 16:33, Domingo Alvarez Duarte wrote:
>>> 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 ?
>> Dear Domingo,
>>
>> I do not yet understand what was you weren't able to express with the
>> current syntax.
>>
>> Instead of
>>
>> if length(p) == 3 then display "true 3"; else display "false 3";
>> if length(p) == 5 then display "true 5"; else display "false 5";
>>
>> you can write:
>>
>> param p,symbolic := "dad";
>> display if length(p) == 3 then "true 3" else 

Re: Adding if/then/else statement to GMPL

2020-08-25 Thread Domingo Alvarez Duarte

Hello Heinrich !

Here is better example from examples/shikaku.mod:

With if/then/else:

=

/* Output solution graphically */
printf "\nSolution:\n";
for { row in rows1 } {
    for { col in cols1 } {
    if (sum{(i,j,k,l,m,n) in B:
    col >= l and col <= n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1} 1) > 0 then
    {
    if (sum{(i,j,k,l,m,n) in B:
    row >= k and row <= m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1} 1) > 0 then printf "+";
    else printf "-";
    }
    else
    {
    if (sum{(i,j,k,l,m,n) in B:
    row >= k and row <= m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1} 1) > 0 then printf "|";
    else printf " ";
    }

    if (sum{(i,j,k,l,m,n) in B:
    col >= l and col < n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1} 1) > 0 then printf "---";
    else printf "   ";
    }
    printf "\n";

    for { col in cols: (sum{ s in rows: s = row } 1) = 1 } {
    if (sum{(i,j,k,l,m,n) in B:
    row >= k and row < m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1} 1) > 0 then printf "|";
    else printf " ";
    if (sum{ (i,j) in V: i = row and j = col} 1) > 0 then printf " 
%2d", givens[row,col];

    else printf "  .";
    }
    if (sum{ r in rows: r = row } 1) = 1 then printf "|\n";
}

=

Original:

=

/* Output solution graphically */
printf "\nSolution:\n";
for { row in rows1 } {
    for { col in cols1 } {
    printf{0..0: card({(i,j,k,l,m,n) in B:
    col >= l and col <= n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1}) > 0 and
    card({(i,j,k,l,m,n) in B:
    row >= k and row <= m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1}) > 0} "+";
    printf{0..0: card({(i,j,k,l,m,n) in B:
    col >= l and col <= n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1}) = 0 and
    card({(i,j,k,l,m,n) in B:
    row >= k and row <= m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1}) > 0} "|";
    printf{0..0: card({(i,j,k,l,m,n) in B:
    row >= k and row <= m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1}) = 0 and
    card({(i,j,k,l,m,n) in B:
    col >= l and col <= n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1}) > 0} "-";
    printf{0..0: card({(i,j,k,l,m,n) in B:
    row >= k and row <= m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1}) = 0 and
    card({(i,j,k,l,m,n) in B:
    col >= l and col <= n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1}) = 0} " ";

    printf{0..0: card({(i,j,k,l,m,n) in B:
    col >= l and col < n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1}) > 0} "---";
    printf{0..0: card({(i,j,k,l,m,n) in B:
    col >= l and col < n and (row = k or row = m) and
    x[i,j,k,l,m,n] = 1}) = 0} "   ";
    }
    printf "\n";

    for { (col,p) in { cols, 1 }: card({ s in rows: s = row }) = 1 } {
    printf{0..0: card({(i,j,k,l,m,n) in B:
    row >= k and row < m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1}) > 0} "|";
    printf{0..0: card({(i,j,k,l,m,n) in B:
    row >= k and row < m and (col = l or col = n) and
    x[i,j,k,l,m,n] = 1}) = 0} " ";
    printf{0..0: card({ (i,j) in V: i = row and j = col}) > 0} " 
%2d", givens[row,col];

    printf{0..0: card({ (i,j) in V: i = row and j = col}) = 0} "  .";
    }
    printf{0..0: card({ r in rows: r = row }) = 1} "|\n";
}

=

Cheers !
On 24/8/20 16:59, Heinrich Schuchardt wrote:

On 24.08.20 16:33, Domingo Alvarez Duarte wrote:

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 ?

Dear Domingo,

I do not yet understand what was you weren't able to express with the
current syntax.

Instead of

if length(p) == 3 then display "true 3"; else display "false 3";
if length(p) == 5 then display "true 5"; else display "false 5";

you can write:

param p,symbolic := "dad";
display if length(p) == 3 then "true 3" else "false 3";
display if length(p) == 5 then "true 5" else "false 5";
solve;
end;

Best regards

Heinrich




Re: Adding if/then/else statement to GMPL

2020-08-24 Thread Andrew Makhorin
> Probably something like MPL (Math Programming
> Language) developed by G.Dantzig in 70's is what you would like to
> have;
> see https://dl.acm.org/doi/10.1145/800184.810495 .
> 

I've got a scanned copy of this Tech. Report (May 1968, 92 pages); so if
someone is interested, I can post it via e-mail.



Re: Adding if/then/else statement to GMPL

2020-08-24 Thread Meketon, Marc
Well said.

Sent from my mobile

On Aug 24, 2020, at 1:39 PM, Jeffrey Kantor  wrote:

 Respectfully, and I very much appreciate the careful design of GMPL and its 
utility for creating ‘beautiful’ models, I have to disagree. What is being 
proposed, I think, is not a general purpose programming language, but rather 
extensions to GMPL making it more suitable to expressing well accepted models 
for important OR applications. Stock cutting is one example, but there are many 
others.

GMPL is very well suited to documenting models and applications, especially for 
teaching and education. They’re short, to the point, and above all, largely 
self-documenting. Extending the language should and could maintain these 
attributes. zWithout these extensions, I fear that GMPL will whither on the 
vine in favor of precisely what you describe … modeling tools embedded in 
higher level languages like Python and Julia.

My hope is the GMPL v2 would, like GMPL v1, something that, once created, stays 
fixed for decades. This is the advantage of a reference language for 
representing models, a role for which GMPL has been successful.  Models 
embedded in Python, Julia, etc, typically require additional maintanece as the 
languages and extensive libraries evolve. With GMPL one doesn’t have to worry 
about that.


On Aug 24, 2020, at 12:17 PM, Andrew Makhorin 
mailto:m...@gnu.org>> wrote:

On Mon, 2020-08-24 at 14: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.


I agree that programming features like "goto" (as well as its structured
versions) sometimes are necessary, but in my opinion it should be
another language. Probably something like MPL (Math Programming
Language) developed by G.Dantzig in 70's is what you would like to have;
see https://dl.acm.org/doi/10.1145/800184.810495 .
The initial design of AMPL, which GNU MathProg is based on, is not
suitable to make AMPL a full-featured programming language, and in my
opinion all further additions just broke the design being incompatible
with it.

On the other hand, developing and implementing yet another (even
domain-specific) programming language is not a good idea. I think that
modeling features might be built *over* an appropriate programming
language. A good example of such approach is the GNU LilyPond (a music
engraving program; see https://lilypond.org/ ), where the domain-
specific part is built over the Scheme programming language (a dialect
of Lisp): in normal circumstances the user writes all things with
domain-specific constructions, but if something unusual is needed,
he/she may write things on a lower level directly in Scheme.


Andrew Makhorin



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.


[Fwd: Re: Adding if/then/else statement to GMPL]

2020-08-24 Thread Andrew Makhorin
 Forwarded Message 
From: Jeffrey Kantor 
To: Andrew Makhorin 
Cc: "Meketon, Marc" , Domingo Alvarez
Duarte , help-glpk@gnu.org 
Subject: Re: Adding if/then/else statement to GMPL
Date: Mon, 24 Aug 2020 12:38:42 -0500

> Respectfully, and I very much appreciate the careful design of GMPL
> and its utility for creating ‘beautiful’ models, I have to disagree.
> What is being proposed, I think, is not a general purpose programming
> language, but rather extensions to GMPL making it more suitable to
> expressing well accepted models for important OR applications. Stock
> cutting is one example, but there are many others.
> 
> GMPL is very well suited to documenting models and applications,
> especially for teaching and education. They’re short, to the point,
> and above all, largely self-documenting. Extending the language should
> and could maintain these attributes. zWithout these extensions, I fear
> that GMPL will whither on the vine in favor of precisely what you
> describe … modeling tools embedded in higher level languages like
> Python and Julia.
> 
> My hope is the GMPL v2 would, like GMPL v1, something that, once
> created, stays fixed for decades. This is the advantage of a reference
> language for representing models, a role for which GMPL has been
> successful.  Models embedded in Python, Julia, etc, typically require
> additional maintanece as the languages and extensive libraries evolve.
> With GMPL one doesn’t have to worry about that. 
> 
> 
> > On Aug 24, 2020, at 12:17 PM, Andrew Makhorin  wrote:
> > 
> > On Mon, 2020-08-24 at 14: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.
> > > 
> > 
> > I agree that programming features like "goto" (as well as its
> > structured
> > versions) sometimes are necessary, but in my opinion it should be
> > another language. Probably something like MPL (Math Programming
> > Language) developed by G.Dantzig in 70's is what you would like to
> > have;
> > see https://dl.acm.org/doi/10.1145/800184.810495 .
> > The initial design of AMPL, which GNU MathProg is based on, is not
> > suitable to make AMPL a full-featured programming language, and in
> > my
> > opinion all further additions just broke the design being
> > incompatible
> > with it.
> > 
> > On the other hand, developing and implementing yet another (even
> > domain-specific) programming language is not a good idea. I think
> > that
> > modeling features might be built *over* an appropriate programming
> > language. A good example of such approach is the GNU LilyPond (a
> > music
> > engraving program; see https://lilypond.org/ ), where the domain-
> > specific part is built over the Scheme programming language (a
> > dialect
> > of Lisp): in normal circumstances the user writes all things with
> > domain-specific constructions, but if something unusual is needed,
> > he/she may write things on a lower level directly in Scheme.
> > 
> > 
> > Andrew Makhorin
> 
> 



Re: Adding if/then/else statement to GMPL

2020-08-24 Thread Andrew Makhorin
On Mon, 2020-08-24 at 14: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.
> 

I agree that programming features like "goto" (as well as its structured
versions) sometimes are necessary, but in my opinion it should be
another language. Probably something like MPL (Math Programming
Language) developed by G.Dantzig in 70's is what you would like to have;
see https://dl.acm.org/doi/10.1145/800184.810495 .
The initial design of AMPL, which GNU MathProg is based on, is not
suitable to make AMPL a full-featured programming language, and in my
opinion all further additions just broke the design being incompatible
with it.

On the other hand, developing and implementing yet another (even
domain-specific) programming language is not a good idea. I think that
modeling features might be built *over* an appropriate programming
language. A good example of such approach is the GNU LilyPond (a music
engraving program; see https://lilypond.org/ ), where the domain-
specific part is built over the Scheme programming language (a dialect
of Lisp): in normal circumstances the user writes all things with
domain-specific constructions, but if something unusual is needed,
he/she may write things on a lower level directly in Scheme.


Andrew Makhorin




[Fwd: Re: Adding if/then/else statement to GMPL]

2020-08-24 Thread Andrew Makhorin
 Forwarded Message 
From: Jeffrey Kantor 
To: "Meketon, Marc" 
Cc: Andrew Makhorin , Domingo Alvarez Duarte , help-glpk@gnu.org 
Subject: Re: Adding if/then/else statement to GMPL
Date: Mon, 24 Aug 2020 09:54:33 -0500

> This would be another vote for extending GMPL to include features to
> support the iterative use of LP’s. As is stands, GMPL is a sweet
> little modeling tool … a well-crafted application is small work of art
> that is generally clear and unambiguous. One mark fo a good model is
> the ability to go back years later and instantly recall the logic
> behind the model. 
> 
> There are so many more applications where iteration is a natural part
> of the modeling. Stocking cutting, for example. Stochastic
> programming. With these features, GMPL could continue to be a useful
> tool for developing and documenting models and MILP applications.
> Without these features, tools like PULP and Pyomo become the lingua
> franca of the field.
> 
> > On Aug 24, 2020, at 9:00 AM, Meketon, Marc via Users list for GLPK
> > (GNU Linear Programming Kit)  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  > org> 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/9d70a37b16bd377722eeb3880f
> > > cf86
> > > 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.
> 
> 



Re: Adding if/then/else statement to GMPL

2020-08-24 Thread Domingo Alvarez Duarte

Hello Heinrich !

That example was a silly one only to do a minimal check that the add 
if/then/else was working (properly?).


My implementation doesn't seem to need much code and allow a bit better 
expressiveness to GMPL.


Another example from examples/pentomino.mod:

Before:



for{i in 1..m}
{ for{j in 1..n}
{ for{0..0: (i,j) in R}
{ for{(c,ii,jj) in S: (i-ii,j-jj) in D[c] and x[c,ii,jj]}
printf" %s", substr(c,1,1);
}
for{0..0: (i,j) not in R}
printf" .";
}
printf"\n";
}



After:



for{i in M}
{ for{j in N}
{ if(i,j) in R then
{ for{(c,ii,jj) in S: (i-ii,j-jj) in D[c] and x[c,ii,jj]}
printf" %s", substr(c,1,1);
}
else
printf" .";
}
printf"\n";
}



Cheers !

On 24/8/20 16:59, Heinrich Schuchardt wrote:

On 24.08.20 16:33, Domingo Alvarez Duarte wrote:

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 ?

Dear Domingo,

I do not yet understand what was you weren't able to express with the
current syntax.

Instead of

if length(p) == 3 then display "true 3"; else display "false 3";
if length(p) == 5 then display "true 5"; else display "false 5";

you can write:

param p,symbolic := "dad";
display if length(p) == 3 then "true 3" else "false 3";
display if length(p) == 5 then "true 5" else "false 5";
solve;
end;

Best regards

Heinrich


RE: Adding if/then/else statement to GMPL

2020-08-24 Thread Meketon, Marc
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.


Re: Adding if/then/else statement to GMPL

2020-08-24 Thread Heinrich Schuchardt
On 24.08.20 16:33, Domingo Alvarez Duarte wrote:
> 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 ?

Dear Domingo,

I do not yet understand what was you weren't able to express with the
current syntax.

Instead of

if length(p) == 3 then display "true 3"; else display "false 3";
if length(p) == 5 then display "true 5"; else display "false 5";

you can write:

param p,symbolic := "dad";
display if length(p) == 3 then "true 3" else "false 3";
display if length(p) == 5 then "true 5" else "false 5";
solve;
end;

Best regards

Heinrich



Re: Adding if/then/else statement to GMPL

2020-08-24 Thread Domingo Alvarez Duarte

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/9d70a37b16bd377722eeb3880fcf86
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.




RE: Adding if/then/else statement to GMPL

2020-08-24 Thread Meketon, Marc
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/9d70a37b16bd377722eeb3880fcf86
> 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.


Re: Adding if/then/else statement to GMPL

2020-08-23 Thread Andrew Makhorin
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/9d70a37b16bd377722eeb3880fcf86
> 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.





Re: Adding if/then/else statement to GMPL

2020-08-23 Thread Domingo Alvarez Duarte

Hello !

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



Again any comment/suggestion is welcome !

Cheers !




Adding if/then/else statement to GMPL

2020-08-23 Thread Domingo Alvarez Duarte

Hello !

I just added the if/then/else statement to GMPL here 
https://github.com/mingodad/GLPK/commit/8984d5db70ce0cc91189911164f5448390026a4a 
and hope it could be added to a future release of GLPK/GMPL.


Any comment/suggestion is welcome !



param p symbolic := "dad";
check length(p) == 3;

if length(p) == 3 then display "true";
if length(p) == 5 then display "true";
if length(p) == 3 then display "true"; else display "false";
if length(p) == 5 then display "true"; else display "false";

if length(p) == 3 then
    display "true";

if length(p) == 5 then
    display "true";

if length(p) == 3 then
    display "true";
else
    display "false";

if length(p) == 5 then
    display "true";
else
    display "false";

if length(p) == 3 then {display "true";}
if length(p) == 5 then {display "true";}
if length(p) == 3 then {}
if length(p) == 5 then {}
if length(p) == 3 then {display "true";} else {display "false";}
if length(p) == 5 then {display "true";} else {display "false";}

if length(p) == 3 then
{
    display "true";
}

if length(p) == 5 then
{
    display "true";
}

if length(p) == 3 then
{
    display "true";
}
else
{
    display "false";
}

if length(p) == 5 then
{
    display "true";
}
else
{
    display "false";
}



Output:



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

58 lines were read
Checking (line 2)...
Display statement at line 4
true
Display statement at line 6
true
Display statement at line 7
false
Display statement at line 10
true
Display statement at line 16
true
Display statement at line 23
false
Display statement at line 25
true
Display statement at line 29
true
Display statement at line 30
false
Display statement at line 34
true
Display statement at line 44
true
Display statement at line 57
false
Model has been successfully generated
GLPK Simplex Optimizer, v4.65
0 rows, 0 columns, 0 non-zeros
~ 0: obj =   0.0e+00  infeas =  0.000e+00
OPTIMAL SOLUTION FOUND
Time used:   0.0 secs
Memory used: 0.1 Mb (67060 bytes)



Cheers !