/*
 * Java Genetic Algorithm Library (@__identifier__@).
 * Copyright (c) @__year__@ Franz Wilhelmstötter
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author:
 *    Franz Wilhelmstötter (franz.wilhelmstoetter@gmx.at)
 */
package org.jenetics;

import static java.lang.Math.min;
import static org.jenetics.internal.math.random.indexes;

import org.jenetics.util.MSeq;
import org.jenetics.util.RandomRegistry;

/**
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version !__version__!
 * @since !__version__!
 */
public class UniformCrossover<
	G extends Gene<?, G>,
	C extends Comparable<? super C>
>
	extends Crossover<G, C>
{

	public UniformCrossover(final double probability) {
		super(probability);
	}

	public UniformCrossover() {
		this(DEFAULT_ALTER_PROBABILITY);
	}

	@Override
	protected int crossover(final MSeq<G> that, final MSeq<G> other) {
		final int length = min(that.length(), other.length());
		return (int)indexes(RandomRegistry.getRandom(), length, _probability)
			.peek(i -> swap(i, that, other))
			.count();
	}

	private static <T> void swap(
		final int index,
		final MSeq<T> that,
		final MSeq<T> other
	) {
		final T temp = that.get(index);
		that.set(index, other.get(index));
		other.set(index, temp);
	}

}

@@ -845,24 +845,68 @@
 m.indexes;%0A%0A
+import org.jenetics.internal.util.require;%0A%0A
 import org.j
@@ -1223,16 +1223,546 @@
 , C%3E%0A%7B%0A%0A
+%09private final double _swapProbability;%0A%0A%09/**%0A%09 * Create a new universal crossover instance.%0A%09 *%0A%09 * @param crossoverProbability the recombination probability as defined in%0A%09 *        %7B@link Crossover#Crossover(double)%7D. This is the probability that%0A%09 *        a given individual is selected for crossover.%0A%09 * @param swapProbability the probability for swapping genes a given gene of%0A%09 *         a chromosome%0A%09 * @throws IllegalArgumentException if the probabilities are not in the%0A%09 *         valid range of %7B@code %5B0, 1%5D%7D%0A%09 */%0A
 %09public 
@@ -1774,24 +1774,27 @@
 rmCrossover(
+%0A%09%09
 final double
@@ -1794,17 +1794,58 @@
  double 
-p
+crossoverProbability,%0A%09%09final double swapP
 robabili
@@ -1846,16 +1846,18 @@
 bability
+%0A%09
 ) %7B%0A%09%09su
@@ -1864,88 +1864,1119 @@
 per(
-probability);%0A%09%7D%0A%0A%09public UniformCrossover() %7B%0A%09%09this(DEFAULT_ALTER_PROBABILITY)
+crossoverProbability);%0A%09%09_swapProbability = require.probability(swapProbability);%0A%09%7D%0A%0A%09/**%0A%09 * Create a new universal crossover instance. The %7B@code swapProbability%7D is%0A%09 * set to %7B@link Alterer#DEFAULT_ALTER_PROBABILITY%7D.%0A%09 *%0A%09 * @param crossoverProbability the recombination probability as defined in%0A%09 *        %7B@link Crossover#Crossover(double)%7D. This is the probability that%0A%09 *        a given individual is selected for crossover.%0A%09 * @throws IllegalArgumentException if the probabilities are not in the%0A%09 *         valid range of %7B@code %5B0, 1%5D%7D%0A%09 */%0A%09public UniformCrossover(final double crossoverProbability) %7B%0A%09%09this(crossoverProbability, DEFAULT_ALTER_PROBABILITY);%0A%09%7D%0A%0A%09/**%0A%09 * Create a new universal crossover instance. The probabilities are set to%0A%09 * %7B@link Alterer#DEFAULT_ALTER_PROBABILITY%7D.%0A%09 */%0A%09public UniformCrossover() %7B%0A%09%09this(DEFAULT_ALTER_PROBABILITY, DEFAULT_ALTER_PROBABILITY);%0A%09%7D%0A%0A%09/**%0A%09 * Return the probability for swapping genes of a chromosome.%0A%09 *%0A%09 * @return the probability for swapping genes of a chromosome%0A%09 */%0A%09public double getSwapProbability() %7B%0A%09%09return _swapProbability
 ;%0A%09%7D
@@ -3172,17 +3172,21 @@
 ength, _
-p
+swapP
 robabili

Add Javadoc.