美文网首页
【工程】Pulp-案例混合问题(四)

【工程】Pulp-案例混合问题(四)

作者: longgb246 | 来源:发表于2018-04-07 12:32 被阅读0次

    一、问题描述

    Ben这个人,想要尽可能便宜地生产他们的猫粮产品,同时确保他们满足罐装食品的营养分析要求。因此,他们想要改变每种食材的用量(主要成分是鸡肉、牛肉、羊肉、大米、小麦和凝胶),同时还能满足他们的营养标准。
    鸡肉、牛肉和羊肉的成本分别为0.013美元、0.008美元和0.010美元,而大米、小麦和凝胶的成本分别为0.002美元、0.005美元和0.001美元(所有费用都是每克)。
    食材与营养之间的关系如下,每克食材的贡献(克):

    image.png

    假设只想用两种食材来制作猫粮:鸡肉和牛肉。

    决策变量:
    $x_{1}$:鸡肉
    $x_{2}$:牛肉

    目标函数:
    $$min(0.013*x_{1}+0.008x_{2})$$

    约束条件:
    $$\left{
    \begin{aligned}
    x_{1}+x_{2} & = 100\
    0.1x_{1}+0.2x_{2} & \geqslant 8\
    0.08x_{1}+0.1x_{2} & \geqslant 6\
    0.001x_{1}+0.005x_{2} & \leqslant 2\
    0.002x_{1}+0.005x_{2} & \leqslant 0.4\
    \end{aligned}
    \right.$$

    使用python程序来解决:

    # Import PuLP modeler functions
    from pulp import *
    
    # Create the 'prob' variable to contain the problem data
    prob = LpProblem("The Whiskas Problem",LpMinimize)
    
    # The 2 variables Beef and Chicken are created with a lower limit of zero
    x1=LpVariable("ChickenPercent",0,None,LpInteger)
    x2=LpVariable("BeefPercent",0)
    
    # The objective function is added to 'prob' first
    prob += 0.013*x1 + 0.008*x2, "Total Cost of Ingredients per can"
    
    # The five constraints are entered
    prob += x1 + x2 == 100, "PercentagesSum"
    prob += 0.100*x1 + 0.200*x2 >= 8.0, "ProteinRequirement"
    prob += 0.080*x1 + 0.100*x2 >= 6.0, "FatRequirement"
    prob += 0.001*x1 + 0.005*x2 <= 2.0, "FibreRequirement"
    prob += 0.002*x1 + 0.005*x2 <= 0.4, "SaltRequirement"
    
    # The problem data is written to an .lp file
    prob.writeLP("WhiskasModel.lp")
    
    # The problem is solved using PuLP's choice of Solver
    prob.solve()
    
    # The status of the solution is printed to the screen
    print "Status:", LpStatus[prob.status]
    
    # Each of the variables is printed with it's resolved optimum value
    for v in prob.variables():
        print v.name, "=", v.varValue
        
    # The optimised objective function value is printed to the screen
    print "Total Cost of Ingredients per can = ", value(prob.objective)
    

    相关文章

      网友评论

          本文标题:【工程】Pulp-案例混合问题(四)

          本文链接:https://www.haomeiwen.com/subject/acqyhftx.html