1 10 package org.jgap; 11 12 import java.io.*; 13 import org.jgap.util.*; 14 15 35 public abstract class FitnessFunction 36 implements Serializable, ICloneable { 37 38 private final static String CVS_REVISION = "$Revision: 1.20 $"; 39 40 public final static double NO_FITNESS_VALUE = -1.0000000d; 41 42 public final static double DELTA = 0.0000001d; 43 44 47 private double m_lastComputedFitnessValue = NO_FITNESS_VALUE; 48 49 61 public final double getFitnessValue(final IChromosome a_subject) { 62 double fitnessValue = evaluate(a_subject); 67 if (fitnessValue < 0.00000000d) { 68 throw new RuntimeException ( 69 "Fitness values must be positive! Received value: " 70 + fitnessValue); 71 } 72 m_lastComputedFitnessValue = fitnessValue; 73 return fitnessValue; 74 } 75 76 84 public double getLastComputedFitnessValue() { 85 return m_lastComputedFitnessValue; 86 } 87 88 103 protected abstract double evaluate(IChromosome a_subject); 104 105 113 public Object clone() { 114 try { 115 return super.clone(); 116 } catch (CloneNotSupportedException cex) { 117 throw new CloneException(cex); 118 } 119 } 120 } 121 | Popular Tags |