1 10 package org.jgap.gp.impl; 11 12 import org.jgap.*; 13 import org.jgap.gp.function.*; 14 15 import org.jgap.gp.*; 16 17 23 public class CommandFactory { 24 25 private final static String CVS_REVISION = "$Revision: 1.1 $"; 26 27 public static CommandGene[] createStoreCommands(CommandGene[] a_target, 28 GPConfiguration a_conf, 29 Class a_type, String a_prefix, 30 int a_count) 31 throws InvalidConfigurationException { 32 CommandGene[] result = new CommandGene[a_count * 2 + a_target.length]; 33 for (int i = 0; i < a_target.length; i++) { 34 result[i] = a_target[i]; 35 } 36 for (int i = 0; i < a_count; i++) { 37 result[i * 2 + a_target.length] = new StoreTerminal(a_conf, 38 a_prefix + i, a_type); 39 result[i * 2 + 1 + 40 a_target.length] = new ReadTerminal(a_conf, a_type, 41 a_prefix + i); 42 } 43 return result; 44 } 45 46 public static CommandGene[] createWriteOnlyCommands(CommandGene[] a_target, 47 GPConfiguration a_conf, 48 Class a_type, String a_prefix, 49 int a_count, 50 boolean a_noValidation) 51 throws InvalidConfigurationException { 52 CommandGene[] result = new CommandGene[a_count + a_target.length]; 53 for (int i = 0; i < a_target.length; i++) { 54 result[i] = a_target[i]; 55 } 56 for (int i = 0; i < a_count; i++) { 57 CommandGene writeCommand = new StoreTerminal(a_conf, 58 a_prefix + i, a_type); 59 writeCommand.setNoValidation(a_noValidation); 60 result[i + a_target.length] = writeCommand; 61 } 62 return result; 63 } 64 65 public static CommandGene[] createReadOnlyCommands(CommandGene[] a_target, 66 GPConfiguration a_conf, 67 Class a_type, String a_prefix, 68 int a_count, 69 int a_startIndex, 70 boolean a_noValidation) 71 throws InvalidConfigurationException { 72 CommandGene[] result = new CommandGene[a_count + a_target.length]; 73 for (int i = 0; i < a_target.length; i++) { 74 result[i] = a_target[i]; 75 } 76 for (int i = 0; i < a_count; i++) { 77 CommandGene readCommand = new ReadTerminal(a_conf, a_type, 78 a_prefix + (i + a_startIndex)); 79 readCommand.setNoValidation(a_noValidation); 80 result[i + a_target.length] = readCommand; 81 } 82 return result; 83 } 84 85 public static CommandGene[] createStackCommands(CommandGene[] a_target, 86 GPConfiguration a_conf, 87 Class a_type) 88 throws InvalidConfigurationException { 89 CommandGene[] result = new CommandGene[a_target.length + 2]; 90 for (int i = 0; i < a_target.length; i++) { 91 result[i] = a_target[i]; 92 } 93 result[a_target.length] = new Push(a_conf, a_type); 94 result[a_target.length + 1] = new Pop(a_conf, a_type); 95 return result; 96 } 97 } 98 | Popular Tags |