
Write constraints in MATLAB
1 回表示 (過去 30 日間)
古いコメントを表示
Hello friends, have a good time I have one limitation: ∑∑𝑃𝐴 (𝑎𝑎, 𝑏𝑏, 𝑚)< 𝑝𝑛 (𝑎𝑎) I wrote it as follows, but since the dimensions of the matrices are different, it does not work, how can I write it?
const1=zeros(aa,1);
for aa=1:AA
for bb=1:BB
for m=1:M
const1(aa)=pop(it,np).arthvar.PA(m,aa,bb)-PN(aa);
if const1(aa)>0
const1(aa)=abs(const1(aa));
else
const1(aa)=0;
end
end
end
end
0 件のコメント
回答 (1 件)
Walter Roberson
2021 年 8 月 26 日
Why are taking abs() of something that you just tested and found to be greater than 0?
You can replace your current if logic with
const1(aa) = max(pop(it,np).arthvar.PA(m,aa,bb)-PN(aa), 0);
... but where are you taking the sum? It is the double sum that needs to be < 

for aa = 1 : AA
const1(aa) = max(0, sum(pop(it,np).arthvar.PA(:,aa,:), 'all') - PN(aa));
end
That can be vectorized even further to avoid the loop.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Genetic Algorithm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!