How can I write an objective function with its constrain for optimization?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
The problem formulation for which I need optimization is as follow:
D- BUYER AGENT
S-SELLER AGENT
p-price
pj – price per unit
aj- amount of energy available
gj- total generation energy
ui- buyer utilities
vj- seller utilities
bi - bid of each buyer
maximize w.r.t 𝑑𝑖, 𝑠𝑗,
𝛩(𝑑𝑖, 𝑠𝑗)=Σ𝑢 𝑖(𝑑𝑖) +Σ𝑣𝑗(𝑔𝑗 − 𝑠𝑗)
𝑖∈𝒟 𝑗∈𝒮
subject to,
𝑑𝑖 ≤ 𝑏𝑖; ∀𝑖 ∈ 𝒟
𝑠𝑗 ≤ 𝑎𝑗; ∀𝑗 ∈ 𝒮
Σ𝑑𝑖 =Σ𝑠𝑗
𝑖∈𝒟 𝑗∈𝒮
Auction happens in iterative manner
採用された回答
- Put your unknowns in a vector x.
- Write your function to be maximized as f*x where f is to be determined from your above problem formulation.
- Write your inequality constraints as A*x <= b where A and b are to be determined by your above problem formulation.
- Write your equality constraint as Aeq*x = beq where Aeq and beq is to be determined by your above problem formulation.
- Determine lower and upper bounds on your unknowns and put them in the arrays lb and ub.
- Call linprog.
11 件のコメント
Thanks for your response @Torsten, but as I'm new to MATLAB, can you please elaborate how to put unkowns in vectorx, and further steps also.
Thanks in advance
So let's try linprog for your problem:
Start with the vector of unknowns. These are d1,...,dD,s1,...,sS.
Since you want to maximize theta, you want to minimize -theta.
So your vector f that has to be passed to linprog is
f = [-u,v]
where u and v are vectors of length D and S, respectively (buyer and seller utilities).
Now your first and second constraints are bound constraints that have to be defined with the help of lb and ub:
lb = [zeros(size(u)),zeros(size(v))]
ub = [b,a];
a = amount of energy available, b = bid of each buyer.
The third constraint has to be put in Aeq and beq:
Aeq = [ones(size(u)),-ones(size(v))];
beq = 0;
Now you can call linprog:
sol = linprog(f,[],[],Aeq,beq,lb,ub)
That's all.
Of course, you must give values to the vectors a, b, u and v first.
u = randperm(5,1);
v = randperm(4,1);
a = randperm(50,1);
b = randperm (30,1);
and do I not need to mention g and s
You want u,v,a,b to have one single element ?
I want them to have a range of values
rng('default')
u = rand(1,6);
b = rand(1,6);
v = rand(1,9);
a = rand(1,9);
f = [-u,v];
lb = [zeros(size(u)),zeros(size(v))];
ub = [b,a];
Aeq = [ones(size(u)),-ones(size(v))];
beq = 0;
sol = linprog(f,[],[],Aeq,beq,lb,ub)
Optimal solution found.
sol = 15×1
0.2785
0.5469
0
0.9649
0.1576
0
0
0.5114
0
0.6787
Thank you @Torsten, I wanted to ask you one more thing, I'm working on NSGA II and I've two function and defined functions like below, is it correct or I need to do as you described earlier:
function z = MOP41(x)
u = randperm(5,1); % buyer utility
d = randperm(10,1); %amount of energy delevered to each buyer
c = randperm(4,1); % seller utility
s = randperm(15,1); % amount of energy each seller can deliver
g = randperm(30,1); % total energy generated
a = randperm(50,1);
b = randperm (30,1);
s1 = 0;
s2 = u*d;
s3 = 0;
s4 = c*(g-s);
n= 7;
for i=1:n
s1= s1+ s2;
end
for i= 1:n
s3 = s3+s4;
end
d<=b;
s<= a;
% Edit the lines below with your calculations.
benergy=randperm(50,1);
bhighest= randperm(40,1);
d=randperm(30,1);
t=5;
g=randperm(20,1);
T = 7;
K= 100;
I= 50;
for i=1:K
d=d;
end
for i= 1:I
g=g;
end
g<d;
for i= 1:T
x = d-g;
end
y= x*t*benergy;
y<= pi;
bhighest < benergy;
% Edit the lines below with your calculations.
%objective = b* log(d) - z;
% objective = max (objective);
%F(1) = s1 + s3;
%F(2) = x*t*benergy;
%x = optimInput(1);
%y = optimInput(2);
%end
z1 = s1 + s3;
z2 = x*t*benergy;
z = [z1 z2]';
end
I gave you the code to solve the optimization problem you posted.
I'm completely lost what you try to do with the function from above since it is full of errors and settings I do not understand.
I suggest you first try to improve your MATLAB skills here
and then work through some examples for "linprog" included here
Thanks for the help with the code, I'm sorry I was trying other objective function and by mistake posted that, but the code you gave did not mentioned 'g' and 's' in the function. you only mentioned funtion of u and v, so I wanted to ask will it effect anyway on the performance
Also can you tell me is the below written code correct for the two objective function as mentioned below:
ist objective
min(g,d,benergy): Σ(Σ𝑑 - Σ𝑔) *t * benergy
subject to:
g<d, bhighest<benergy, Σ(Σ𝑑𝑖 - Σ𝑔𝑗) *t * benergy <= pi
and 2nd objective
max(g,d,benergy): Σ(Σg - Σd) *t * benergy - Σcczrbon
subject to:
d<g, bhighest<benergy, 0<ccarbon<=pi
code for both objective function:
function z = MOP41(x)
benergy1 = randperm(50,1);
bhighest1 = randperm(40,1);
d1 = randperm (30,1);
g1 = randperm(20,1);
t1 = 5;
ccarbon = randperm(30,1);
Tseller = 7;
K1 = 100;
I1 = 50;
for i = 1:I1
g1=g1;
end
for i = 1:K1
d1 =d1;
end
for i=1:Tseller
u = g1-d1;
end
v= u*t1*bhighest1 + ccarbon;
d1 < g1;
bhighest1<benergy1;
0<ccarbon<pi;
% Edit the lines below with your calculations.
benergy=randperm(50,1);
bhighest= randperm(40,1);
d=randperm(30,1);
t=5;
g=randperm(20,1);
T = 7;
K= 100;
I= 50;
for i=1:K
d=d;
end
for i= 1:I
g=g;
end
g<d;
for i= 1:T
x = d-g;
end
y= x*t*benergy;
y<= pi;
bhighest < benergy;
z1 = (u*t1*bhighest1 + ccarbon);
z2 = x*t*benergy;
z = [z1 z2]';
end
d = sol(1:numel(u))
and
s = sol(numel(u)+1:end)
They have to be put in one common solution vector "sol" for linprog to work.
sum(v.*g) is constant and does not need to appear in the objective function.
rng('default')
u = rand(1,6);
b = rand(1,6);
v = rand(1,9);
a = rand(1,9);
f = [-u,v];
lb = [zeros(size(u)),zeros(size(v))];
ub = [b,a];
Aeq = [ones(size(u)),-ones(size(v))];
beq = 0;
sol = linprog(f,[],[],Aeq,beq,lb,ub);
Optimal solution found.
d = sol(1:numel(u))
d = 6×1
0.2785
0.5469
0
0.9649
0.1576
0
s = sol(numel(u)+1:end)
s = 9×1
0
0.5114
0
0.6787
0.7577
0
0
0
0
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Systems of Nonlinear Equations についてさらに検索
参考
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)
