Reputation: 31
Please help me to find out where is the mistake of the following code. I've seen that there is a thread with a similar problem, but the solution provided there does not solve my problem, unfortunately.
code:
A_ub=[[0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, -1], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, -1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1]]
b_ub=[0, 0, 0, 0]
A_eq=[[0, -0.7092198581560284, 0.7092198581560284, 0, 0, 0, 0, 0, 0, 0, 0], [-1, -0.7092198581560284, -0.7092198581560284, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0.7092198581560284, 0, 1, 0, 1, 1, 0, 0, 0, 0], [0, 0.7092198581560284, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, -0.7092198581560284, 0, -1, -1, 0, 0, 1, 0, 0], [0, 0, 0.7092198581560284, 0, 0, 0, 0, 0, 0, 1, 0]]
b_eq=[0, 1, 0, 1, 0, 0, 0, 0]
c=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
res = linprog(c, A_ub, b_ub,A_eq, b_eq)
print res
I obtain the following error:
fun: 2.0
message: 'Optimization failed. Unable to find a feasible starting point.'
nit: 5
status: 2
success: False
x: nan
Upvotes: 1
Views: 2457
Reputation: 1576
Your solution space is empty, no feasible point exists. Check your second equality constraint for instance:
[-1, -0.7092198581560284, -0.7092198581560284, 0, 0, 0, 0, 0, 0, 0, 0]
multiplied by the vector of decision variables shall equal 1.
Decision variables are assumed to be non negative by default and since no positive coefficient for that constraint exists it is easy to see one example why the model is infeasible. So -1 * x1 -0.7092198581560284 * x2 -0.7092198581560284 * x3 = 1 has no feasible solution if all x have to be greater or equal to 0.
The bounds on x will not solve your problem though. Even if x is real, the solution space is empty. My guess is that the equality constraints, which limit the solution space strongly, are contradictional. Depending on what you are trying to model, you will have to look at the entire program to be sure where the problem lies though.
Upvotes: 1