1

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 番目の親からコピーされます。

親 1 = 染色体および親 2 = インディ。

親をインプレースの子に変えています

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;
        }   
    }   
}
4

1 に答える 1

3

一様なクロスオーバーでは、一般的にやりたいことは次のとおりです。

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
于 2012-02-17T01:58:29.983 に答える