Solving an integer linear programming problem with PuLP


In [1]:
import pulp

Objective function

$$z(max) = 7x_1 + 6x_2$$

Constraints:

  • $C_1 = 2x_1 + 3x_2 \leq 12$
  • $C_2 = 6x_1 + 5x_2 \leq 30$
  • $x_1,x_2 \geq 0$
  • $x_1, x_2 \space must \space be \space Integers$

In [2]:
z = pulp.LpProblem('problem x', pulp.LpMaximize)
x1 = pulp.LpVariable('x1', lowBound=0, cat='Integer')
x2 = pulp.LpVariable('x2', lowBound=0, cat='Integer')

In [3]:
z += 7*x1 + 6*x2

In [4]:
z += 2*x1 + 3*x2 <= 12
z += 6*x1 + 5*x2 <= 30

In [5]:
pulp.LpStatus[z.solve()]


Out[5]:
'Optimal'

In [6]:
pulp.value(x1), pulp.value(x2), pulp.value(z.objective)


Out[6]:
(5.0, 0.0, 35.0)