Reputation: 11
I spent about 4-5 hours last night searching Stack Overflow, going through scipy optimize documents etc and could not find an answer to my problem. My question is, how do I set a lower bounds for the optimization equation when the option only seems to be for upper bound? Please see my equation and code below.
import numpy as np
from scipy.optimize import linprog
from numpy.linalg import solve
c = np.array([4,7,5])
A = np.array([[4,1,10],[3,2,1],[0,4,5]])
b = np.array([10,12,20])
res = linprog(c,A_ub = A,b_ub = b)
print(res)
('Optimal value:', -0.0, '\nX:', array([ 0., 0., 0.]))
fun: -0.0
message: 'Optimization terminated successfully.'
nit: 0
slack: array([ 10., 12., 20.])
status: 0
success: True
x: array([ 0., 0., 0.])
('Optimal value:', -37.666666666666664, '\nX:', array([ 0.66666667, 5. ` , 0. ]))`
fun: -37.666666666666664
message: 'Optimization terminated successfully.'
nit: 2
slack: array([ 2.33333333, 0. , 0. ])
status: 0
success: True
x: array([ 0.66666667, 5. , 0. ])
It is giving me an answer in the first one to minimize x1,x2,x3 which obviously shows all zeros. The 2nd answer maximizes the function if each is <=10,<=12,<=20 because obviously it is an upper bound. What I need is the best possible answer based on being >=10,>=12,>=20 minimizing on the function.
Sorry if this is easy! I spent many hours crawling the web on this...
Upvotes: 0
Views: 1180
Reputation: 16752
a'x >= b
is the same as -a'x <= -b
. I.e. multiply the >=
inequality by -1.
Upvotes: 1