Shadow prices with juice
A firm is employing two machines \(M_1\) and \(M_2\) to put grapefruit juice (\(g\)) and orange juice (\(o\)) in bottles. Its goal is to maximize profit subject to the constraints
M1: \(6g + 5.5o \leq 40\) and M2: \(3g + 2.5o \leq 20\)
The constraints reflect the productivity and availability of machines. For example, M1 is available for 40 hours per week and needs 6 hours to bottle 1 ton of grapefruit juice and 5.5 hours for a ton of orange juice.
There is an additional supply constraint where the firm only receives a maximum of 6 tons of grapefruit a week, and 12 tons of oranges. These are the upper bounds.
pulp
has been imported for you and model
has been defined as well as the variables g
and o
for grapefruit and orange juice.
Este ejercicio forma parte del curso
Introduction to Optimization in Python
Instrucciones del ejercicio
- Complete the for loop to include a check to see if shadow price is positive.
- Enter the variable that measures marginal increase in objective when constraint is relaxed.
- Enter the variable that measures how tight the constraint is.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
print(LpStatus[model.status])
print(f'The optimal amount of {g.name} embottled is: {g.varValue:.2f} tons')
print(f'The optimal amount of {o.name} embottled is: {o.varValue:.2f} tons')
for name, c in model.constraints.items():
# Check if shadow value is positive
if c.____ > 0:
# Enter the variable that measures marginal increase in objective when constraint is relaxed
print(f"Increasing the capacity of {name} by one unit would increase profit by {c.____} units.")
else:
# Enter the variable that measures how tight the constraint is
print(f"{name} has {c.____} units of unused capacity.")