KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Fitness function always returning the same value.<p>
16  * Only for testing purpose!
17  *
18  * @author Klaus Meffert
19  * @since 1.1
20  */

21 public class StaticFitnessFunction
22     extends FitnessFunction implements Comparable JavaDoc {
23
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.10 $";
26
27   /**
28    * @since 2.0 (until 1.1: type int)
29    */

30   private double m_staticFitnessValue;
31
32   /**
33    * @param a_staticFitnessValue double
34    *
35    * @author Klaus Meffert
36    * @since 2.0 (until 1.1: input type int)
37    */

38   public StaticFitnessFunction(double a_staticFitnessValue) {
39     m_staticFitnessValue = a_staticFitnessValue;
40   }
41
42   /**
43    * @param a_chrom ignored: the Chromosome to evaluate
44    * @return static fitness value
45    *
46    * @author Klaus Meffert
47    * @since 2.0 (until 1.1: return type int)
48    */

49   public double evaluate(IChromosome a_chrom) {
50     double result = m_staticFitnessValue;
51     return result;
52   }
53
54   /**
55    * @return double typed fitness value
56    *
57    * @author Klaus Meffert
58    * @since 2.0 (until 1.1: return type int)
59    */

60   public double getStaticFitnessValue() {
61     return m_staticFitnessValue;
62   }
63
64   /**
65    * @param a_staticFitnessValue the value to return as fitness value when
66    * calling evaluate()
67    *
68    * @author Klaus Meffert
69    * @since 2.0 (until 1.1: type int)
70    */

71   public void setStaticFitnessValue(double a_staticFitnessValue) {
72     m_staticFitnessValue = a_staticFitnessValue;
73   }
74
75   public int hashCode() {
76     int result = new Double JavaDoc(m_staticFitnessValue).hashCode();
77     return result;
78   }
79
80   /**
81    * @param a_other sic
82    * @return as always
83    *
84    * @author Klaus Meffert
85    * @since 3.2
86    */

87   public int compareTo(Object JavaDoc a_other) {
88     StaticFitnessFunction other = (StaticFitnessFunction)a_other;
89     if (m_staticFitnessValue > other.m_staticFitnessValue) {
90       return 1;
91     }
92     else if (m_staticFitnessValue < other.m_staticFitnessValue) {
93       return -1;
94     }
95     else {
96       return 0;
97     }
98   }
99 }
100
Popular Tags