01 /*
02 * JENES
03 * A time and memory efficient Java library for genetic algorithms and more
04 * Copyright (C) 2011 Intelligentia srl
05 *
06 * This program is free software: you can redistribute it and/or modify
07 * it under the terms of the GNU General Public License as published by
08 * the Free Software Foundation, either version 3 of the License, or
09 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 package jenes.tutorials.problem2;
20
21 import jenes.chromosome.Chromosome;
22 import jenes.population.Individual;
23 import jenes.population.Population;
24 import jenes.stage.ExclusiveDispenser;
25
26 /**
27 * Tutorial showing how to extend <code>GeneticAlgorithm</code> and how to use
28 * the flexible and configurable breeding structure in Jenes.
29 * The problem consists in searching a pattern of integers with a given precision.
30 * Solutions flow through two different crossovers in parallel. Some are processed by
31 * a single point crossover, the other by a double point crossover.
32 * After solutions are mutated.
33 *
34 * This class implements the strategy for dispensing solutions in the two branches.
35 * Odd solutions goes to the first, even to the second.
36 *
37 * @author Luigi Troiano
38 *
39 * @version 2.0
40 *
41 * @since 1.0
42 */
43 public class SimpleDispenser<T extends Chromosome> extends ExclusiveDispenser<T> {
44
45 private int count;
46
47 public SimpleDispenser(int span) {
48 super(span);
49 }
50
51 public void preDistribute(Population<T> population){
52 this.count = 0;
53 }
54
55 @Override
56 public int distribute(Individual<T> ind) {
57 return count++ % span;
58 }
59
60 }
|
|
|