In [ ]:
import scipy.optimize
Problem examples:
In [ ]:
# Coefficients of the linear objective function to be minimized
c = [-1, 4]
# 2-D array which, when matrix-multiplied by x, gives the values of the upper-bound inequality constraints at x.
A = [[-3, 1],
[ 1, 2]]
# 1-D array of values representing the upper-bound of each inequality constraint (row) in A.
b = [6, 4]
# Sequence of (min, max) pairs for each element in x, defining the bounds on that parameter.
# Use None for one of min or max when there is no bound in that direction.
# By default bounds are (0, None) (non-negative).
# If a sequence containing a single tuple is provided, then min and max will be applied to all variables in the problem.
x0_bounds = (None, None)
x1_bounds = (-3, None)
bounds = (x0_bounds,x1_bounds)
scipy.optimize.linprog(c, A_ub=A, b_ub=b, bounds=bounds)
In [ ]:
# Coefficients of the linear objective function to be minimized
c = np.array([3, 5])
# 2-D array which, when matrix-multiplied by x, gives the values of the upper-bound inequality constraints at x.
A_ub = np.array([[3, 2],
[1, 2],
[5, 4]])
# 1-D array of values representing the upper-bound of each inequality constraint (row) in A_ub.
b_ub = np.array([700, 500, 1500])
# Sequence of (min, max) pairs for each element in x, defining the bounds on that parameter.
# Use None for one of min or max when there is no bound in that direction.
# By default bounds are (0, None) (non-negative).
# If a sequence containing a single tuple is provided, then min and max will be applied to all variables in the problem.
bounds = ((0, None), (0, None))
scipy.optimize.linprog(-c, A_ub=A_ub, b_ub=b_ub, bounds=bounds)
The optimal solution is obtain for $x_1=100$ and $x_2=200$ with a gain of 1300.