01 /*
02 * Java Genetic Algorithm Library (jenetics-6.1.0).
03 * Copyright (c) 2007-2020 Franz Wilhelmstötter
04 *
05 * Licensed under the Apache License, Version 2.0 (the "License");
06 * you may not use this file except in compliance with the License.
07 * You may obtain a copy of the License at
08 *
09 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * Author:
18 * Franz Wilhelmstötter (franz.wilhelmstoetter@gmail.com)
19 */
20 package io.jenetics.engine;
21
22 import io.jenetics.Gene;
23 import io.jenetics.Phenotype;
24 import io.jenetics.util.ISeq;
25
26 /**
27 * This functional interface defines the evolution function, which takes an
28 * {@link EvolutionStart} object, evolves the population, and returns an
29 * {@link EvolutionResult} object.
30 *
31 * @param <G> the gene type
32 * @param <C> the fitness result type
33 *
34 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
35 * @version 5.1
36 * @since 5.1
37 */
38 @FunctionalInterface
39 public interface Evolution<
40 G extends Gene<?, G>,
41 C extends Comparable<? super C>
42 > {
43
44 /**
45 * Perform one evolution step with the given evolution {@code start} object
46 * New phenotypes are created with the fitness function and fitness scaler
47 * defined by this <em>engine</em>
48 *
49 * @apiNote
50 * The implementation of this method must be thread-safe.
51 *
52 * @since 3.1
53 * @see #evolve(ISeq, long)
54 *
55 * @param start the evolution start object
56 * @return the evolution result
57 * @throws java.lang.NullPointerException if the given evolution
58 * {@code start} is {@code null}
59 */
60 EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start);
61
62
63 /**
64 * Perform one evolution step with the given {@code population} and
65 * {@code generation}.
66 * <p>
67 * <em>This method is thread-safe.</em>
68 *
69 * @see #evolve(EvolutionStart)
70 *
71 * @param population the population to evolve
72 * @param generation the current generation; used for calculating the
73 * phenotype age.
74 * @return the evolution result
75 * @throws java.lang.NullPointerException if the given {@code population} is
76 * {@code null}
77 * @throws IllegalArgumentException if the given {@code generation} is
78 * smaller then one
79 */
80 default EvolutionResult<G, C> evolve(
81 final ISeq<Phenotype<G, C>> population,
82 final long generation
83 ) {
84 return evolve(EvolutionStart.of(population, generation));
85 }
86
87 }
|