linprog error message: the dual appears to be infeasible (and the primal unbounded).
Show older comments
Hi I am trying to solve a linear optimization problem using linprog but I get the following errors most of the times (exitflag= -3 or -2).
*Exiting: One or more of the residuals, duality gap, or total relative error has stalled
*Exiting: One or more of the residuals, duality gap, or total relative error has grown 100000 times greater than its minimum value so far
I think the the problem is that some of my constraints are very small numbers compared to others. For example, A and b matrices look something like the following.
A = [1 1 0 0; 0 0 .5 1; 0 1e-8 0 1e-9]
b = [1 0 1e-12]
Moreover, when I get this error, some variables in the output of the optimization problem are negative, while I have a constraint that the variables must be non-negative.
Any idea to solve this issue would be appreciated.
Thanks
1 Comment
Accepted Answer
More Answers (1)
Alan Weiss
on 30 Jun 2015
I cannot reproduce your result. When I entered the following, I got an answer:
A =[
0.5 -1 0 0 0 0
1 -1 0 0 0 0
-1 0 0 0 0 0
1 0 0 0 0 0
0 0 1 -1 0 0
0 0 -1 0 0 0
0 0 1 0 0 0
0 0 0 0 1 -1
0 0 0 0 -1 0
0 0 0 0 1 0
-1.04e-07 0 -7.03e-08 0 -8.17e-08 0
];
b = [ 0 7.94e-06 0 0.1 0 0 0.1 0 0 0.1 -1e-11]';
x = linprog(zeros(6,1),A,b)
Optimization terminated.
x =
0.0945
86.2581
0.0856
75.3455
0.0856
75.3455
This solution indeed satisfies the constraints:
A*x-b
ans =
-86.2108
-86.1636
-0.0945
-0.0055
-75.2599
-0.0856
-0.0144
-75.2599
-0.0856
-0.0144
-0.0000
Alan Weiss
MATLAB mathematical toolbox documentation
9 Comments
Mehdi
on 30 Jun 2015
Alan Weiss
on 30 Jun 2015
Thank you for including the reproduction steps. Indeed, the default interior-point algoririthm has trouble with that case.
Try another algorithm.
options = optimoptions('linprog','Algorithm','dual-simplex');
x = linprog(f,A,b,[],[],[],[],[],options)
Optimal solution found.
x =
0
0
0
0
0
0
A*x-b
ans =
0
-0.0000
0
-0.1000
0
0
-0.1000
0
0
-0.1000
0.0000
Or, if you don't have a recent enough version of the toolbox to have the 'dual-simplex' algorithm, try setting the Algorithm option to 'simplex' to get the same result.
Alan Weiss
MATLAB mathematical toolbox documentation
Mehdi
on 30 Jun 2015
Matt J
on 30 Jun 2015
The above result is not correct because I have the non-negative constraints for the values.
The constraints are still satisfied within the TolCon parameter.
Mehdi
on 1 Jul 2015
Anyway, the point is to remember that you're working on finite precision computers and so exact math cannot be expected of them. You must expect that the constraints may be violated by small amounts due to floating point errors.
In a linear program, in particular, the solution is always at the boundary of the feasible region, so floating point errors can push the solver slightly outside of this boundary.
Torsten
on 2 Jul 2015
If you multiply b by a factor of 1e10, you will also have to multiply A with this big number to get an equivalent problem to the one you started with.
Best wishes
Torsten.
Matt J
on 2 Jul 2015
In addition to what Torsten said, scaling the entire A,b data will not fix the original problem because the relative magnitudes of the last row to the other rows remains the same.
That is why I proposed scaling the final rows only, as in my Comment here,
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!