01 /*
02 * Java Genetic Algorithm Library (jenetics-3.4.0).
03 * Copyright (c) 2007-2016 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@gmx.at)
19 */
20 package org.jenetics;
21
22 /**
23 * Selectors are responsible for selecting a given number of individuals from
24 * the population. The selectors are used to divide the population into
25 * survivors and offspring. The selectors for offspring and for the survivors
26 * can be chosen independently.
27 * <pre>{@code
28 * final Engine<DoubleGene, Double> engine = Engine
29 * .builder(gtf, ff)
30 * .offspringSelector(new RouletteWheelSelector<>())
31 * .survivorsSelector(new TournamentSelector<>())
32 * .build();
33 * }</pre>
34 *
35 * @param <G> The gene type this GA evaluates,
36 * @param <C> The result type (of the fitness function).
37 *
38 * @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
39 * @since 1.0
40 * @version 1.0
41 */
42 @FunctionalInterface
43 public interface Selector<
44 G extends Gene<?, G>,
45 C extends Comparable<? super C>
46 >
47 {
48
49 /**
50 * Select phenotypes from the Population.
51 *
52 * @param population The population to select from.
53 * @param count The number of phenotypes to select.
54 * @param opt Determines whether the individuals with higher fitness values
55 * or lower fitness values must be selected. This parameter determines
56 * whether the GA maximizes or minimizes the fitness function.
57 * @return The selected phenotypes (a new Population).
58 * @throws NullPointerException if the arguments is {@code null}.
59 * @throws IllegalArgumentException if the select count is smaller than zero.
60 */
61 public Population<G, C> select(
62 final Population<G, C> population,
63 final int count,
64 final Optimize opt
65 );
66
67 }
|