【线性规划LP建模实例——黄瓜洋葱】

本文介绍了一位农民如何使用线性规划方法来决定种植黄瓜和洋葱的最佳配比,考虑了肥料A和B的用量限制,以及防虫剂的需求,目标是最大化蔬菜总重量。通过crop.mod文件模型,展示了如何运用4kg/m²黄瓜和5kg/m²洋葱的单位面积产量,以及相应的肥料和防虫剂需求,实现农业生产的高效计划。
摘要由CSDN通过智能技术生成

线性规划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());
} 

运行结果:
最大值22

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值