In [1]:
from scipy.optimize import linprog
import numpy as np
In [2]:
z = np.array([ 7, 6])
In [3]:
C = np.array([
[ 2, 3], #C1
[ 6, 5] #C2
])
In [4]:
b = np.array([12, 30])
In [5]:
x1 = (0, None)
x2 = (0, None)
In [6]:
sol = linprog(-z, A_ub = C, b_ub = b, bounds = (x1, x2), method='simplex')
In [7]:
sol
Out[7]:
In this case this problem is not giving Integer Variables.
Getting integer variables, add options={'maxiter':True}
in the parameters of linprog
.
In [8]:
sol = linprog(-z, A_ub = C, b_ub = b, bounds = (x1, x2), method='simplex', options={'maxiter':True})
In [9]:
sol
Out[9]:
To print the values that we need:
In [10]:
print(f"x1 = {sol.x[0]}, x2 = {sol.x[1]}, z = {sol.fun*-1}")
LP problem is solved, to check the result just replace the values $x_1$ and $x_2$ into the objective function.
$z(max) = 7x_1 + 6x_2$
$z(max) = 7*5 + 6*0$
$z(max) = 35$