how to include a loop and stopping criteria in fmincon

2 ビュー (過去 30 日間)
Rose WABUTI
Rose WABUTI 2018 年 10 月 24 日
編集済み: Torsten 2018 年 10 月 24 日
I am using fmincon to slove a two stage optimization - the stackelberg leader follower type, by backward induction. The code below works but its too manual, the value of x calculated in the first stage is taken as the limit in the next stage and vise versa, I need to refine the code to include a stopping criteria such that when fval is non changing from the previous value and to not manually keeb changing the variable x as seen in the code I have changed the variable from b,c, z,d,. I need to include a loop but I don't know how, any idea?
fun =@(b)(-1)*( b(2)*( a - 2*(b(1) + b(2)) - (5 - b(2) + b(2)^2)) );
x0 = [0,1];
A = [];
B = [];
Aeq= [];
beq= [];
lb=[0,0];
ub=[1,1];
[b,fval(1)] = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
% leader observing followers responce choses the val
% fun =@(c)(-1)*( c(1)*( a - 2*(c(1) + c(2)) - (4 - c(1))) );
fun =@(c)(-1)*( c(1)*( a - 2*(c(1) + c(2)) - (4 - c(1) + c(1)^2)) );
lb=[0,b(2)];
ub=[1,b(2)];
[c,fval(2)] = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
%follower choses value in reaction to leaders
fun=@(z)(z(2)*( a - 2*(z(1) + z(2)) - (5 - z(2) + z(2)^2))*(-1));
x0 = [0,1];
A = [];
B = [];
Aeq= [];
beq= [];
lb=[c(1),0];
ub=[c(1),1];
[z,fval(3)] = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
%leader chooses value in reaction
% fun =@(d)(-1)*( d(1)*( a - 2*(d(1) + d(2)) - (4 - d(1))));
fun =@(d)(-1)*( d(1)*( a - 2*(d(1) + d(2)) - (4 - d(1) + d(1)^2)) );
lb=[0,z(2)];
ub=[1,z(2)];
[d,fval(4)] = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
% follower chooses value
fun=@(e)(e(2)*( a - 2*(e(1) + e(2)) - (5 - e(2) + e(2)^2))*(-1));
x0 = [0,1];
A = [];
B = [];
Aeq= [];
beq= [];
lb=[d(1),0];
ub=[d(1),1];
[e,fval(5)] = fmincon(fun,x0,[],[],Aeq,beq,lb,ub);

回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by