Selector.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-1.6.0).
03  * Copyright (c) 2007-2014 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  * [code]
28  * final GeneticAlgorithm<DoubleGene, Double> ga = ...
29  * ga.setOffspringFraction(0.7);
30  * ga.setSurvivorSelector(
31  *     new RouletteWheelSelector<DoubleGene, Double>()
32  * );
33  * ga.setOffspringSelector(
34  *     new TournamentSelector<DoubleGene, Double>()
35  * );
36  * [/code]
37  *
38  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
39  @since 1.0
40  @version 1.0 &mdash; <em>$Date: 2014-02-14 $</em>
41  */
42 public interface Selector<
43     extends Gene<?, G>,
44     extends Comparable<? super C>
45 >
46 {
47 
48     /**
49      * Select phenotypes from the Population.
50      *
51      @param population The population to select from.
52      @param count The number of phenotypes to select.
53      @param opt Determines whether the individuals with higher fitness values
54      *        or lower fitness values must be selected. This parameter determines
55      *        whether the GA maximizes or minimizes the fitness function.
56      @return The selected phenotypes (a new Population).
57      @throws NullPointerException if the arguments is {@code null}.
58      @throws IllegalArgumentException if the select count is smaller than zero.
59      */
60     public Population<G, C> select(
61         final Population<G, C> population,
62         final int count,
63         final Optimize opt
64     );
65 
66 }