¡Esta es una revisión vieja del documento!
GNU MathProg
Nota: Esta página es la traducción (en curso) al español de http://lpsolve.sourceforge.net/5.5/MathProg.htm
GNU MathProg es un lenguaje de modelización para la descripción de modelos de programación matemática lineal. Un modelo escrito el lenguaje GNU MathProg consiste en un conjunto de instrucciones y bloques de datos construidos por el usuario.
Véase http://gnuwin32.sourceforge.net/downlinks/glpk-doc-zip.php para una descripción completa de este lenguaje de modelado.
GNU MathProg es parte de GLPK solver. Las páginas principales son http://www.gnu.org/software/glpk/glpk.html y http://gnuwin32.sourceforge.net/packages/glpk.htm.
Obsérvese que MathProg es un subconjunto del lenguaje de modelización AMPL. Véase Using lpsolve from AMPL. El XLI usado por lp_solve para leer estos modelos está derivado de este código.
lp_solve puede leer, escribir y resolver estos modelos MathProg directamente vía el driver xli_MathProg (véase External Language Interfaces. Puede leer los modelos en el formato anterior y puede resolverlos.
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;