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 Multiply 23 extends MathCommand implements IMutateable { 24 25 private static final String CVS_REVISION = "$Revision: 1.6 $"; 26 27 public Multiply(final GPConfiguration a_conf, Class a_type) 28 throws InvalidConfigurationException { 29 super(a_conf, 2, a_type); 30 } 31 32 public CommandGene applyMutation(int index, double a_percentage) 33 throws InvalidConfigurationException { 34 Divide mutant = new Divide(getGPConfiguration(), getReturnType()); 35 return mutant; 36 } 37 38 public String toString() { 39 return "&1 * &2"; 40 } 41 42 48 public String getName() { 49 return "Multiply"; 50 } 51 52 public int execute_int(ProgramChromosome c, int n, Object [] args) { 53 return c.execute_int(n, 0, args) * c.execute_int(n, 1, args); 54 } 55 56 public long execute_long(ProgramChromosome c, int n, Object [] args) { 57 return c.execute_long(n, 0, args) * c.execute_long(n, 1, args); 58 } 59 60 public float execute_float(ProgramChromosome c, int n, Object [] args) { 61 return c.execute_float(n, 0, args) * c.execute_float(n, 1, args); 62 } 63 64 public double execute_double(ProgramChromosome c, int n, Object [] args) { 65 return c.execute_double(n, 0, args) * c.execute_double(n, 1, args); 66 } 67 68 public Object execute_object(ProgramChromosome c, int n, Object [] args) { 69 return ( (Compatible) c.execute_object(n, 0, args)).execute_multiply(c. 70 execute_object(n, 1, args)); 71 } 72 73 protected interface Compatible { 74 public Object execute_multiply(Object o); 75 } 76 } 77 | Popular Tags |