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: Multi problems in GMPL

2020-08-26 Thread Domingo Alvarez Duarte

Hello !

Meanwhile I implemented only the parsing/display of problem statement 
like ampl but without domains.


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

Output:



./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...
107 lines were read
Checking (line 14)...
Generating Number...
Generating Fill...
Generating Reduced_Cost...
Generating Width_Limit...
Display statement at line 39
problem Cutting_Opt: Cut, Number, Fill;
problem Pattern_Gen: Use, Reduced_Cost, Width_Limit;
problem Mix: Cut, Reduced_Cost;
Model has been successfully generated
>Exit code: 0



Cheers !

On 26/8/20 19:57, Domingo Alvarez Duarte wrote:

Hello !

Thinking in how to have multiple problem in GMPL I'm asking for other 
user opinions about how that could be expressed, one example can be 
like the one bellow where we have common elements and namespaced 
problems.


If you have any other idea that you want to share let me know !



param roll_width;
set WIDTHS;

problem Cutting_Opt {
    # 
    param nPAT integer >= 0, default 0;
    set PATTERNS := 1..nPAT;
    param orders {WIDTHS} > 0;
    param nbr {WIDTHS,PATTERNS} integer >= 0;

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

    var Cut {PATTERNS} integer >= 0;

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

    subject to Fill {i in WIDTHS}:
       sum {j in PATTERNS} 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;
}
solve Cutting_Opt;
solve Pattern_Gen;



Cheers !