The diet problem revisited
You are reviewing the financials for a farmer who asked you to revisit the diet of his pigs and cut on the cost if possible. The current cost minimization diet is based on the vet's recommendation for at least 17% protein, 2% fat, 7lb food following specifications
Food | Cost ($/lb) | Protein (%) | Fat (%) |
---|---|---|---|
corn | 0.11 | 10 | 2.5 |
soybean | 0.28 | 40 | 1 |
You have the information that the 7 lb was a rounded figure and could decrease to 6.6 lb. You are asked to see how changing the weight or fat constraints one at a time affects the minimum cost. You will solve the original problem as is and examine the slack and shadow price.
pulp
has been imported for you and model
has been defined as well as the variables C
and S
for corn and soybean.
Este exercício faz parte do curso
Introduction to Optimization in Python
Instruções do exercício
- Print the slack of the Weight constraint.
- Check if the shadow price of the Weight constraint is greater than 0.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
model.constraints['Weight'] = C + S >= 7
model.solve()
print(f"Status: {LpStatus[model.status]}\n")
# Print the slack of the weight constraint
print("The slack of the Weight constraint is {}",
____.constraints['Weight'].____)
# Check if the shadow price is greater than 0
if ____.constraints['Weight'].____ > 0:
print('Tightening the constraint will increase minimum cost')