| 1 |
""" |
| 2 |
Example problem file that solves the whiskas blending problem |
| 3 |
""" |
| 4 |
import pulp |
| 5 |
|
| 6 |
|
| 7 |
whiskas_model = pulp.LpProblem("The Whiskas Problem", pulp.LpMinimize) |
| 8 |
|
| 9 |
ingredients = ["chicken", "beef", "mutton", "rice", "wheat", "gel"] |
| 10 |
|
| 11 |
|
| 12 |
x = pulp.LpVariable.dict("x_%s", ingredients, lowBound=0) |
| 13 |
|
| 14 |
|
| 15 |
cost = dict(zip(ingredients, [0.013, 0.008, 0.010, 0.002, 0.005, 0.001])) |
| 16 |
|
| 17 |
whiskas_model += sum([cost[i] * x[i] for i in ingredients]) |
| 18 |
|
| 19 |
|
| 20 |
protein = dict(zip(ingredients, [0.100, 0.200, 0.150, 0.000, 0.040, 0.000])) |
| 21 |
fat = dict(zip(ingredients, [0.080, 0.100, 0.110, 0.010, 0.010, 0.000])) |
| 22 |
fibre = dict(zip(ingredients, [0.001, 0.005, 0.003, 0.100, 0.150, 0.000])) |
| 23 |
salt = dict(zip(ingredients, [0.002, 0.005, 0.007, 0.002, 0.008, 0.000])) |
| 24 |
|
| 25 |
|
| 26 |
whiskas_model += sum([protein[i] * x[i] for i in ingredients]) >= 8.0 |
| 27 |
whiskas_model += sum([fat[i] * x[i] for i in ingredients]) >= 6.0 |
| 28 |
whiskas_model += sum([fibre[i] * x[i] for i in ingredients]) <= 2.0 |
| 29 |
whiskas_model += sum([salt[i] * x[i] for i in ingredients]) <= 0.4 |
| 30 |
|
| 31 |
|
| 32 |
whiskas_model.solve() |
| 33 |
|
| 34 |
|
| 35 |
for ingredient in ingredients: |
| 36 |
print("The mass of %s is %s grams per can" % (ingredient, x[ingredient].value())) |