size error in matlab code

조회 수: 1 (최근 30일)
Metehan Geçer
Metehan Geçer 2022년 5월 23일
편집: Torsten 2022년 5월 23일
clc;
clear all;
close all;
eniyifitness=zeros(810,5);
sayac=1;
for iii=1:3
if iii ==1
Pm=0.1;
end
if iii==2
Pm=0.2;
end
if iii==3
Pm=0.3;
end
for jjj=1:3
if jjj==1
popsize=100;
MaxIterration=1000;
end
if jjj==2
popsize=200;
MaxIterration=500;
end
if jjj==3
popsize=250;
MaxIterration=400;
end
for kkk=1:3
if kkk==1
e=0.1;
end
if kkk==2
e=0.2;
end
if kkk==3
e=0.3;
end
for p=1:30
tic
%PARAMETRELER
%MaxIterration=10;
M=3;%kromozom sayısı
Pc=1;%çaprazlama olasılığı
%Pm=0.3;%mutasyon olasılığı
alfa1=0.1 ;
alfa2=0.5 ;
%popsize=10;
%e=0.1
k=3 ;
cozumhafiza=zeros(popsize,M);
fitnesshafiza=zeros(popsize,1);
for i=1 : popsize
%ilk çözüm
x1=('a')*rand(1);
x2=('a')*rand(1);
x3=('a')*rand(1);
cozum00=[x1 x2 x3];
%ilk fitness hesabı
f0=6*x1+6*x2+7*x3;
ceza1=(6*x1+7*x2+7*x3)-(20+2*(1-alfa1));
ceza2=(5*x1+5*x2+9*x3)-(110+11*(1-alfa1));
ceza3=(4*x1+3*x2+8*x3)-(150+15*(1-alfa1));
if ceza1>0
f1=f0-ceza1*2;
end
if ceza2>0
f1=f1-ceza2*2;
end
if ceza3>0
f1=f1-ceza3*2;
end
cozumhafiza(i,: )=cozum00;
fitnesshafiza(i,:)=f1;
end
for i7=1:MaxIterration
C4=popsize-popsize*e;
ebeveynhafiza=zeros(C4*2,M);
ebeveynfitnesslar=zeros(C4*2,1);
for i2=1:C4*2
A=randi([1,popsize],k,1)
B=fitnesshafiza(A)
C=cozumhafiza(A,:)
B2=sort(B)
ebeveynfitness=B2(k,1)
[mm,i4]=max(B)
%ebeveyn sıra numarası bulma
%A(i,1);
%fprintf('Ebeveyn sirasi: %d\n ',round(A(i,1)));
%cozumhafiza(A(i,1),[1,2,3]);
ebeveynkromozom=cozumhafiza(A(i4,1),[1,2,3])
ebeveynhafiza(i2,:)=ebeveynkromozom;
ebeveynfitnesslar(i2,:)=ebeveynfitness;
end
ebeveynhafiza;
ebeveynfitnesslar;
%Tam aritmetik yapılsın
cocuklar=zeros(C4,3);
for i3=1:C4
anne=ebeveynhafiza(i3*2-1,:)
baba=ebeveynhafiza(i3*2,:)
cocuk=anne
rassal=randi (3)
cocuk(1,rassal)=anne(1,rassal)*alfa2+baba(1,rassal)*(1-alfa2)
cocuklar(i3,:)=cocuk
end
cocuklar;
for i6=1:C4
rassal2=rand;
if rassal2<Pm
rassal1=randi(3);
rassal3=('a')*rand(1);
cocuklar(i6,rassal1)=rassal3;
end
end
for i5=1:C4
x1=cocuklar(i5,1);
x2=cocuklar(i5,2);
x3=cocuklar(i5,3);
f2=6*x1+6*x2+7*x3;
ceza1=(6*x1+7*x2+7*x3)-(20+2*(1-alfa1));
ceza2=(5*x1+5*x2+9*x3)-(110+11*(1-alfa1));
ceza3=(4*x1+3*x2+8*x3)-(150+15*(1-alfa1));
if ceza1>0
f3=f2-ceza1*2;
end
if ceza2>0
f3=f3-ceza2*2;
end
if ceza3>0
f3=f3-ceza3*2;
end
cocukfitnesslar(i5,1)=f3;
end
cocukfitnesslar;
ebeveynfitnesslar;
C1=[fitnesshafiza];
C2=sort(C1);
C21=C2(C4+1:end); %%ELİTİZM UYGULANACAK BİREYLERİN FİTNESSLARI
[~,idx] = ismember(C2,C1)%%elitizm uygulanacakların hangi sırada olduğu
C3=idx
N2=cozumhafiza(C3,:);
yenipopulasyonfitnesslari=[cocukfitnesslar;C21];
fitnesshafiza=yenipopulasyonfitnesslari;
cozumhafiza=[cocuklar;N2];
end
sure=toc
eniyifitness(sayac,1)=Pm;
eniyifitness(sayac,2)=p
popsize;
eniyifitness(sayac,3)=MaxIterration;
eniyifitness(sayac,4)=e;
eniyifitness(sayac,5)=max(fitnesshafiza);
sayac=sayac+1;
end
end
end
end
I am getting an error on this line while the runs continue, 810 lines should find a solution, but 230 solutions give a size error. I want the solutions I will find to go up to 810 lines, how can I fix it?
wrong line : N2=cozumhafiza(C3,:);
  댓글 수: 4
Metehan Geçer
Metehan Geçer 2022년 5월 23일
wrong line :N2=cozumhafiza(C3,:);
error message : Index in position 1 exceeds array bounds(must not exceed 190 )
Error in GA (line 165)
Metehan Geçer
Metehan Geçer 2022년 5월 23일
There was no such thing as opsize when I wrote it, the moderator edited it

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by