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 Xor 23 extends MathCommand { 24 25 private final static String CVS_REVISION = "$Revision: 1.5 $"; 26 27 public Xor(final GPConfiguration a_conf) 28 throws InvalidConfigurationException { 29 super(a_conf, 2, CommandGene.BooleanClass); 30 } 31 32 public CommandGene applyMutation(int index, double a_percentage) 33 throws InvalidConfigurationException { 34 CommandGene mutant; 35 if (a_percentage < 0.5d) { 36 mutant = new And(getGPConfiguration()); 37 } 38 else { 39 mutant = new Or(getGPConfiguration()); 40 } 41 return mutant; 42 } 43 44 public String toString() { 45 return "&1 ^ &2"; 46 } 47 48 54 public String getName() { 55 return "Xor"; 56 } 57 58 public boolean execute_boolean(ProgramChromosome c, int n, Object [] args) { 59 return c.execute_boolean(n, 0, args) ^ c.execute_boolean(n, 1, args); 60 } 61 } 62 | Popular Tags |