Employing Linear Programming
369
The model is ready to optimize (it has ingested both the objective function and the
constraints). Call the
solve
method and then check its status. (Sometimes a solu-
tion may prove impossible to find or may not be optimal.)
model.solve()
print ('Completion status: %s'
% pulp.LpStatus[model.status])
Completion status: Optimal
Having received confirmation that the optimizer found the optimal solution, you
print the related quantities of product A and B.
print ("Production of model A = %0.1f" % A.varValue)
print ("Production of model B = %0.1f" % B.varValue)
Production of model A = 16.0
Production of model B = 6.0
In addition, you print the resulting total profit achievable by this solution.
print ('Maximum profit achieved: %0.1f'
% pulp.value(model.objective))
Maximum profit achieved: 63000.0
CHAPTER 20
Do'stlaringiz bilan baham: |