Java中的一致交叉

Java中的一致交叉,java,genetic-algorithm,crossover,Java,Genetic Algorithm,Crossover,我在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].

我在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 .
}

对于均匀交叉,您通常要做的是:

For each gene
  if rand()<0.5
    take from parent a
  else
    take from parent b
每个基因的

如果是rand(),请在询问家庭作业问题时添加“家庭作业”标签。
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