01 /*
02 * Java Genetic Algorithm Library (jenetics-5.1.0).
03 * Copyright (c) 2007-2019 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 * @author <a href="mailto:franz.wilhelmstoetter@gmail.com">Franz Wilhelmstötter</a>
28 * @version 5.1
29 * @since 5.1
30 */
31 @FunctionalInterface
32 public interface Evolution<
33 G extends Gene<?, G>,
34 C extends Comparable<? super C>
35 > {
36
37 /**
38 * Perform one evolution step with the given evolution {@code start} object
39 * New phenotypes are created with the fitness function and fitness scaler
40 * defined by this <em>engine</em>
41 *
42 * @apiNote
43 * The implementation of this method must be thread-safe.
44 *
45 * @since 3.1
46 * @see #evolve(ISeq, long)
47 *
48 * @param start the evolution start object
49 * @return the evolution result
50 * @throws java.lang.NullPointerException if the given evolution
51 * {@code start} is {@code null}
52 */
53 public EvolutionResult<G, C> evolve(final EvolutionStart<G, C> start);
54
55
56 /**
57 * Perform one evolution step with the given {@code population} and
58 * {@code generation}. New phenotypes are created with the fitness function
59 * and fitness scaler defined by this <em>engine</em>
60 * <p>
61 * <em>This method is thread-safe.</em>
62 *
63 * @see #evolve(EvolutionStart)
64 *
65 * @param population the population to evolve
66 * @param generation the current generation; used for calculating the
67 * phenotype age.
68 * @return the evolution result
69 * @throws java.lang.NullPointerException if the given {@code population} is
70 * {@code null}
71 * @throws IllegalArgumentException if the given {@code generation} is
72 * smaller then one
73 */
74 public default EvolutionResult<G, C> evolve(
75 final ISeq<Phenotype<G, C>> population,
76 final long generation
77 ) {
78 return evolve(EvolutionStart.of(population, generation));
79 }
80
81 }
|