2012-02-16 7 views
0

java에서 균일 한 크로스 오버를 구현하는 데 문제가 있습니다. 이것이 알고리즘입니다.Java의 균일 크로스 오버

// Uniform Crossover 
public void UniformCrossover(Individual indi) { 
    if (RVGA.rand.nextDouble() < pc) { 

    // Put your implementation of uniform crossover here 

    // For each gene create a random number in   [0,   1]. 
    // If the number is less than   0.5, swap the gene values in 
    // the parents for this gene; other wise, no swapping . 
} 

은 내가 무작위로 번호를 저장 int tmp 수 알고, 다음 if tmp < 0.5 내가 어떤 도움이 감사를 시작하게 관리 할 수있는 루프

계속!

이것은 내 형식을 알고 있으므로 내 원 포인트 크로스 오버의 예입니다.

1 포인트 크로스 오버 - 크로스 오버 포인트가 선택되면, 크로 모 포인트의 시작부터 크로스 오버 포인트까지의 바이너리 스트링이 한 부모로부터 복사되고, 나머지는 두번째 부모로부터 복사됩니다.

부모 1 = 염색체 및 부모 2 = indi.

내가 균일 한 크로스 오버로 인플레 이스

public void onePointCrossover(Individual indi) { 
    if (SGA.rand.nextDouble() < pc) { 
     int xoverpoint = SGA.rand.nextInt(length); 

     int tmp; 
     for (int i=xoverpoint; i<length; i++){ 
      tmp = chromosome[i]; 
      chromosome[i] = indi.chromosome[i]; 
      indi.chromosome[i] = tmp; 
     } 
    } 
} 
+2

숙제에 대한 질문을 할 때 "숙제"태그를 추가하십시오. – DNA

+0

방금 ​​추가했습니다. – Student

답변

1

자녀로 부모를 전환하고, 당신이 일반적으로하고 싶은 것은 :

For each gene 
    if rand()<0.5 
    take from parent a 
    else 
    take from parent b 

당신은 당신의 원 포인트 예제로, 보인다 동시에 양쪽 부모를 수정해야합니다. 어떤 경우 :

For each gene 
    if rand()<0.5 
    leave both parents alone 
    else 
    swap chromosome[i] with indi.chromosome[i] as before