混合:最小化重量但保持坚固

问题描述

enter image description here

我需要构建一个对象。

对象是 3 个元素的混合体。

我需要最小化对象的重量,但要保持它的健壮性。 (请原谅我的英语...)

元素在学校 (x/20) 中标注,就像在学校课堂中一样。

所需的最小对象强度如下所示:10/20。

           strength  weight
steel :    18/20      16/20
plastic :  3/20       6/20
ceramic:   12/20      10/20

这是我构建的 Pulp 线性程序,请问您对此有何看法?

from pulp import *

# I want to minimize weight
prob = LpProblem("Minimize",LpMinimize)

# Ingredients list and characteristics
products = ["steel","plastic","ceramic"]
strength = {"steel": 18,"plastic": 3,"ceramic": 12}
weight = {"steel": 16,"plastic": 6,"ceramic": 20}

# Build variables
x = LpVariable.dicts("products ",x,0)

# Objective function
prob += lpSum([weight[i] * x[i] for i in products ]),"MinimizeWeight"

# Constraints
prob += lpSum([(strength[i] * x[i]) / 20 for i in products]) >= 10,"strength"

# note Max Constraint ( Seen in most of blend problems...)
prob += lpSum([1 * x[f] for f in products]) == 20,"noteMax"


prob.solve()

for v in prob.variables ():
    print (v.name,"=",v.varValue)

print ("Note",value (prob.objective /20))

我无法理解的是约束应该是平均值,就像这样,但它不起作用:

   prob += (lpSum([(strength[i] * x[i])  for i in products]) / 3) >= 10,"strength"

**这是我得到的结果,请问正确吗?基本上它说我应该使用 9.3/20 钢和 10.6/20 塑料来获得尽可能纤薄但仍然坚固的物体......这是对的吗?

Status: Optimal
products__ceramic = 0.0
products__steel = 9.3333333
products__plastic = 10.666667
Note 10.66666674

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)