4

I'm using scipy.optimize.linprog library to calculate the minimization using the simplex method. I have two cases where I am getting error:

"ValueError: Phase 1 of the simplex method failed to find a feasible solution. The pseudo-objective function evaluates to 3.1e-12 which exceeds the required tolerance of 1e-12 for a solution to be considered 'close enough' to zero to be a basic solution. Consider increasing the tolerance to be greater than 3.1e-12. If this tolerance is unacceptably large the problem may be infeasible. ".

Maybe someone will find where the problem is.

Minimaze:     45x1 + 54x2 + 42x3 + 36x4

Subject to:   x1 + x2 + x3 + x4 = 1600
              30x1 + 60x2 + 70x3 + 80x4 = 100000
              30x1 + 40x2 + 0x3 + 20x4 = 30000

The code I wrote:

A = np.array([[-30, -60, -70, -80], [-30, -40, 0, -20], [-1, -1, -1, -1]])
b = np.array([-100000, -30000, -1600])
c = np.array([45, 54, 42, 36])

res = linprog(c, A_eq=A, b_eq=b, bounds=(0, None))

Here is the second examples:

Minimize:     100x1 + 50x2 + 100x3

Subject to:   x1 + x2 + x3 = 3000
              28x1 + 14x2 + 10x3 <= 42000
              10x1 + 12x2 + 6x3 <= 24000
              30x1 + 20x2 + 30x3 >= 75000
              10x1 + 10x2 + 15x3 >= 36000

Here is the code:

A_ub = np.array([[28, 14, 10], [10, 12, 6], [-30, -20, -30], [-10, -10, -15]])
b_ub = np.array([42000, 24000, -75000, -36000])
A_eq = np.array([[1, 1, 1]])
b_eq = np.array([3000])
c = np.array([100, 50, 200])

res = linprog(c, A_ub, b_ub, A_eq, b_eq, bounds=(0, None))

print('Optimal value:', res.fun, '\nX:', res.x)
Dubster
  • 71
  • 4
  • Please add the objective function (Minimize:) to first example. It is missing. – kcw78 Jan 16 '19 at 14:21
  • If I remove the equality constraint the `linprog` works just fine. The program is telling you there isn't a valid set of values that can satisfy all of the constraints. You should check that. – Mstaino Jan 16 '19 at 14:33
  • Well, both solutions is feasible @Mstaino – rockikz Jan 16 '19 at 16:52

2 Answers2

4

I checked the system and solutions are indeed feasible. After reading this post, it seems that there are floating point issues in linprog, clearly a problem of the method. Seems that passing method='interior-point' improves the algorithm.

It worked for me in both cases

Case 1:

res = linprog(c, A_eq=A, b_eq=b, method='interior-point')
print('Optimal value:', res.fun, '\nX:', res.x)
>> Optimal value: 64090.8624935836 
X: [4.90908724e+02 1.50821194e-05 3.45454303e+02 7.63635788e+02]

Case 2:

res = linprog(c, A_ub, b_ub, A_eq, b_eq, bounds=(0, None), method='interior-point')
print('Optimal value:', res.fun, '\nX:', res.x)
#output:
>> Optimal value: 449999.99988966336 
X: [ 377.22836393  748.5144238  1874.25721154]
Mstaino
  • 3,568
  • 1
  • 7
  • 19
  • did you check status for Case #1? I get `res.status = 4` (message is `The solution does not satisfy the constraints, yet no errors were raised...Otherwise, please enable presolve`. I didn't disable presolve. I added the `disp=True` option to print convergence messages. It says `Optimization terminated successfully.` I manually checked constraints, and they are very close (<0.1 error). Not sure what to make of it. – kcw78 Jan 16 '19 at 20:50
0

There are really some problems in linprog with simplex method. I've found more than 15 cases that are soluble in Matlab but can't be solved by linprog with "method=simplex". It can also be solved by passing "method=interior-point". But the usually the simplex method is more popular. Hope to fix it.

Jan Sršeň
  • 1,024
  • 3
  • 18
  • 37