Reputation: 7100
I am getting quite confused with how the equality constraint in the method works. What am I doing wrong here? I would expect dot(A_eq, x) to be equal to b_eq. I thought that was the definition of the equality constraint. However, np.dot(A_eq, res.x) gives me [0, -6] while b_eq is clearly given as [0,0]. Am I crazy, or is this a bug?
(EDIT: the constraints are actually from a misspecfication of the model. Once I correct the model, it's actually working fine. Nonetheless, given this misspecified model, I would still expect the equality constraint to hold, or in the worst case, the linprog procedure should fail instead of succeeding but giving an answer that does not fit the constraints)
import numpy as np
from scipy.optimize import linprog
c=[-0.098782540360068297, -0.072316526358138802, 0.004, 0.004, 0.004, 0.004]
A_ub=[[1.0, 0, 0, 0, 0, 0], [-1.0, 0, 0, 0, 0, 0], [0, -1.0, 0, 0, 0, 0], [0, 1.0, 0, 0, 0, 0], [1.0, 1.0, 0, 0, 0, 0]]
b_ub=[3.0, 3.0, 3.0, 3.0, 20.0]
A_eq=[[1.0, 0, -1, 1, -1, 1], [0, -1.0, -1, 1, -1, 1]]
b_eq=[0,0]
res=linprog(c, A_ub, b_ub, A_eq, b_eq)
np.dot(A_eq, res.x)
Upvotes: 2
Views: 1033