1 10 package examples.grid.evolutionDistributed; 11 12 import org.jgap.*; 13 import org.jgap.distr.grid.*; 14 15 22 public class MyRequestSplitStrategy 23 implements IRequestSplitStrategy { 24 25 private final static String CVS_REVISION = "$Revision: 1.1 $"; 26 27 private Configuration m_config; 28 29 public MyRequestSplitStrategy(Configuration a_config) { 30 m_config = a_config; 31 } 32 33 public Configuration getConfiguration() { 34 return m_config; 35 } 36 37 49 public JGAPRequest[] split(JGAPRequest a_request) 50 throws Exception { 51 Population pop = a_request.getPopulation(); 52 boolean firstTime; 55 if (pop == null || pop.size() < 1) { 56 firstTime = true; 57 } 58 else { 59 firstTime = false; 60 } 61 if (!firstTime) { 62 pop.sortByFitness(); 65 } 66 int requests = 20; JGAPRequest[] result = new JGAPRequest[requests]; 70 int count = getConfiguration().getPopulationSize() / 10; 73 for (int j = 0; j < requests; j++) { 74 result[j] = (JGAPRequest) a_request.newInstance("Population " + j, j); 75 Configuration config = getConfiguration().newInstance(j + "", 78 "population " + j); 79 RandomGenerator rand = getConfiguration().getRandomGenerator(); 82 Population workPop = new Population(config, count); 83 if (!firstTime) { 84 for (int i = 0; i < count; i++) { 85 IChromosome chrom; 86 if (rand.nextDouble() > 0.2d) { 87 chrom = pop.getChromosome(i); 90 } 91 else { 92 chrom = pop.getChromosome(i + count); 95 } 96 workPop.addChromosome(chrom); 97 } 98 } 99 result[j].setPopulation(workPop); 100 } 101 return result; 102 } 103 } 104 | Popular Tags |