<commit_before>/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ <NAME>
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     <NAME> (<EMAIL>)
 *     
 */
package org.jenetics;

import static org.jenetics.util.ArrayUtils.shuffle;
import static org.jenetics.util.ArrayUtils.subset;
import static org.jenetics.util.EvaluatorRegistry.evaluate;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.jenetics.util.Evaluator;
import org.jenetics.util.EvaluatorRegistry;
import org.jenetics.util.Probability;
import org.jenetics.util.RandomRegistry;

/**
 * An EGA combine elements of existing solutions in order to create a new solution, 
 * with some of the properties of each parent. Recombination creates a new 
 * chromosome by combining parts of two (or more) parent chromosomes. This 
 * combination of chromosomes can be made by selecting one or more crossover 
 * points, splitting these chromosomes on the selected points, and merge those 
 * portions of different chromosomes to form new ones.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id: Recombination.java,v 1.17 2010-01-14 16:12:48 fwilhelm Exp $
 */
public abstract class Recombination<G extends Gene<?, G>> extends Alterer<G> {

	/**
	 * Create a <code>Alterer</code> concatenating the given 
	 * <code>Alterer</code>S.
	 * 
	 * @param component the <code>Alterer</code>S this <code>Alterer</code>
	 *        consists.
	 */
	public Recombination(final Alterer<G> component) {
		this(Probability.ONE, component);
	}
	
	/**
	 * Constructs an alterer with a given recombination probability.
	 * 
	 * @param probability The recombination probability.
	 * @throws NullPointerException if the <code>probability</code> is 
	 * 		<code>null</code>.
	 */
	public Recombination(final Probability probability) {
		super(probability);
	}
	
	/**
	 * Constructs an alterer with a given recombination probability. A
	 * second Alterer can be specified for a composite Alterer.
	 * 
	 * @param probability The recombination probability.
	 * @param component The composite Alterer.
	 * @throws NullPointerException if the <code>probability</code> or the
	 * 		<code>component</code> is <code>null</code>. 
	 */
	public Recombination(
		final Probability probability, final Alterer<G> component
	) {
		super(probability, component);
	}

	/**
	 * This method executes the recombination of in parallel if the current
	 * {@link Evaluator} 
	 */
	@Override
	protected final <C extends Comparable<C>> void change(
		final Population<G, C> population, final int generation
	) {
		final int subsetSize = (int)Math.ceil(population.size()*_probability.doubleValue());
		
		if (subsetSize > 0) {
			final Random random = RandomRegistry.getRandom();<commit_msg>Adding javadoc.<commit_after>/*
 * Java Genetic Algorithm Library (@!identifier!@).
 * Copyright (c) @!year!@ <NAME>ter
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author:
 *     <NAME> (<EMAIL>)
 *     
 */
package org.jenetics;

import static org.jenetics.util.ArrayUtils.shuffle;
import static org.jenetics.util.ArrayUtils.subset;
import static org.jenetics.util.EvaluatorRegistry.evaluate;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.jenetics.util.Evaluator;
import org.jenetics.util.EvaluatorRegistry;
import org.jenetics.util.Probability;
import org.jenetics.util.RandomRegistry;

/**
 * An EGA combine elements of existing solutions in order to create a new solution, 
 * with some of the properties of each parent. Recombination creates a new 
 * chromosome by combining parts of two (or more) parent chromosomes. This 
 * combination of chromosomes can be made by selecting one or more crossover 
 * points, splitting these chromosomes on the selected points, and merge those 
 * portions of different chromosomes to form new ones.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @version $Id: Recombination.java,v 1.18 2010-01-15 09:23:57 fwilhelm Exp $
 */
public abstract class Recombination<G extends Gene<?, G>> extends Alterer<G> {

	/**
	 * Create a <code>Alterer</code> concatenating the given 
	 * <code>Alterer</code>S.
	 * 
	 * @param component the <code>Alterer</code>S this <code>Alterer</code>
	 *        consists.
	 */
	public Recombination(final Alterer<G> component) {
		this(Probability.ONE, component);
	}
	
	/**
	 * Constructs an alterer with a given recombination probability.
	 * 
	 * @param probability The recombination probability.
	 * @throws NullPointerException if the <code>probability</code> is 
	 * 		<code>null</code>.
	 */
	public Recombination(final Probability probability) {
		super(probability);
	}
	
	/**
	 * Constructs an alterer with a given recombination probability. A
	 * second Alterer can be specified for a composite Alterer.
	 * 
	 * @param probability The recombination probability.
	 * @param component The composite Alterer.
	 * @throws NullPointerException if the <code>probability</code> or the
	 * 		<code>component</code> is <code>null</code>. 
	 */
	public Recombination(
		final Probability probability, final Alterer<G> component
	) {
		super(probability, component);
	}

	/**
	 * This method executes the recombination of in parallel if the current
	 * {@link Evaluator} provides more than one parallel tasks.
	 */
	@Override
	protected final <C extends Comparable<C>> void change(
		final Population<G, C> population, final int generation
	) {
		final int subsetSize = (int)Math.ceil(population.size()*_probability.doubleValue());
		
		if (subsetSize > 0) {
			final Random random = RandomRegistry.getRandom();
{'fraction_non_alphanumeric': 0.09563113704283478, 'fraction_numerical': 0.008823110858118686, 'mean_word_length': 4.052480230050324, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1669699', 'n_tokens_mistral': 2161, 'n_tokens_neox': 1932, 'n_words': 754}