Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

linear programming - Blend : minimize weight but keep it robust

enter image description here

I need to build an object.

The object is a mixture of 3 elements.

I need to minimize the object weight, but to keep it robust. (Please pardon my English...)

Elements are noted as in school (x/20), just like in the school class .

The minimum needed object strength is the following note : 10/20 .

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

This is the Pulp Linear Program I have built, what do you think about this, please ?

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))

What I can't understand is that constraint should be an average, like this, but it doesn't work :

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

**This is the result I get, is this correct, please ? Basically it says that I should use 9.3/20 steel and 10.6/20 plastic to get the slimmer object as possible but still robust ... Is this right ?

Status: Optimal
products__ceramic = 0.0
products__steel = 9.3333333
products__plastic = 10.666667
Note 10.66666674
question from:https://stackoverflow.com/questions/65829711/blend-minimize-weight-but-keep-it-robust

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...