1 10 package org.jgap.gp.function; 11 12 import org.jgap.*; 13 import org.jgap.gp.*; 14 import org.apache.commons.lang.builder.CompareToBuilder; 15 import org.apache.commons.lang.builder.EqualsBuilder; 16 import org.jgap.gp.impl.*; 17 18 24 public class Loop 25 extends CommandGene { 26 27 private final static String CVS_REVISION = "$Revision: 1.4 $"; 28 29 private Class m_typeVar; 30 31 private int m_count; 32 33 44 public Loop(final GPConfiguration a_conf, Class a_typeVar, int a_count) 45 throws InvalidConfigurationException { 46 this(a_conf, a_typeVar, a_count, 0, 0); 47 } 48 49 public Loop(final GPConfiguration a_conf, Class a_typeVar, int a_count, 50 int a_subReturnType, int a_subChildType) 51 throws InvalidConfigurationException { 52 super(a_conf, 1, CommandGene.VoidClass, a_subReturnType, a_subChildType); 53 m_typeVar = a_typeVar; 54 m_count = a_count; 55 } 56 57 public String toString() { 58 return "loop(" + m_count + ", &1 }"; 59 } 60 61 67 public String getName() { 68 return "Loop"; 69 } 70 71 public void execute_void(ProgramChromosome c, int n, Object [] args) { 72 for (int i = 0; i < m_count; i++) { 75 c.execute_void(n, 0, args); 76 } 77 } 78 79 public boolean isValid(ProgramChromosome a_program) { 80 return true; 81 } 82 83 public Class getChildType(IGPProgram a_ind, int a_chromNum) { 84 return CommandGene.VoidClass; 85 } 86 87 96 public int compareTo(Object a_other) { 97 if (a_other == null) { 98 return 1; 99 } 100 else { 101 Loop other = (Loop) a_other; 102 return new CompareToBuilder() 103 .append(m_typeVar, other.m_typeVar) 104 .append(m_count, other.m_count) 105 .toComparison(); 106 } 107 } 108 109 118 public boolean equals(Object a_other) { 119 if (a_other == null) { 120 return false; 121 } 122 else { 123 try { 124 Loop other = (Loop) a_other; 125 return new EqualsBuilder() 126 .append(m_typeVar, other.m_typeVar) 127 .append(m_count, other.m_count) 128 .isEquals(); 129 } catch (ClassCastException cex) { 130 return false; 131 } 132 } 133 } 134 } 135 | Popular Tags |