1 10 package examples.grid.evolutionDistributed; 11 12 import org.homedns.dade.jcgrid.client.*; 13 import org.jgap.*; 14 import org.jgap.distr.grid.*; 15 16 22 public class ClientEvolveStrategy 23 implements IClientEvolveStrategy { 24 25 public final static String CVS_REVISION = "$Revision: 1.1 $"; 26 27 private Configuration m_config; 28 29 private IClientFeedback m_clientFeedback; 30 31 private final int m_maxEvolutions = 3; 32 33 private Population m_pop; 34 35 47 public void initialize(GridClient a_gc, Configuration a_config, 48 IClientFeedback a_clientFeedback) 49 throws Exception { 50 m_clientFeedback = a_clientFeedback; 51 m_config = a_config; 52 m_pop = new Population(m_config); 55 } 56 57 public void afterWorkRequestsSent() 58 throws Exception { 59 m_pop.clear(); 63 } 64 65 public boolean isEvolutionFinished(int a_evolutionsDone) { 66 IChromosome fittest = m_pop.determineFittestChromosome(); 69 if (fittest.getFitnessValue() > 50000) { 70 return true; 71 } 72 if (a_evolutionsDone > m_maxEvolutions) { 75 return true; 76 } 77 else { 78 return false; 79 } 80 } 81 82 85 public void onFinished() { 86 IChromosome best = m_pop.determineFittestChromosome(); 87 m_clientFeedback.info("Best solution evolved: " + best); 88 } 89 90 public void evolve() 91 throws Exception { 92 } 96 97 public JGAPRequest[] generateWorkRequests(JGAPRequest m_workReq, 98 IRequestSplitStrategy m_splitStrategy, Object data) 99 throws Exception { 100 JGAPRequest[] workList; 101 m_workReq.setPopulation(m_pop); 102 m_workReq.setConfiguration(m_config); 103 workList = m_splitStrategy.split(m_workReq); 104 return workList; 105 } 106 107 113 public void resultReceived(JGAPResult a_result) 114 throws Exception { 115 m_pop.addChromosomes(a_result.getPopulation()); 116 } 117 } 118 | Popular Tags |