KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > DefaultCrossoverRateCalculator


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.impl;
11
12 import org.jgap.*;
13
14 /**
15  * Default implementation of a dynamic CrossoverRateCalculator.
16  *
17  * @author Chris Knowles
18  * @since 2.0
19  */

20 public class DefaultCrossoverRateCalculator
21     extends BaseRateCalculator {
22   /** String containing the CVS revision. Read out via reflection!*/
23   private static final String JavaDoc CVS_REVISION = "$Revision: 1.8 $";
24
25   /**
26    *
27    * @param a_config the configuration to use
28    * @throws InvalidConfigurationException
29    */

30   public DefaultCrossoverRateCalculator(Configuration a_config)
31       throws InvalidConfigurationException {
32     super(a_config);
33   }
34
35   /**
36    * Calculates the dynamic crossover rate. This is chosen to be the chromosome
37    * size. As the chromosome gets larger we assume that it is less likely to
38    * reproduce.
39    *
40    * @return calculated divisor of crossover rate
41    *
42    * @author Chris Knowles
43    * @since 2.0
44    */

45   public int calculateCurrentRate() {
46     int size = getConfiguration().getChromosomeSize();
47     if (size < 1) {
48       size = 1;
49     }
50     return size;
51   }
52
53   /**
54    * Determines whether crossover is to be carried out for a given population.
55    *
56    * @param a_chrom ignored
57    * @param a_geneIndex ignored
58    * @return true: the DefaultCrossoverRateCalculator always returns a finite
59    * rate
60    *
61    * @author Chris Knowles
62    * @since 2.0
63    */

64   public boolean toBePermutated(IChromosome a_chrom, int a_geneIndex) {
65     return true;
66   }
67 }
68
Popular Tags