유전자 알고리즘에서 2 포인트 크로스 오버 연산을위한 코드를 작성하려고했습니다. 처음에는 두 개의 무작위 유전자 위치가 선택됩니다. 그 후에, 두 염색체는 genelocation1과 genelocatıon2라고 불리는 난수에 btw 위치하는 유전자를 교환합니다.2 포인트 크로스 오버 작업
for example First Gene [0.3,0.2,0.4,0,0.1,0.5,0.7]
Second Gene [0.25,0.6,0.45,0.15,0.80,0.9,0.85]
rndm genelocation1=3
rdnm gnelocation2 =5
child Gene1 [0.3,0.2,0.4,0.15,0.80,0.5,0.7]
Gene2 [0.25, 0.6, 0.45, 0, 0.1,0.9,0.85]
내 문제점이있다 : 두 개의 번호가 랜덤하게 생성되어 있기 때문에, 전 [genelocation2-genelocation1] .. 어떻게 문제를 해결할 수있는 배열과 같은 배열을 정의 할 수있다. 여기에 2 포인트 크로스 오버에 관한 제 전체 코드가 있습니다. 포인터는 어쩌면 해결책이지만 포인터가 좋지 않습니다. 당신은 스택에 변수 크기의 배열을 정의 할 수 없습니다
void Xover (int mother,int father)
{
int tempo;
int Rndmgenelocation1=(rand()%ActivityNumber);
int Rndmgenelocation2=(rand()%ActivityNumber);
if (Rndmgenelocation1>Rndmgenelocation2)//sure that 2>1
{
tempo=Rndmgenelocation1;
Rndmgenelocation1=Rndmgenelocation2;
Rndmgenelocation2=tempo;
}
int size=(Rndmgenelocation2-Rndmgenelocation1);
int Temp1[size];//this makes an error
int ppp=Rndmgenelocation1;
for (int pp=Rndmgenelocation1;pp<Rndmgenelocation2;pp++)
{
Temp1[pp]=Sol_list[father].Chromosome[ppp];
ppp++;
}
int pppx=Rndmgenelocation1;
for (int ppx=Rndmgenelocation1;ppx<Rndmgenelocation2;ppx++)
{
Sol_list[father].Chromosome[ppx]=Sol_list[mother].Chromosome[pppx];
pppx++;
}
int ppplx=Rndmgenelocation1;
for (int pplx=Rndmgenelocation1;pplx<Rndmgenelocation2;pplx++)
{
Sol_list[father].Chromosome[pplx]=Temp1[ppplx];
ppplx++;
}
return;
}
변수의 의미를 설명 할 수 있습니까? 어머니/아버지는 값 자체인가, 배열의 인덱스인가? ActivityNumber 란 무엇입니까? Sol_list의 구조는 무엇입니까? – Heinzi
어머니와 아버지는 내가 처음에 첫 번째 유전자와 두 번째 유전자로 언급 한 염색체입니다. 나는 "유전자"를 잘못 작성했는데 "염색체"여야합니다. 어쨌든, 활동 수는 유전자의 길이입니다 (이 예제에서 7). Sol_list [] .Chromosome [] 구조체는 이전에 채집 한 것을 저장하는 배열입니다. (예 : Sol_list [1]. 염색체는 첫 번째 유전자, 두 번째 유전자와 같은 이전 집단의 해답입니다) – furkan
내 코드가 이상 할 수도 있습니다. 나는 당신의 코드를 받아들이지 만 처음부터 언급 한 것과 같은 작업을 포함해야합니다. 두 점 크로스 오버 .. 감사합니다 – furkan