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 If 23 extends CommandGene { 24 25 private final static String CVS_REVISION = "$Revision: 1.4 $"; 26 27 public If(final GPConfiguration a_conf, Class type) 28 throws InvalidConfigurationException { 29 super(a_conf, 2, type); 30 } 31 32 public String toString() { 33 return "if(&1) then (&2)"; 34 } 35 36 public boolean execute_boolean(ProgramChromosome c, int n, Object [] args) { 37 boolean x = c.execute_boolean(n, 0, args); 38 boolean value = false; 39 if (x) { 40 value = c.execute_boolean(n, 1, args); 41 } 42 return value; 43 } 44 45 public int execute_int(ProgramChromosome c, int n, Object [] args) { 46 int x = c.execute_int(n, 0, args); 47 int value = 0; 48 if (x >= 0) { 49 value = c.execute_int(n, 1, args); 50 } 51 return value; 52 } 53 54 public long execute_long(ProgramChromosome c, int n, Object [] args) { 55 long x = c.execute_long(n, 0, args); 56 long value = 0; 57 if (x >= 0) { 58 value = c.execute_long(n, 1, args); 59 } 60 return value; 61 } 62 63 public float execute_float(ProgramChromosome c, int n, Object [] args) { 64 float x = c.execute_float(n, 0, args); 65 float value = 0; 66 if (x >= 0) { 67 value = c.execute_float(n, 1, args); 68 } 69 return value; 70 } 71 72 public double execute_double(ProgramChromosome c, int n, Object [] args) { 73 double x = c.execute_double(n, 0, args); 74 double value = 0; 75 if (x >= 0) { 76 value = c.execute_double(n, 1, args); 77 } 78 return value; 79 } 80 81 public void execute_void(ProgramChromosome c, int n, Object [] args) { 82 int x = c.execute_int(n, 0, args); 83 if (x >= 0) { 84 c.execute_void(n, 1, args); 85 } 86 } 87 } 88 | Popular Tags |