Linprogr in Matlab not finding a solution when a solution exists

24 Ansichten (letzte 30 Tage)
CT
CT am 14 Aug. 2019
Bearbeitet: Bruno Luong am 26 Mär. 2024 um 17:16
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 Kommentare
Bruno Luong
Bruno Luong am 25 Sep. 2023
Bearbeitet: Bruno Luong am 25 Sep. 2023
Four year (sept 2023) later where the problem is reported and still the same issue with linprog.
Bruno Luong
Bruno Luong am 26 Mär. 2024 um 17:10
Bearbeitet: Bruno Luong am 26 Mär. 2024 um 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 14 Aug. 2019
Bearbeitet: Bruno Luong am 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 Kommentare
CT
CT am 14 Aug. 2019
Bearbeitet: CT am 14 Aug. 2019
Thanks. I tried to call gurobi from Matlab (in place of linprogr): gurobi always finds a solution.
Rub Ron
Rub Ron am 24 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Derya
Derya am 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 Kommentare
Derya
Derya am 25 Sep. 2023
Thank you very much for providing the problem instance, Simão Pedro.
Kind Regards,
Derya
Bruno Luong
Bruno Luong am 27 Sep. 2023
Bearbeitet: Bruno Luong am 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.

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 26 Sep. 2023
Bearbeitet: Matt J am 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 Kommentare
Bruno Luong
Bruno Luong am 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 am 27 Sep. 2023
Bearbeitet: Bruno Luong am 24 Okt. 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;

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by