Estos apuntes son libres y los puedes editar.

Algunas secciones están en inglés puedes colaborar traduciendo algunos párrafos.

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
Próxima revisión Ambos lados, revisión siguiente
gnu_mathprog [2008/10/04 19:55]
mmarquez
gnu_mathprog [2008/10/05 20:14]
mmarquez
Línea 2: Línea 2:
 Nota: Esta página es la traducción (en curso) al español de [[http://lpsolve.sourceforge.net/5.5/MathProg.htm]] Nota: Esta página es la traducción (en curso) al español de [[http://lpsolve.sourceforge.net/5.5/MathProg.htm]]
 ---- ----
 +===== Introducción =====
  
 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. 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.
Línea 9: Línea 10:
 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]]. 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 [[http://lpsolve.sourceforge.net/5.5/AMPL.htm|Using lpsolve from AMPL]. El XLI usado por lp_solve para leer estos modelos está derivado de este código.+Obsérvese que MathProg es un subconjunto del lenguaje de modelización AMPL. Véase [[http://lpsolve.sourceforge.net/5.5/AMPL.htm|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 [[http://lpsolve.sourceforge.net/5.5/XLI.htm|External Language Interfaces]]. Puede leer los modelos en el formato anterior y puede resolverlos. lp_solve puede leer, escribir y resolver estos modelos MathProg directamente vía el driver xli_MathProg (véase [[http://lpsolve.sourceforge.net/5.5/XLI.htm|External Language Interfaces]]. Puede leer los modelos en el formato anterior y puede resolverlos.
  
-----+Por ejemplo:
  
-For example:+   lp_solve -rxli xli_MathProg Diet1.mod
  
-lp_solve -rxli xli_MathProg Diet1.mod+Que da como resultado:
  
-This gives as result:+   Value of objective function88.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
  
-Value of objective function: 88.2+MathProg tiene también la posibilidad de tener el modelo y los datos en dos ficheros separadoslp_solve puede tratar esta situación. Por ejemplo:
  
-Actual values of the variables: +   lp_solve -rxli xli_MathProg diet.mod -rxlidata diet.dat
-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:+Que da como resultado:
  
-lp_solve -rxli xli_MathProg diet.mod -rxlidata diet.dat+   Value of objective function: 88.
 +     
 +   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
  
-This gives as result: 
  
-Value of objective function: 88.2+===== Generación de modelos MathProg =====
  
-Actual values of the variables: +El XLI puede crear modelos MathProg, no obstante no usa las capacidades del lenguajeLas restricciones se escriben línea a línea. Pero puede ser el comienzo. Por ejemplo:
-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+   lp_solve model.lp -wxli xli_MathProg model.mod
  
-The XLI can also create a MathProg model, however it doesn't use the strength of the languageConstraints are written out line per line. But it can be a starter. For example:+Resulta model.mod:
  
-lp_solve model.lp -wxli xli_MathProg 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;
  
-This gives as model.mod:+===== API =====
  
-/* Variable definitions */ +Use la llamada a [[http://lpsolve.sourceforge.net/5.5/read_XLI.htm|read_XLI]] para leer un modelo [[http://lpsolve.sourceforge.net/5.5/write_XLI.htm|write_XLI]] para escribirlo. Véase también [[http://lpsolve.sourceforge.net/5.5/XLI.htm|External Language Interfaces]].
-var x >= 0; +
-var >= 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). 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).
Línea 80: Línea 80:
 In the [XLI] section the following must be added: In the [XLI] section the following must be added:
  
-lib1=xli_MathProg+   lib1=xli_MathProg
  
 And a new section for the MathProg XLI must also be added: And a new section for the MathProg XLI must also be added:
  
-[xli_MathProg] +   [xli_MathProg] 
-extension=.mod +   extension=.mod 
-language=MATHPROG+   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. 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; +===== Ejemplos =====
-set FOOD;+
  
-param cost {FOOD} > 0; +==== Diet1.mod ====
-param f_min {FOOD} >0; +
-param f_max {j in FOOD} >f_min[j];+
  
-param n_min {NUTR} >= 0; +   set NUTR; 
-param n_max {i in NUTR} >= n_min[i]; +   set FOOD; 
- +     
-param amt {NUTR,FOOD} >= 0; +   param cost {FOOD} > 0; 
- +   param f_min {FOOD} >= 0; 
-var Buy {j in FOOD} >= f_min[j], <= f_max[j]; +   param f_max {j in FOOD} >= f_min[j]; 
- +     
-minimize total_cost:  sum {j in FOOD} cost[j] * Buy[j]; +   param n_min {NUTR} >= 0; 
- +   param n_max {i in NUTR} >= n_min[i]; 
-subject to diet {i in NUTR}:+     
 +   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];    n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];
- +     
- +     
-data; +   data; 
- +     
-set NUTR := A B1 B2 C ; +   set NUTR := A B1 B2 C ; 
-set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ; +   set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ; 
- +     
-param:   cost  f_min  f_max := +   param:   cost  f_min  f_max := 
-  BEEF   3.19    0     100 +    BEEF   3.19    0     100 
-  CHK    2.59    0     100 +    CHK    2.59    0     100 
-  FISH   2.29    0     100 +    FISH   2.29    0     100 
-  HAM    2.89    0     100 +    HAM    2.89    0     100 
-  MCH    1.89    0     100 +    MCH    1.89    0     100 
-  MTL    1.99    0     100 +    MTL    1.99    0     100 
-  SPG    1.99    0     100 +    SPG    1.99    0     100 
-  TUR    2.49    0     100 ; +    TUR    2.49    0     100 ; 
- +     
-param:   n_min  n_max := +   param:   n_min  n_max := 
-   A      700   10000 +    A      700   10000 
-   C      700   10000 +    C      700   10000 
-   B1     700   10000 +    B1     700   10000 
-   B2     700   10000 ; +    B2     700   10000 ; 
- +     
-param amt (tr):+   param amt (tr):
               C   B1   B2 :=               C   B1   B2 :=
-   BEEF   60   20   10   15 +    BEEF   60   20   10   15 
-   CHK        0   20   20 +    CHK        0   20   20 
-   FISH    8   10   15   10 +    FISH    8   10   15   10 
-   HAM    40   40   35   10 +    HAM    40   40   35   10 
-   MCH    15   35   15   15 +    MCH    15   35   15   15 
-   MTL    70   30   15   15 +    MTL    70   30   15   15 
-   SPG    25   50   25   15 +    SPG    25   50   25   15 
-   TUR    60   20   15   10 ; +    TUR    60   20   15   10 ; 
-end;+   end;
  
-diet.mod+==== diet.mod ====
  
-set NUTR; +   set NUTR; 
-set FOOD; +   set FOOD; 
- +     
-param cost {FOOD} > 0; +   param cost {FOOD} > 0; 
-param f_min {FOOD} >= 0; +   param f_min {FOOD} >= 0; 
-param f_max {j in FOOD} >= f_min[j]; +   param f_max {j in FOOD} >= f_min[j]; 
- +     
-param n_min {NUTR} >= 0; +   param n_min {NUTR} >= 0; 
-param n_max {i in NUTR} >= n_min[i]; +   param n_max {i in NUTR} >= n_min[i]; 
- +     
-param amt {NUTR,FOOD} >= 0; +   param amt {NUTR,FOOD} >= 0; 
- +     
-var Buy {j in FOOD} >= f_min[j], <= f_max[j]; +   var Buy {j in FOOD} >= f_min[j], <= f_max[j]; 
- +     
-minimize total_cost:  sum {j in FOOD} cost[j] * Buy[j]; +   minimize total_cost:  sum {j in FOOD} cost[j] * Buy[j]; 
- +     
-subject to diet {i in NUTR}:+   subject to diet {i in NUTR}:
    n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];    n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i];
  
-diet.dat+==== diet.dat ====
  
-set NUTR := A B1 B2 C ; +   set NUTR := A B1 B2 C ; 
-set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ; +   set FOOD := BEEF CHK FISH HAM MCH MTL SPG TUR ; 
- +     
-param:   cost  f_min  f_max := +   param:   cost  f_min  f_max := 
-  BEEF   3.19    0     100 +    BEEF   3.19    0     100 
-  CHK    2.59    0     100 +    CHK    2.59    0     100 
-  FISH   2.29    0     100 +    FISH   2.29    0     100 
-  HAM    2.89    0     100 +    HAM    2.89    0     100 
-  MCH    1.89    0     100 +    MCH    1.89    0     100 
-  MTL    1.99    0     100 +    MTL    1.99    0     100 
-  SPG    1.99    0     100 +    SPG    1.99    0     100 
-  TUR    2.49    0     100 ; +    TUR    2.49    0     100 ; 
- +     
-param:   n_min  n_max := +   param:   n_min  n_max := 
-   A      700   10000 +    A      700   10000 
-   C      700   10000 +    C      700   10000 
-   B1     700   10000 +    B1     700   10000 
-   B2     700   10000 ; +    B2     700   10000 ; 
- +     
-param amt (tr):+   param amt (tr):
               C   B1   B2 :=               C   B1   B2 :=
-   BEEF   60   20   10   15 +    BEEF   60   20   10   15 
-   CHK        0   20   20 +    CHK        0   20   20 
-   FISH    8   10   15   10 +    FISH    8   10   15   10 
-   HAM    40   40   35   10 +    HAM    40   40   35   10 
-   MCH    15   35   15   15 +    MCH    15   35   15   15 
-   MTL    70   30   15   15 +    MTL    70   30   15   15 
-   SPG    25   50   25   15 +    SPG    25   50   25   15 
-   TUR    60   20   15   10 ; +    TUR    60   20   15   10 ;
- +
-model.lp +
- +
-/* model.lp */+
  
-max: 143 x + 60 y;+==== model.lp ====
  
-120 x + 210 y <= 15000; +   /* model.lp */ 
-110 x + 30 y <= 4000; +     
-x + y <= 75;+   max: 143 x + 60 y; 
 +     
 +   120 x + 210 y <= 15000; 
 +   110 x + 30 y <= 4000; 
 +   x + y <= 75;
  

QR Code
QR Code gnu_mathprog (generated for current page)