01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licencing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
10: package org.jgap.gp.impl;
11:
12: import org.jgap.*;
13: import org.jgap.gp.*;
14:
15: /**
16: * GP Fitness function always returning the same value.<p>
17: * Only for testing purpose!
18: *
19: * @author Klaus Meffert
20: * @since 3.2
21: */
22: public class StaticGPFitnessFunction extends GPFitnessFunction
23: implements Comparable {
24: /** String containing the CVS revision. Read out via reflection!*/
25: private final static String CVS_REVISION = "$Revision: 1.1 $";
26:
27: /**
28: * @since 3.2
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 StaticGPFitnessFunction(double a_staticFitnessValue) {
39: m_staticFitnessValue = a_staticFitnessValue;
40: }
41:
42: /**
43: * @param a_subject ignored: the GP program to evaluate
44: * @return static fitness value
45: *
46: * @author Klaus Meffert
47: * @since 3.2
48: */
49: protected double evaluate(IGPProgram a_subject) {
50: double result = m_staticFitnessValue;
51: return result;
52: }
53:
54: /**
55: * @return double typed fitness value
56: *
57: * @author Klaus Meffert
58: * @since 3.2
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(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 a_other) {
88: StaticGPFitnessFunction other = (StaticGPFitnessFunction) a_other;
89: if (m_staticFitnessValue > other.m_staticFitnessValue) {
90: return 1;
91: } else if (m_staticFitnessValue < other.m_staticFitnessValue) {
92: return -1;
93: } else {
94: return 0;
95: }
96: }
97: }
|