Linprog gives a solution but one constraint is not satisfied (no notification)

5 views (last 30 days)
JT
JT on 16 Dec 2021
Commented: JT on 19 Dec 2021
Hi!
I am trying to solve a linear programming problem with LinProg where I try to maximize x1 and (in another application) maximize the sum of a vector, subject to some constraints. Now my problem is that the software provides a solution but when I check this with the constraint, in both applications the first constraint is not satisfied. I checked that I didn't write any negatives when there should be a positive or the other way around but the constraint seems fine. It has the same structure as the others and comes from the same data set so there should be no problem here.
Does anyone know what could be the problem here?
Thank you in advance!!!

Accepted Answer

Torsten
Torsten on 16 Dec 2021
I get
x3(1) = 387,2108
x3(3) = 7,5211
x3(9) = 4,8920
x3(10) = 0.3761
and x3(i) = 0 for all other components.
And this vector is feasible as you can see when you print out
constraints3*x3-b3
eq'*x3-400

More Answers (2)

John D'Errico
John D'Errico on 16 Dec 2021
Edited: John D'Errico on 16 Dec 2021
Not possible to know, since you don't actually show us the code you wrote. You may have done something wrong.
Or it may just be your understanding of what it means to satisfy a constraint, in terms of floating point arithmetic and the constraint tolerance. That is, is the constraint satisfied WITHIN the constraint tolerance?
Beyond that, my crystal ball tells me only that you may soon come into a large sum of money. Or maybe it is telling me that your relatives may soon inherit a large sum of money from you. It is very unclear. These darned crystal balls. ;-)
Seriously, if you want a better answer, you need to show code we can look at and verify to know where you are going wrong.
  6 Comments
Torsten
Torsten on 16 Dec 2021
Your zmatrix has only 23 elements in it, instead of 31.
W3' is 23x31, x3 is 31x1, b3' is 23x1.

Sign in to comment.


Matt J
Matt J on 16 Dec 2021
Edited: Matt J on 16 Dec 2021
load data
defaultOptions=optimoptions('linprog');
[x3,fval,exitflag,output] = linprog(f3,constraints3,b3,eq',400,lb3,[], defaultOptions);
Optimal solution found.
The constraint violation is quite small, certainly smaller than the default tolerance, although I don't know if that's supposed to be an absolute or relative tolerance.
output.constrviolation
ans = 2.9802e-08
defaultOptions.ConstraintTolerance
ans = 1.0000e-04
It is also insignificant compared to the typical magnitudes of your constraints:
min(b3-constraints3*x3)
ans = -2.9802e-08
median(b3-constraints3*x3)
ans = 1.5049e+08

Community Treasure Hunt

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

Start Hunting!

Translated by