PuLP installation:
pip install pulp
In [ ]:
from pulp import LpProblem, LpVariable, lpSum, LpMaximize, value
In [ ]:
prob = LpProblem("Dedication Model", LpMaximize)
In [ ]:
X1 = LpVariable("X1", 0, None)
X2 = LpVariable("X2", 0, None)
In [ ]:
# Objective function
prob += 4*X1 + 3*X2 # Objectives are nothing more than expressions without a right hand side
# Constraints
prob += X1 + X2 <= 100
prob += 2*X1 + X2 <= 150
prob += 3*X1 + 4*X2 <= 360
In [ ]:
prob.solve()
In [ ]:
print("Optimal total cost is: ", value(prob.objective))
In [ ]:
print("X1 :", X1.varValue)
print("X2 :", X2.varValue)