1 package examples.gp; 2 3 import org.jgap.gp.impl.*; 4 import org.jgap.gp.*; 5 import org.jgap.gp.function.*; 6 import org.jgap.gp.terminal.*; 7 8 15 public class FibonacciNodeValidator 16 implements INodeValidator { 17 44 public boolean validate(ProgramChromosome a_chrom, CommandGene a_node, 45 CommandGene a_rootNode, 46 int a_tries, int a_num, int a_recurseLevel, 47 Class a_type, CommandGene[] a_functionSet, 48 int a_depth, boolean a_grow, int a_childIndex) { 49 if (a_tries > 10) { 52 return true; 53 } 54 if (a_num == 0) { 57 if (a_recurseLevel > 0 && a_node.getClass() == SubProgram.class) { 59 return false; 60 } 61 if (a_recurseLevel == 0 && a_node.getClass() != SubProgram.class) { 62 return false; 63 } 64 if (a_recurseLevel == 1 && a_node.getClass() != StoreTerminal.class) { 65 return false; 66 } 67 } 68 if (a_num == 1) { 71 if (a_recurseLevel > 0 && a_node.getClass() == ForLoop.class) { 73 return false; 74 } 75 if (a_recurseLevel == 0 && a_node.getClass() != ForLoop.class) { 77 return false; 78 } 79 if (a_recurseLevel > 1 && a_node.getClass() == Variable.class) { 81 return false; 82 } 83 if (a_recurseLevel == 1 && a_depth == 1 85 && a_node.getClass() != Variable.class) { 86 return false; 87 } 88 if (a_recurseLevel > 1 && a_depth > 1 90 && a_node.getClass() == SubProgram.class) { 91 return false; 92 } 93 if (a_recurseLevel == 1 && a_depth > 1 && a_type == CommandGene.VoidClass 95 && a_node.getClass() != SubProgram.class) { 96 return false; 97 } 98 if (a_recurseLevel == 2 && a_depth > 1 && a_type == CommandGene.VoidClass 100 && a_node.getClass() != AddAndStore.class 101 && a_node.getClass() != TransferMemory.class) { 102 return false; 103 } 104 if (a_recurseLevel != 2 && a_depth > 1 && a_type == CommandGene.VoidClass 106 && (a_node.getClass() == AddAndStore.class 107 || a_node.getClass() == TransferMemory.class)) { 108 return false; 109 } 110 } 111 return true; 112 } 113 } 114 | Popular Tags |