Linprogr in Matlab not finding a solution when a solution exists

조회 수: 17 (최근 30일)
CT
CT 2019년 8월 14일
편집: Bruno Luong 2024년 3월 26일
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
Bruno Luong
Bruno Luong 2023년 9월 25일
편집: Bruno Luong 2023년 9월 25일
Four year (sept 2023) later where the problem is reported and still the same issue with linprog.
Bruno Luong
Bruno Luong 2024년 3월 26일
편집: Bruno Luong 2024년 3월 26일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2019년 8월 14일
편집: Bruno Luong 2019년 8월 14일
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
CT
CT 2019년 8월 14일
편집: CT 2019년 8월 14일
Thanks. I tried to call gurobi from Matlab (in place of linprogr): gurobi always finds a solution.
Rub Ron
Rub Ron 2023년 10월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Derya
Derya 2019년 8월 15일
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
Derya
Derya 2023년 9월 25일
Thank you very much for providing the problem instance, Simão Pedro.
Kind Regards,
Derya
Bruno Luong
Bruno Luong 2023년 9월 27일
편집: Bruno Luong 2023년 9월 27일
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.

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2023년 9월 26일
편집: Matt J 2023년 9월 26일
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
Bruno Luong
Bruno Luong 2023년 9월 26일
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 2023년 9월 27일
편집: Bruno Luong 2023년 10월 24일
@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;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by