1 10 package org.jgap.gp; 11 12 import org.jgap.*; 13 import org.jgap.gp.impl.*; 14 15 22 public abstract class GPProgramBase 23 implements IGPProgram { 24 25 private final static String CVS_REVISION = "$Revision: 1.9 $"; 26 27 private double m_fitnessValue = FitnessFunction.NO_FITNESS_VALUE; 28 29 private GPConfiguration m_conf; 30 31 34 private Class [] m_types; 35 36 39 private Class [][] m_argTypes; 40 41 44 private CommandGene[][] m_nodeSets; 45 46 49 private int[] m_minDepths; 50 51 54 private int[] m_maxDepths; 55 56 60 private int m_maxNodes; 61 62 65 private Object m_applicationData; 66 67 public GPProgramBase(GPConfiguration a_conf) 68 throws InvalidConfigurationException { 69 if (a_conf == null) { 70 throw new InvalidConfigurationException("Configuration must not be null!"); 71 } 72 m_conf = a_conf; 73 } 74 75 public GPProgramBase(IGPProgram a_prog) throws InvalidConfigurationException { 76 this(a_prog.getGPConfiguration()); 77 m_types = a_prog.getTypes(); 78 m_argTypes = a_prog.getArgTypes(); 79 m_nodeSets = a_prog.getNodeSets(); 80 m_maxDepths = a_prog.getMaxDepths(); 81 m_minDepths = a_prog.getMinDepths(); 82 m_maxNodes = a_prog.getMaxNodes(); 83 } 84 85 public GPConfiguration getGPConfiguration() { 86 return m_conf; 87 } 88 89 98 public boolean equals(Object a_other) { 99 try { 100 return compareTo(a_other) == 0; 101 } catch (ClassCastException cex) { 102 return false; 103 } 104 } 105 106 113 public double calcFitnessValue() { 114 GPFitnessFunction normalFitnessFunction = getGPConfiguration(). 115 getGPFitnessFunction(); 116 if (normalFitnessFunction != null) { 117 m_fitnessValue = normalFitnessFunction.getFitnessValue(this); 121 } 122 return m_fitnessValue; 123 } 124 125 131 public double getFitnessValue() { 132 if (m_fitnessValue >= 0.000d) { 133 return m_fitnessValue; 134 } 135 else { 136 return calcFitnessValue(); 137 } 138 } 139 140 146 public double getFitnessValueDirectly() { 147 return m_fitnessValue; 148 } 149 150 public void setFitnessValue(double a_fitness) { 151 m_fitnessValue = a_fitness; 152 } 153 154 public void setTypes(Class [] a_types) { 155 m_types = a_types; 156 } 157 158 public Class [] getTypes() { 159 return m_types; 160 } 161 162 public Class getType(int a_index) { 163 return m_types[a_index]; 164 } 165 166 public void setArgTypes(Class [][] a_argTypes) { 167 m_argTypes = a_argTypes; 168 } 169 170 public Class [][] getArgTypes() { 171 return m_argTypes; 172 } 173 174 public Class [] getArgType(int a_index) { 175 return m_argTypes[a_index]; 176 } 177 178 public void setNodeSets(CommandGene[][] a_nodeSets) { 179 m_nodeSets = a_nodeSets; 180 } 181 182 public CommandGene[][] getNodeSets() { 183 return m_nodeSets; 184 } 185 186 public CommandGene[] getNodeSet(int a_index) { 187 return m_nodeSets[a_index]; 188 } 189 190 public void setMaxDepths(int[] a_maxDepths) { 191 m_maxDepths = a_maxDepths; 192 } 193 194 public int[] getMaxDepths() { 195 return m_maxDepths; 196 } 197 198 public void setMinDepths(int[] a_minDepths) { 199 m_minDepths = a_minDepths; 200 } 201 202 public int[] getMinDepths() { 203 return m_minDepths; 204 } 205 206 public void setMaxNodes(int a_maxNodes) { 207 m_maxNodes = a_maxNodes; 208 } 209 210 public int getMaxNodes() { 211 return m_maxNodes; 212 } 213 214 222 public void setApplicationData(Object a_data) { 223 m_applicationData = a_data; 224 } 225 226 232 public Object getApplicationData() { 233 return m_applicationData; 234 } 235 236 237 243 public abstract Object clone(); 244 } 245 | Popular Tags |