# GNU MathProg GNU MathProg is a modeling language intended for describing linear mathematical programming models. Model descriptions written in the GNU MathProg language consist of a set of statements and data blocks constructed by the user. See http://gnuwin32.sourceforge.net/downlinks/glpk-doc-zip.php for a complete description of this modeling language. GNU MathProg is part of the GLPK solver. See http://www.gnu.org/software/glpk/glpk.html and http://gnuwin32.sourceforge.net/packages/glpk.htm for the homepage of it. Note that MathProg is a subset of the AMPL modeling language. See Using lpsolve from AMPL. The XLI used by lp_solve to read these models is derived from this code. lp_solve can read/write and solve these MathProg models directly via the xli_MathProg XLI driver (see External Language Interfaces). It reads such a model in above format and can solve it then. For example:
    lp_solve -rxli xli_MathProg Diet1.mod
This gives as result:
    Value of objective function: 88.2

    Actual values of the variables:
    Buy[BEEF]                       0
    Buy[CHK]                        0
    Buy[FISH]                       0
    Buy[HAM]                        0
    Buy[MCH]                  46.6667
    Buy[MTL]                        0
    Buy[SPG]                        0
    Buy[TUR]                        0
MathProg has also the possibility to have the model and data in two separate files. lp_solve can handle this also. For example:
    lp_solve -rxli xli_MathProg diet.mod -rxlidata diet.dat
This gives as result:
    Value of objective function: 88.2

    Actual values of the variables:
    Buy[BEEF]                       0
    Buy[CHK]                        0
    Buy[FISH]                       0
    Buy[HAM]                        0
    Buy[MCH]                  46.6667
    Buy[MTL]                        0
    Buy[SPG]                        0
    Buy[TUR]                        0
#### Generating MathProg models The XLI can also create a MathProg model, however it doesn't use the strength of the language. Constraints are written out line per line. But it can be a starter. For example:
    lp_solve model.lp -wxli xli_MathProg model.mod
This gives as model.mod:
    /* Variable definitions */
    var x >= 0;
    var y >= 0;

    /* Objective function */
    maximize obj: +143*x +60*y;

    /* Constraints */
    R1: +120*x +210*y <= 15000;
    R2: +110*x +30*y <= 4000;
    R3: +x +y <= 75;
#### API Use the lpsolve API call read_XLI to read a model and write_XLI to write a model. See also External Language Interfaces. #### IDE Also from within the IDE, this XLI can be used. However, some entries must be added in LpSolveIDE.ini (in the folder where the IDE is installed). In the [XLI] section the following must be added:
    lib1=xli_MathProg
And a new section for the MathProg XLI must also be added:
    [xli_MathProg]
    extension=.mod
    language=MATHPROG
Then make sure that the xli_MathProg.dll is available for the IDE. This must be done by placing this dll in the IDE folder or in the Windows system32 folder. #### Example models/data ##### Diet1.mod
    set NUTR;
    set FOOD;

    param cost {FOOD} > 0;
    param f_min {FOOD} >= 0;
    param f_max {j in FOOD} >= f_min[j];

    param n_min {NUTR} >= 0;
    param n_max {i in NUTR} >= n_min[i];

    param amt {NUTR,FOOD} >= 0;

    var Buy {j in FOOD} >= f_min[j], <= f_max[j];

    minimize total_cost:  sum {j in FOOD} cost[j] * Buy[j];

    subject to diet {i in NUTR}:
       n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];

    data;

    set NUTR := A B1 B2 C ;
    set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ;

    param:   cost  f_min  f_max :=
      BEEF   3.19    0     100
      CHK    2.59    0     100
      FISH   2.29    0     100
      HAM    2.89    0     100
      MCH    1.89    0     100
      MTL    1.99    0     100
      SPG    1.99    0     100
      TUR    2.49    0     100 ;

    param:   n_min  n_max :=
       A      700   10000
       C      700   10000
       B1     700   10000
       B2     700   10000 ;

    param amt (tr):
               A    C   B1   B2 :=
       BEEF   60   20   10   15
       CHK     8    0   20   20
       FISH    8   10   15   10
       HAM    40   40   35   10
       MCH    15   35   15   15
       MTL    70   30   15   15
       SPG    25   50   25   15
       TUR    60   20   15   10 ;
    end;
##### diet.mod
    set NUTR;
    set FOOD;

    param cost {FOOD} > 0;
    param f_min {FOOD} >= 0;
    param f_max {j in FOOD} >= f_min[j];

    param n_min {NUTR} >= 0;
    param n_max {i in NUTR} >= n_min[i];

    param amt {NUTR,FOOD} >= 0;

    var Buy {j in FOOD} >= f_min[j], <= f_max[j];

    minimize total_cost:  sum {j in FOOD} cost[j] * Buy[j];

    subject to diet {i in NUTR}:
       n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];
##### diet.dat
    set NUTR := A B1 B2 C ;
    set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ;

    param:   cost  f_min  f_max :=
      BEEF   3.19    0     100
      CHK    2.59    0     100
      FISH   2.29    0     100
      HAM    2.89    0     100
      MCH    1.89    0     100
      MTL    1.99    0     100
      SPG    1.99    0     100
      TUR    2.49    0     100 ;

    param:   n_min  n_max :=
       A      700   10000
       C      700   10000
       B1     700   10000
       B2     700   10000 ;

    param amt (tr):
               A    C   B1   B2 :=
       BEEF   60   20   10   15
       CHK     8    0   20   20
       FISH    8   10   15   10
       HAM    40   40   35   10
       MCH    15   35   15   15
       MTL    70   30   15   15
       SPG    25   50   25   15
       TUR    60   20   15   10 ;
##### model.lp
    /* model.lp */

    max: 143 x + 60 y;

    120 x + 210 y <= 15000;
    110 x + 30 y <= 4000;
    x + y <= 75;