package org.jenetics.example;

import org.jenetics.DoubleGene;
import org.jenetics.Mutator;
import org.jenetics.TruncationSelector;
import org.jenetics.engine.Codec;
import org.jenetics.engine.Engine;
import org.jenetics.engine.EvolutionResult;
import org.jenetics.engine.codecs;
import org.jenetics.util.DoubleRange;

/**
 * The (μ, λ) evolution strategy is among the simplest ES algorithms.
 *
 * 1) We begin with a population of (typically) λ number of individuals,
 *    generated randomly.
 * 2) μ is the number of parents which survive. This is realized by setting the
 *    survivors selector to the TruncationSelector.
 * 3) λ is the number of kids that the μ parents make in total. Since only the
 *    offspring are altered, we also use the TruncationSelector for the offspring.
 *
 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
 * @version !__version__!
 * @since !__version__!
 */
public class MLStrategy {

	static double fitness(final double x) {
		return x;
	}

	public static void main(final String[] args) {
		final int μ = 5;
		final int λ = 20;
		final double p = 0.2;

		final Codec<Double, DoubleGene> codec = codecs
			.ofScalar(DoubleRange.of(0, 1));

		final Engine<DoubleGene, Double> engine = Engine
			.builder(MLStrategy::fitness, codec)
			.populationSize(λ)
			.survivorsSize(0)
			.offspringSelector(new TruncationSelector<>(μ))
			.alterers(new Mutator<>(p))
			.build();

		System.out.println(
			codec.decode(
				engine.stream()
					.limit(100)
					.collect(EvolutionResult.toBestGenotype())
			)
		);
	}

}

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

Add Javadoc.