現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)