Alterer.java
01 /*
02  * Java Genetic Algorithm Library (jenetics-2.0.2).
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  * The Alterer is responsible for the changing/recombining the Population.
24  * Alterers can be chained by appending a list of alterers with the
25  {@link GeneticAlgorithm#setAlterers(Alterer...)} method.
26  *
27  * [code]
28  * final GeneticAlgorithm<DoubleGene, Double> ga = ...
29  * ga.setAlterers(
30  *     new Crossover<DoubleGene>(0.1),
31  *     new Mutator<DoubleGene>(0.05),
32  *     new MeanAlterer<DoubleGene>(0.2)
33  * );
34  * [/code]
35  *
36  * The order of the alterer calls is: Crossover, Mutation and MeanAlterer.
37  *
38  @param <G> the gene type.
39  *
40  @author <a href="mailto:franz.wilhelmstoetter@gmx.at">Franz Wilhelmstötter</a>
41  @since 1.0
42  @version 2.0 &mdash; <em>$Date: 2014-03-30 $</em>
43  */
44 public interface Alterer<G extends Gene<?, G>> {
45 
46 
47     /**
48      * Alters (recombine) a given population. If the {@code population}
49      * is empty, nothing is altered.
50      *
51      @param <C> the fitness function result type
52      @param population The Population to be altered. If the
53      *        {@code population} is {@code null} or empty, nothing is altered.
54      @param generation the date of birth (generation) of the altered phenotypes.
55      @return the number of genes that has been altered.
56      @throws NullPointerException if the given {@code population} is
57      *        {@code null}.
58      */
59     public <C extends Comparable<? super C>> int alter(
60         final Population<G, C> population,
61         final int generation
62     );
63 
64 }