Write constraints in MATLAB

์กฐํšŒ ์ˆ˜: 2 (์ตœ๊ทผ 30์ผ)
Zaz Pourghazi
Zaz Pourghazi 2021๋…„ 8์›” 26์ผ
๋‹ต๋ณ€: Walter Roberson 2021๋…„ 8์›” 26์ผ
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

๋‹ต๋ณ€ (1๊ฐœ)

Walter Roberson
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.

์นดํ…Œ๊ณ ๋ฆฌ

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!

Translated by