python - Specifying greater than inequality in scipy -


i've solved simple lp problem constraints "less or equal to".

i used scipy.optimize.linprog those.

the problem when 1 or more of constraints equation "greater or equal to". how specify that? need use two-phase approach provided scipy.optimize.linprog

an example of such is:

      7x1 + 4x2 + 9x3 ≥ 750                                                                                   4x1 + 6x2 + 7x3 ≤ 40     17x1 + 9x2 + 2.5x3 ≥ 3540                                                                                   56x1 + 3x2 + 27x3 ≤ 6450   

here wrapper incorporates lower bound rows in lingprog formulation. note more error trapping necessary (for example, number of columns of each a matrix need equal), not meant robust implementation. proper error trapping, suggest skim through linprog source code.

from scipy.optimize import linprog import numpy np  def linprog_lb_wrapper(c, a_ub=none, b_ub=none, a_lb=none, b_lb=none, a_eq=none, b_eq=none, \     bounds=none, method='simplex', callback=none, options=none):      if a_lb none:         res = linprog(c, a_ub, b_ub, a_eq, b_eq, bounds, method, callback, options)         return res     elif (b_lb none) or (len(b_lb) != len(a_lb)):         # catch error here         print('error')      a_ub_new, b_ub_new = np.array(a_ub), np.array(b_ub)     a_lb_new, b_lb_new = np.array(a_lb), np.array(b_lb)     a_lb_new *= -1.     b_lb_new *= -1.     a_ub_new = np.vstack((a_ub_new, a_lb_new))     b_ub_new = np.vstack((b_ub_new, b_lb_new))      res = linprog(c=c, a_ub=a_ub_new, b_ub=b_ub_new, a_eq=a_eq, b_eq=b_eq, bounds=bounds, \          method=method, callback=callback, options=options)      return res  def test():     c = [0, 0, 0]     a_ub = [[4, 6, 7], [56, 3, 27]]     b_ub = [40, 6450]     a_lb = [[7, 4, 9], [17, 9, 2.5]]     b_lb = [750, 3540]     bounds = ((none, none), (none, none), (none, none))      res = linprog_lb_wrapper(c=c, a_ub=a_ub, b_ub=b_ub, a_lb=a_lb, b_lb=b_lb, bounds=bounds)     print(res)  test() 

note instance presented, there no feasible solution (i checked solver , got infeasibility proof).

i hope helps.

this code can tested here.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -