linprog not giving all possible solutions
Show older comments
I have the following issue with linear programming specific to biological data.
The specific method requires the maximization and minimization of all values subject to one specific value.
for example I have 5 variables v,w,x,y,z, I need to maximize v, and when this is performed what are the values of w,x,y,z. This is then repeated where w is maximized and the optimal values of v,x,y and z are required.
I have been using the linprog function to determine the value, the following constraints and equalities are set:
v + w + x + y = 100
v + y <= 60
w + x <= 40
x + z <= 30
v + x <= 70
w + y <= 30
y + z <= 20
v,w,x,y,z >= 0
v,w,x,y,z <=100
I'm assuming my problem is the setup of the objective function, currently what I have been trying with moderate success is to set the objective function specific to the value that needs to be optimized eg. 1v + 0w + 0x + 0y + 0z
my code is as follows:
f = [1;0;0;0;0]
A = [1 0 0 1 0; 0 1 1 0 0; 0 0 1 0 1; 1 0 1 0 0; 0 1 0 1 0; 0 0 0 1 1]
b = [60;40;30;70;30;20]
Aeq = [1 1 1 1 0]
beq = 100
lb =[0;0;0;0;0]
ub = [100;100;100;100;100]
When I perform the linprog I get the following values for when v is minimized:
>> x = linprog(f,A,b,Aeq,beq,lb,ub)
Optimal solution found.
x =
40
10
30
20
0
which according to my notes is correct, however when I maximize v:
>> x = linprog(-f,A,b,Aeq,beq,lb,ub)
Optimal solution found.
x =
60
30
10
0
0
where the expected solution should have been:
x =
60
30
10
0
20
This pattern repeats with every variable where either all the values are correct or the last value is incorect (usually displaying zero when it is not). Is this an issue as to how I approaced the objective function? Is there a better way to solve these types of issues? Any assistance would be greatly appreciated.
Accepted Answer
More Answers (1)
green_ananas
on 16 Feb 2021
0 votes
Hey,
Maybe you didn't copy the equations correctly. The way you stated it, z doesn't appear in the top equation. Therefore, as long as all constraints are met and x is maximum, the value of z doesn't matter and you just obtain one of all local solutions as expected.
3 Comments
Wynand van Losenoord
on 16 Feb 2021
green_ananas
on 16 Feb 2021
Exactly, and as you can see, every value of
is compatible with your constraints. If you wanted to obtain the maximum z of all solutions, you would need to reformulate your objective function which you are minimizing. The way it is formulated now, linprog only looks for the maximum value of v, and doesn't care about the other values as long as they don't violate the constraints.
is compatible with your constraints. If you wanted to obtain the maximum z of all solutions, you would need to reformulate your objective function which you are minimizing. The way it is formulated now, linprog only looks for the maximum value of v, and doesn't care about the other values as long as they don't violate the constraints.
Wynand van Losenoord
on 16 Feb 2021
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!