이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
lin prog optimization with recourse function.
조회 수: 1 (최근 30일)
이전 댓글 표시
bus14
2019년 5월 2일
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
Torsten
2019년 5월 2일
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
2019년 5월 2일
x will be for this instance a number, beq=[x] is the same x as in the objective function and needs to be find by optimizing the objective function.
Min c.'*x-s.'*y+(l-q).'*z
s.t. x=y+A1.'*z
where
x>0, y>0, 0<z<D
Why do you solve for Y and Z in the second linprog if you want to retain the values of the first linprog ?
Because I do not know how to put it into linprog when I do not want to optimze Z and Y in the new situation but only want to optimize X using the already found Z & Y of the first linprog.
should f1 in the case of only optimizing x be:
f1= [c.'-s.'*y+(l-q).'*z];
or would X then be multiplied by all three parts of the function [c.',s.',(l-q).']?
Hope you can help me out
Torsten
2019년 5월 2일
편집: Torsten
2019년 5월 2일
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
2019년 5월 2일
Thankyou, I understand that f1 should only have [c.'] as x is optimized. However, what I do not understand is how the optimization than takes into account the rest of the objective function in the optimization?
As it is: Min c.'*x-s.'*y+(l-q).'*z.
because when setting f1=[c.'] linprog will only take into account minimizing c.'*x am I right? and does nothing with the remaining value of -s.'*y+(l-q).'*z. Is it because the second part is merely a numerical value so it cannot be optimized further or do I misunderstand the working of the f[] in linprog?
Sorry to bother you with my many questions
Torsten
2019년 5월 2일
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
2019년 5월 6일
Torsten, in improving the code and trying it with different parameters I encoutered a struggle. In finding this x value, as to optimize the unkown x value which is in the objective function as well as in the constraint. Matlab returns an error saying that x variable is undefined. However, x is the variable that I want to find using linprog(which is the reason that no value is assigned to it yet).
f1 = [c.'];
Aeq = y+A1.'*z;
beq = x;
lb = 0;
ub = Inf;
sol = linprog(f1,[],[],Aeq,beq,lb,ub)
x = sol(1)
In your answer to this question you stated that Aeq=1 and beq=y+A1.'*z but 1 does not represent the value of x.
Or am I misunderstanding it and did you use 1 because AeqX=beq and X=x ??
The value of x should satisfy the constrained and also Min the objective funtion of Min c'*x.
Really hope you can answer this question!
Torsten
2019년 5월 7일
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
2019년 5월 8일
yes this was indeed what I was looiking for
Another question, Is it possible to have some sort of summation in the objective function in linprog? Or a loop
As i want to find y(k) and z(k) for multiple instances and use this to find the optimal value for x.
would look like:
Min c'*x+Sigma(pk(k)*((l-q).'*z(k)-s.'*y(k))
s.t y(k)-x+A1.'*z*(k)=0
y(k)>0, x>0 0<z(k)<k for k=1:1:200
or Is this not possible? As linprog only optimizes regarding Y and Z and not for Y(k) and Z(k)?
bus14
2019년 5월 8일
편집: bus14
2019년 5월 8일
And saying that X returns just 1 value instead of 200 is not possible? As X should have the same value for every of the 200 instances
f2 = [c',pk(k)*-s.',pk(k)*(l-q).'];
Aeq = [-1,1,A1.']; %[x y z]
beq = [0];
lb = [0,0,0];
ub = [inf,inf,k];
sol = linprog(f2,[],[],Aeq,beq,lb,ub);
x= sol(1); % or x(k)=sol(1);
y(k) = sol(2);
z(k) = sol(3);
This is what I used, returns 0 for all vectors
bus14
2019년 5월 8일
편집: bus14
2019년 5월 8일
Yes indeed. First I tried this in the case of only Min c*x
then I used Aeq=1
beq= Y(k)+A1'*Z(k)
However having three variables, I do not know how to put this in the Aeq matrix in a way that it satifies x=y(k)+A1.'*z(k)
p.s the whole linprog is in a for loop for k=1:1:200 so that it runs from itself. My only problem is defining the Aeq and beq to fix this.
tried to use Aeq=[1,0,0] beq=[y(k)+A1.'*z(k)] but y and z are then undefined
Torsten
2019년 5월 8일
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
2019년 5월 8일
This would mean that Aeq becomes 1 huge matrix and beq can stil be set to 0, am I right
bus14
2019년 5월 8일
편집: bus14
2019년 5월 8일
Was in a bit of a hurry...
What I meant was:
Aeq=[-ones(200,1),eye(200),eye(200)];
beq = [zeros(200,1)];
Now new problems rise as the number of columns of Aeq must be the same as the number elements in f
f2 = [c';pk(k)*-s.';pk(k)*(l-q).']
However, without running the for loop. This ofcourse has only 3 elements. Is there a trick I can use to repeat this for the objective function f2 to put all 200 situation in them instead of just typing it out?
because there are indeed 200 instances of y(k) and 200 instances of z(k) do not know how to put this into f2.
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)