lin prog optimization with recourse function.
Show older comments
Hi community, I have a problem with constructing the right code. Where I first want to minimize a code using linprog to find values for Y & Z and thereafter want to use these obtained values of Z & Y to find an optimal value for X.
%first stage making expectation of second stage to determine x
%Min c.'*x+E[Q(x,D)]
i=1;
j=1;
c = 3;
l = 0.25;
q = 11;
s = 2;
A1 = 1;
D= 100;
x1=110
f2 = [-s.',(l-q).']; %[ Y, Z]
E=sum(f2) %value for expected optimum solution Q(x,D)
Aeq = [eye(j),A1.'];
beq = x1;
lb = [zeros(1,i+j)]; %requires 4 bounds as there are 4 variables --> for versatility lb=[zeros(1,v) v= number of variables in V
ub = [inf(1,j),D];
sol = linprog(f2,[],[],Aeq,beq,lb,ub);
y = sol(1)
z = sol(2)
%V=[V1 V2 V3]= [X Y Z]
f1= [c.',-s.',(l-q).'];
Aeq = [0,eye(j), A1.'];
beq = [x];
lb = [0,0,0];%x>0
ub = [Inf,inf,D]; ?
sol = linprog(f1,[],[],Aeq,beq,lb,ub)
x = sol(1)
from the second linprog I only want a solution for the value of X, since the values of Z & Y should be the same as obtained from the f2 Linprog function. I do not now How to fix that the second linprog f1 uses the values obtained from optimization f2. As now As result of optimization f1 I get X=Y=Z=0. which is not satisfactory. Does anyone have an idea how I can fix this?
Thankyou!
20 Comments
Torsten
on 2 May 2019
What is x in "beq = [x]" ?
Why do you solve for Y and Z in the second linprog if you want to retain the values of the first linprog ?
bus14
on 2 May 2019
As I already answered in another thread of yours, the constant term -s.'*y+(l-q).'*z doesn't matter in f1. Thus f1 is simply [c.'].
Thus your second optimization reads
f1 = [c.'];
Aeq = 1;
beq = y + A1.'*z;
lb = 0;
ub = Inf;
sol = linprog(f1,[],[],Aeq,beq,lb,ub)
x = sol(1)
bus14
on 2 May 2019
Torsten
on 2 May 2019
What does it mean that a feasible x* is optimal ?
It means that
c.'x* <= c.'x
for all feasible vectors x.
Now adding the constant value -s.'y+(l-q).'z at both sides of this inequality gives
c.'x* -s.'y+(l-q).'z <= c.'x -s.'y+(l-q).'z
for all feasible vectors x.
Thus the same x* is also optimal for the problem
min: c.'x -s.'y+(l-q).'z
This means that adding a constant to the objective function doesn't change the optimal x (and thus does not need to be taken into account).
bus14
on 2 May 2019
bus14
on 6 May 2019
Torsten
on 7 May 2019
If Aeq = 1 and beq = y+A1.*z, your solution variable x satisfies
Aeq*x = x = y+A1.*z = beq
I think this is what you want.
bus14
on 8 May 2019
Torsten
on 8 May 2019
Linprog can't be set in a loop if x is connected to all of the 200 Y(k) and Z(k) solution variables. It must be solved as one big problem.
Define the solution vector of this big problem as
V = [x Y(1) Y(2) ... Y(200) Z(1) Z(2) ... Z(200)]
Then V has 401 solution variables.
All Aeq, beq, lb, ub and c settings follow automatically from this setting of the solution vector.
Think about it.
bus14
on 8 May 2019
bus14
on 8 May 2019
Torsten
on 8 May 2019
I did not write pk(k), but Pk which is
Pk = [pk(1);pk(2);pk(3);...;pk(200)]
Answers (0)
Categories
Find more on Solver Outputs and Iterative Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!