KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > DefaultFitnessEvaluator


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;
11
12 import org.jgap.util.*;
13
14 /**
15  * A default implementation of a fitness evaluator. This implementation is
16  * straight forward: a higher fitness value is seen as fitter.
17  *
18  * @author Klaus Meffert
19  * @since 1.1
20  */

21 public class DefaultFitnessEvaluator
22     implements FitnessEvaluator, ICloneable, Comparable JavaDoc {
23   /** String containing the CVS revision. Read out via reflection!*/
24   private final static String JavaDoc CVS_REVISION = "$Revision: 1.12 $";
25
26   /**
27    * Compares the first given fitness value with the second and returns true
28    * if the first one is greater than the second one. Otherwise returns false
29    * @param a_fitness_value1 first fitness value
30    * @param a_fitness_value2 second fitness value
31    * @return true: first fitness value greater than second
32    *
33    * @author Klaus Meffert
34    * @since 2.0 (until 1.1: input types int)
35    */

36   public boolean isFitter(final double a_fitness_value1,
37                           final double a_fitness_value2) {
38     return a_fitness_value1 > a_fitness_value2;
39   }
40
41   public boolean isFitter(IChromosome a_chrom1, IChromosome a_chrom2) {
42     return isFitter(a_chrom1.getFitnessValue(), a_chrom2.getFitnessValue());
43   }
44
45   /**
46    * @return deep clone of this instance
47    *
48    * @author Klaus Meffert
49    * @since 3.2
50    */

51   public Object JavaDoc clone() {
52     return new DefaultFitnessEvaluator();
53   }
54
55   /**
56    * @param a_other sic
57    * @return as always
58    *
59    * @author Klaus Meffert
60    * @since 3.2
61    */

62   public int compareTo(Object JavaDoc a_other) {
63     if (a_other.getClass().equals(getClass())) {
64       return 0;
65     }
66     else {
67       return getClass().getName().compareTo(a_other.getClass().getName());
68     }
69   }
70 }
71
Popular Tags