Solving Linear Optimization Models 351
67 # Write the problem data to an .lp file
68 model.writeLP("casestud1b.lp")
69
70 # Solve the optimization problem using the specified PuLP Solver
71 model.solve(GLPK())
72
73 # Print the status of the solution
74 print "Status:", LpStatus[model.status]
75
76 # Print each of the variables with its resolved optimum value
77 for v in model.variables():
78 print v.name, "=", v.varValue
79
80 # Print the optimised value of the objective function
81 print "Optimal sales", value(model.objective)
The data are set with Python lists and dictionaries on lines 11–31 and
is exactly the same as in the model using Pyomo. Lines 33–48 displays the
problem data for verification purposes.
The Pulp model for the problem is declared in