
422 Introduction to Computational Models with Python
# Arc Capacity Constraints
model += x[1,2] <= 7,"Arc 1-2"
model += x[2,3] <= 4,"Arc 2-3"
model += x[2,4] <= 3,"Arc 2-4"
model += x[3,4] <= 6,"Arc 3-4"
model += x[3,5] <= 3,"Arc 3-5"
model += x[4,5] <= 4,"Arc 4-5"
# Intermediate Node Constraints
model += x[1,2] - x[2,3] - x[2,4] + y[2] <= 0,"Node 2"
model += x[2,3] - x[3,4] - x[3,5] + y[3] <= 0,"Node 3"
model += x[2,4] + x[3,4] - x[4,5] + y[4] <= 0,"Node 4"
# Solve the optimization problem using the PuLP Solver
model.solve(GLPK())
# Print the status of the solution
print "Status:", LpStatus[model.status]
# Print each of the variables with it’s resolved optimum ...