Linprogr in Matlab not finding a solution when a solution exists

21 views (last 30 days)
I am solving a linear programming in Matlab using linprogr. All the matrices are attached.
clear
rng default
load matrices
f=zeros(size(x,1),1);
possible_solution = linprog(f,Aineq,bineq,Aeq,beq, lb, ub);
The output is
No feasible solution found.
Linprog stopped because no point satisfies the constraints.
From some theory behind the problem, I know that the vector x (uploaded together with the other matrices) should be a solution of linprog(f,Aineq,bineq,Aeq,beq, lb, ub).
In fact, x seems to satisfy all the constraints, except the equality constraints. However, regarding the equality constraints, the maximum absolute difference between Aeq*x and beq is around 3*10^(-15). Hence, also the equality constraints are almost satisfied by x.
load x
check_lb=sum(x>=0)==size(x,1);
check_ub=sum(x<=1)==size(x,1);
check_ineq=(sum(Aineq*x<=bineq)==size(Aineq,1));
check_eq=max(abs((Aeq*x-beq)));
Therefore, my question is: why linprog(f,Aineq,bineq,Aeq,beq, lb, ub) does not find x as solution? It does not seem to be a problem of the equality constraints, because if I remove the inequality constraints and run
rng default
possible_solution_no_inequalities = linprog(f,[],[],Aeq,beq, lb, ub);
the program finds a solution. Is it a matter of numerical precision? How can I control for that?
  2 Comments
Bruno Luong
Bruno Luong on 25 Sep 2023
Edited: Bruno Luong on 25 Sep 2023
Four year (sept 2023) later where the problem is reported and still the same issue with linprog.
Bruno Luong
Bruno Luong on 26 Mar 2024 at 17:10
Edited: Bruno Luong on 26 Mar 2024 at 17:16
UPDATE R2024A has a new default algorithm 'dual-simplex-highs' and this issue seems to be somewhat resolve
load matrices
f=zeros(size(x,1),1);
possible_solution = linprog(f,Aineq,bineq,Aeq,beq, lb, ub);
Optimal solution found.
Sill fail on @Simão Pedro da Graça Oliveira Marto example below.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 14 Aug 2019
Edited: Bruno Luong on 14 Aug 2019
It looks to me LINPROG is flawed or buggy in your case. I try to remove suspected constraints and change beq so that the equality is satisfied by x, and LINPROG still fails.
load matrices
f=zeros(size(x,1),1);
Aeq = round(Aeq);
beq = Aeq*x;
keep = max(abs(Aineq),[],2)>1e-10;
all(x>=lb)
ans = logical
1
all(x<=ub)
ans = logical
1
all(Aineq*x<=bineq)
ans = logical
1
all(Aeq*x==beq)
ans = logical
1
% This will fail to return solution
options = optimoptions('linprog','Algorithm','interior-point','ConstraintTolerance',1e-3);
xlinprog = linprog(f,Aineq(keep,:),bineq(keep,:),Aeq,beq, lb, ub, options);
The problem is infeasible. Linprog stopped because no point satisfies the constraints.
But if I call QUADPROG it will returns a solution
% This will returns a solution
H = sparse(size(x,1),size(x,1));
xquadprog = quadprog(H,f,Aineq(keep,:),bineq(keep,:),Aeq,beq, lb, ub);
Warning: Quadratic matrix (H) is empty or all zero. Your problem is linear. Consider calling LINPROG instead.
Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
  2 Comments
CT
CT on 14 Aug 2019
Edited: CT on 14 Aug 2019
Thanks. I tried to call gurobi from Matlab (in place of linprogr): gurobi always finds a solution.
Rub Ron
Rub Ron on 24 Oct 2023
I am very much dissapointed and upset by linprog and Matlab. I had spend a lot of time dealling with errors in my algorithm. I was putting the blame in some flaw in my algorithm and precomputation of variables, but at the end the issue was with linprog. I switched now to gurobi and my algorithm does perform as expected. It was a huge waste of time and effort, and the documentation on linprog is poor, it does not even flag cases with "challlenging" data.

Sign in to comment.

More Answers (2)

Derya
Derya on 15 Aug 2019
Hello CT,
linprog with 'Preprocess' option set to 'none' will give you a solution. Then, by decreasing the 'ConstraintTolerance' you may get a solution with better feasibility measures. Since the problem is numerically challenging(*) you may need to examine any solution found (by any solver) carefully.
Thank you very much for providing the example. Using it, we'll try to improve linprog so that it can solve these type of problems with its default settings.
Kind Regards,
Derya
(*)
1. there are very small coefficient in matrices which are below some of the tolerances used in our numerical algorithms.
2. the ratio between the largest and smallest absolute values of coefficients in the constraint matrices is large.
  3 Comments
Derya
Derya on 25 Sep 2023
Thank you very much for providing the problem instance, Simão Pedro.
Kind Regards,
Derya
Bruno Luong
Bruno Luong on 27 Sep 2023
Edited: Bruno Luong on 27 Sep 2023
The issue of problem submited by Semao seems to be different than CT. If we set
options = optimoptions('linprog','Algorithm','interior-point')
In Simao problem linprog will find solution. This is not the case with CT's problem.
quadprog works for both problems.

Sign in to comment.


Matt J
Matt J on 26 Sep 2023
Edited: Matt J on 26 Sep 2023
The problem seems to be that the inequality constrained region has barely any intersection with the equality constrained region. This means that the feasible set, if it exists, is very small, making the solution very unstable numerically, as well as difficult for linprog to find.
As evidence of this, the code below shows that by enlarging the inequality constrained region very slightly to Aineq*x<=bineq+1e-10, a solution is found. Note that this is after a pre-normalization of the rows of the constraint matrices.
load('matrices.mat')
[Aineq,bineq]=normalizeConstraints(Aineq,bineq,'<=');
[Aeq,beq]=normalizeConstraints(Aeq,beq,'==');
opts=optimoptions('linprog','ConstraintTol',1e-9);
f=zeros(size(x,1),1);
xp = linprog(f,Aineq,bineq+1e-10,Aeq,beq, lb, ub,opts);
Optimal solution found.
function [A,b]=normalizeConstraints(A,b,op)
idx=~any(A,2); %find rows with all zeros
switch op
case '=='
assert( all(b(idx)==0) , 'Trivially infeasible')
case '<='
assert( all(b(idx)>=0) , 'Trivially infeasible')
end
A(idx,:)=[]; %discard rows with all zeros
b(idx)=[];
s=vecnorm(A,2,2);
A=A./s; %normalize rows of A to unit l2-norm
b=b./s;
end
  11 Comments
Bruno Luong
Bruno Luong on 26 Sep 2023
Interesting. I have to think about it more tomorrow. Now it is too late and I'm lazy to dig into your code.
Bruno Luong
Bruno Luong on 27 Sep 2023
Edited: Bruno Luong on 24 Oct 2023
@Matt J The last code with shifted solution by x wrong since you forgot to change accordingly lb and ub. IMO the correct command is
xnew = linprog(f,Aineq,bineq-Aineq*x,Aeq,beq-Aeq*x, lb-x, ub-x,opts)+x;

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!