How to write constraints for a linear programming problem shown below? [Unable to write constraints even after referring to matlab help guides]
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all, I am new to optimization. I have a linear objective function that I'd like to minimize. It goes as such:
Min O.F= 1/3(−9x1 + 4y1) + 1/3(−9x2 + 4y2) + 1/3(−9x3 + 4y3)
Constraints:
- 0 ≤ ED ≤ 150,
- 100 − ED = x1 + y1
- 125 - ED = x2 + y2
- 150 - ED = x3 + y3
- x1, x2, x3 ≤ 0
- y1, y2, y3 >= 0
I tried the code shown below after referring to some optimization guides, but I am constantly getting errors.
e=[100;125;150];
p=[1/3;1/3;1/3];
x=zeros(3,1);
y=zeros(3,1);
variables={'eD','x','y'};
N = length(variables);
lb = zeros(size(variables));
lb([y(1),y(2),y(3)]) = [0,0,0];
ub = Inf(size(variables));
ub([x(1),x(2),x(3)]) = [0,0,0];
Aeq=zeros(3,4);
Aeq(1,[eD,x(1),y(1)]) = [1,1,1];
Aeq(2,[eD,x(2),y(2)]) = [1,1,1];
Aeq(3,[eD,x(3),y(3)]) = [1,1,1];
beq=[100;125;150];
f = zeros(size(variables));
f([x(1) y(1) x(2) y(2) x(3) y(3)]) = [p(1)*-9 p(1)*4 p(2)*-9 p(2)*4 p(3)*-9 p(3)*4];
[x,fval] = linprog(f,Aeq,beq,lb,ub);
Any help would be appreciated
0 commentaires
Réponses (1)
Alan Weiss
le 2 Mar 2015
You would do yourself a favor to read an introductory example about linear programming in MATLAB. The main idea is that the control variables, meaning the variables that linprog moves around to try to find the optimum, are the ones that you need to have in a single variable, which is usually called x. For example, you could have
x = [x1,x2,x3,y1,y2,y3,ED]
Then it is easy to write all your conditions in terms of the one variable x. This is 7 dimensions, so each row of your A or Aeq matrices has to have 7 components.
Please look at the example for details.
Alan Weiss
MATLAB mathematical toolbox documentation
2 commentaires
Alan Weiss
le 3 Mar 2015
I think that you gave bounds incorrectly.
x1, x2, x3 ≤ 0
y1, y2, y3 >= 0
To me, this means that the lower bounds on the x1, x2, and x3 variables are -Inf, and the upper bounds on them are 0.
Alan Weiss
MATLAB mathematical toolbox documentation
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!