1 10 package org.jgap.gp.function; 11 12 import org.jgap.*; 13 import org.jgap.gp.*; 14 import org.jgap.gp.impl.*; 15 16 22 public class GreaterThan 23 extends MathCommand { 24 25 private final static String CVS_REVISION = "$Revision: 1.1 $"; 26 27 private Class m_type; 28 29 public GreaterThan(final GPConfiguration a_conf, Class a_type) 30 throws InvalidConfigurationException { 31 this(a_conf, a_type, 0, null); 32 } 33 34 public GreaterThan(final GPConfiguration a_conf, Class a_type, 35 int a_subReturnType, 36 int[] a_subChildTypes) 37 throws InvalidConfigurationException { 38 super(a_conf, 2, CommandGene.BooleanClass, a_subReturnType, a_subChildTypes); 39 m_type = a_type; 40 } 41 42 public String toString() { 43 return "&1 > &2"; 44 } 45 46 52 public String getName() { 53 return "GreaterThan"; 54 } 55 56 public boolean execute_boolean(ProgramChromosome c, int n, Object [] args) { 57 if (m_type == CommandGene.BooleanClass) { 58 return c.execute_boolean(n, 0, args) && !c.execute_boolean(n, 1, args); 59 } 60 else if (m_type == CommandGene.IntegerClass) { 61 return c.execute_int(n, 0, args) > c.execute_int(n, 1, args); 62 } 63 else if (m_type == CommandGene.LongClass) { 64 return c.execute_long(n, 0, args) > c.execute_long(n, 1, args); 65 } 66 else if (m_type == CommandGene.DoubleClass) { 67 return c.execute_double(n, 0, args) > c.execute_double(n, 1, args); 68 } 69 else if (m_type == CommandGene.FloatClass) { 70 return c.execute_float(n, 0, args) > c.execute_float(n, 1, args); 71 } 72 throw new UnsupportedOperationException ("Unsupported type " + m_type + 77 " for GreaterThan-command!"); 78 } 79 80 public Class getChildType(IGPProgram a_ind, int a_index) { 81 return m_type; 82 } 83 } 84 | Popular Tags |