线性规划LP建模实例——苹果发酵和蒸馏
Apples Required Files: cider.mod, configExe
Maximum number of files:10
Type of work: Individual workA factory produces juice or cider from apples. The price of a ton of
apples is 1500€. Each ton of apples can yield 500 liters of juice or
250 liters of cider. The maximum possible sales (in liters) and
selling prices are given in the following table:
By fermentation and distillation, the factory can also produce cider from apple juice and Calvados from cider.
Fermenting a liter of apple juice produces 0.6 liters of cider, and distilling a liter of cider gives 0.4 liters of Calvados.
The factory can sell a maximum of 500 liters of Calvados, at a selling price of 10€/liter.The problem is to maximize the profit of the factory.
Question: model this problem as a linear program.
cider.mod
/*********************************************
* OPL 12.6.0.0 Model
* Cider
*********************************************/
//Data declarations.
//Make sure you use c[i] to access the i-th data
//and do not remove/change the following line
float c[1..4] = [-1500,4, 8, 10];
//Decision variables.
dvar float+ apples;
dvar float+ juices;
dvar float+ ciders;
dvar float+ calvados;
dvar float+ ciders_oP; // ciders of apples
dvar float+ juices_oP; //juices of apples
dvar float+ ciders_fC; // ciders for calvados
dvar float+ juices_fC; //juices for ciders
//Objective function.
maximize apples*c[1]+juices*c[2]+ciders*c[3]+calvados*c[4];
//Constraints
subject to {
Apple:
ciders_oP/250+juices_oP/500==apples;
Juice:
juices_oP-juices_fC==juices;
juices<=5000;
Cider:
juices_fC*0.6+ciders_oP-ciders_fC==ciders;
ciders<=2000;
Calvados:
ciders_fC*0.4==calvados;
calvados<=500;
}
// Display
execute {
writeln("Post treatment: ");
writeln("The objectif's value is "+cplex.getObjValue());
}
换种写法:
dvar float+ pomme;
dvar float+ jusDePomme;
dvar float+ jusDePomme_A_Vendre;
dvar float+ cidreDePomme;
dvar float+ cidreFermente;
dvar float+ cidre_A_Vendre;
dvar float+ calvados;
//Objective function.
maximize c[1] * pomme + c[2] * jusDePomme_A_Vendre + c[3] * cidre_A_Vendre + c[4] * calvados;
//Constraints
subject to {
//Jus de pomme
jusDePomme/500 + cidreDePomme/250 == pomme;
jusDePomme_A_Vendre + cidreFermente/0.6 == jusDePomme;
jusDePomme_A_Vendre <= 5000;
//Cidre
cidre_A_Vendre + calvados/0.4 == cidreDePomme + cidreFermente;
cidre_A_Vendre <= 2000;
//Calvados
calvados <= 500;
}
// Display
execute {
writeln("Post treatment: ");
writeln("The objectif's value is "+cplex.getObjValue());
}
运行结果
Default LOCALE: en_US.UTF-8
IBM ILOG CPLEX Optimization Studio Community Edition. The CPLEX Optimizers will solve problems up to 1000 variables and 1000 constr
aints.
CP Optimizer (Community Edition) solves problems with a search space of up to 2^1000
<<< setup, at 0s, took 1.64588e+09s
<<< generate, at 0s, took 0.00443316s
Tried aggregator 1 time.
LP Presolve eliminated 7 rows and 8 columns.
All rows and columns eliminated.
Presolve time = 0.00 sec. (0.00 ticks)
<<< solve, at 0s, took 0.000446796s
OBJECTIVE: 11000
Post treatment:
The objectif's value is 11000
<<< post process, at 0s, took 0.00019002s
// solution (optimal) with objective 11000
// Quality There are no bound infeasibilities.
// There are no reduced-cost infeasibilities.
// Max. unscaled (scaled) Ax-b resid. = 4.54747e-13 (4.54747e-13)
// Max. unscaled (scaled) c-B'pi resid. = 0 (0)
// Max. unscaled (scaled) |x| = 8333.33 (8333.33)
// Max. unscaled (scaled) |slack| = 500 (500)
// Max. unscaled (scaled) |pi| = 1500 (1500)
// Max. unscaled (scaled) |red-cost| = 2.5 (2.5)
// Condition number of scaled basis = 1.7e+01
//
apples = 16.667;
juices = 5000;
ciders = 2000;
calvados = 0;
ciders_oP = 0;
juices_oP = 8333.3;
juices_fC = 3333.3;
ciders_fC = 0;
<<< done, at 0s, took 0.000254154s