Borrar filtros
Borrar filtros

Linprogr in Matlab not finding a solution when a solution exists

5 visualizaciones (últimos 30 días)
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 comentarios
Bruno Luong
Bruno Luong el 25 de Sept. de 2023
Editada: Bruno Luong el 25 de Sept. de 2023
Four year (sept 2023) later where the problem is reported and still the same issue with linprog.
Bruno Luong
Bruno Luong el 26 de Mzo. de 2024
Editada: Bruno Luong el 26 de Mzo. de 2024
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.

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 14 de Ag. de 2019
Editada: Bruno Luong el 14 de Ag. de 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 comentarios
CT
CT el 14 de Ag. de 2019
Editada: CT el 14 de Ag. de 2019
Thanks. I tried to call gurobi from Matlab (in place of linprogr): gurobi always finds a solution.
Rub Ron
Rub Ron el 24 de Oct. de 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.

Iniciar sesión para comentar.

Más respuestas (2)

Derya
Derya el 15 de Ag. de 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 comentarios
Derya
Derya el 25 de Sept. de 2023
Thank you very much for providing the problem instance, Simão Pedro.
Kind Regards,
Derya
Bruno Luong
Bruno Luong el 27 de Sept. de 2023
Editada: Bruno Luong el 27 de Sept. de 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.

Iniciar sesión para comentar.


Matt J
Matt J el 26 de Sept. de 2023
Editada: Matt J el 26 de Sept. de 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 comentarios
Bruno Luong
Bruno Luong el 26 de Sept. de 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 el 27 de Sept. de 2023
Editada: Bruno Luong el 24 de Oct. de 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;

Iniciar sesión para comentar.

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by