java.tutorial.problem2.SimpleDispencer.java

01 /*
02  * CISELab, Computational and Intelligent Systems Engineering Laboratory
03  * Department of Engineering
04  * University of Sannio, 82100 Benevento (ITALY)
05  * web-site: www.ciselab.org
06  *
07  * JENES, A Java Library for Genetic Algorithms
08  * Copyright (C) 2009, Luigi Troiano
09  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301  USA
24  *
25  * COPYRIGHT DISCLAIMER
26  * CISELab, hereby disclaims all copyright interest in the
27  * library `JENES' (A Java Library for Genetic Algorithms)
28  * written by Luigi Troiano et al.
29  *
30  * Luigi Troiano, 1 January 2009
31  * CISELab Coordinator
32  */

33 package jenes.tutorials.problem2;
34 
35 import jenes.chromosome.Chromosome;
36 import jenes.population.Individual;
37 import jenes.population.Population;
38 import jenes.stage.ExclusiveDispenser;
39 
40 public class SimpleDispenser<T extends Chromosome> extends ExclusiveDispenser<T> {
41     
42     private int count;
43     
44     public SimpleDispenser(int span) {
45         super(span);
46     }
47     
48     public void preDistribute(Population<T> population){
49         this.count = 0;
50     }
51     
52     @Override
53     public int distribute(Individual<T> ind) {
54         return count++ % span;
55     }
56     
57 }
Comments