KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > DeltaFitnessEvaluator


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  * An implementation of a fitness evaluator interpreting the fitness as delta
16  * value.
17  *
18  * @author Klaus Meffert
19  * @since 2.0
20  */

21 public class DeltaFitnessEvaluator
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.10 $";
25
26   /**
27    * Compares the first given fitness value with the second and returns true
28    * if the first one is smaller 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 smaller than second
32    *
33    * @since 2.0 (until 1.1: input types int)
34    */

35   public boolean isFitter(final double a_fitness_value1,
36                           final double a_fitness_value2) {
37     if (Double.isNaN(a_fitness_value1)) {
38       return false;
39     }
40     else if (!Double.isNaN(a_fitness_value1) &&
41              !Double.isNaN(a_fitness_value2)) {
42       if (a_fitness_value1 < 0) {
43         return false;
44       }
45       if (a_fitness_value2 < 0) {
46         return true;
47       }
48       return a_fitness_value1 < a_fitness_value2;
49     }
50     return true;
51   }
52
53   public boolean isFitter(IChromosome a_chrom1, IChromosome a_chrom2) {
54     return isFitter(a_chrom1.getFitnessValue(), a_chrom2.getFitnessValue());
55   }
56
57   /**
58    * @return deep clone of this instance
59    *
60    * @author Klaus Meffert
61    * @since 3.2
62    */

63   public Object JavaDoc clone() {
64     return new DeltaFitnessEvaluator();
65   }
66
67   /**
68    * @param a_other sic
69    * @return as always
70    *
71    * @author Klaus Meffert
72    * @since 3.2
73    */

74   public int compareTo(Object JavaDoc a_other) {
75     if (a_other.getClass().equals(getClass())) {
76       return 0;
77     }
78     else {
79       return getClass().getName().compareTo(a_other.getClass().getName());
80     }
81   }
82 }
83
Popular Tags