线性规划LP建模实例——黄瓜洋葱
Required Files: crop.mod, configExe
A farmer is producing two types of vegetables: cucumbers and onions. His goal is
to produce the maximum weight of vegetables knowing that the yield is
4kg/m² for cucumbers and 5kg/m² for onions. In order to crop his
vegetables he must use two types of fertilizer, A and B.8l of fertilizer A is available 2l/m² is needed for cucumbers and
1l/m² for onions 7l of fertilizer B is available 1l/m² is needed for
cucumbers and 2l/m² for onions Unfortunatly, he must also use an
anti-parasite in order to prevent his crops from being degraded.3l of anti-parasites is available 1l/m² is needed for onions
Question: model this problem as a linear program.
crop.mod
/*********************************************
* OPL 12.6.0.0 Model
* Crop
*********************************************/
//Data declarations.
//Make sure you use c[i] to access the i-th cost
//and do not remove/change the following line
float c[1..2] = [4, 5];
//Decision variables.
dvar float+ concombre;
dvar float+ onion;
//Objective function.
maximize concombre*c[1]+onion*c[2];
//Constraints
subject to {
concombre*2+onion*1<=8 ;
concombre*1+onion*2<=7 ;
concombre*0+onion*1<=3 ;
}
// Display
execute {
writeln("Post treatment: ");
writeln("The objectif's value is "+cplex.getObjValue());
}
运行结果: