Jecoliwiki:CAGA - configuring and Running the Algorithm

From jecoliwiki
Jump to: navigation, search


Contents


Configuration

Initially, a specific configuration object has to be created. In this case a CellularGeneticAlgorithmConfiguration object. This object has the methods defined in the IConfiguration interface plus the following set of primitives, T stands for the representation defined and S represents the specific factory that extends the solution factory interface (ISolutionFactory<T>):

int getPopulationSize():
NeighborhoodType getNeighborhoodType():
ISolutionSet<T> getInitialPopulation():
void setInitialPopulation(ISolutionSet<T> initialPopulation):
CellularAutomataType getCellularAutomataType():
int getRadius():
ISelectionOperator<T> getSelectionOperator():
IReproductionOperator<T,S> selectReproductionOperator():
IOperatorContainer<IReproductionOperator> getReproductionOperatorContainer():
void setReproductionOperatorContainer(IOperatorContainer<IReproductionOperator<T,S>> reproductionOperatorContainer):
boolean isDoPopulationInitialization():
void setDoPopulationInitialization(boolean doPopulationInitialization):
boolean isFixedPopulationSize():
void setFixedPopulationSize(boolean fixedPopulationSize):

List<Integer> getSolutionIndexList():
int getWidth():
int getHeight():
void setRadius(int radius):
void setSolutionFactory(S solutionFactory):
void setNeighborhoodType(NeighborhoodType neighborhoodType):
void setCellularAutomataType(CellularAutomataType cellularAutomataType):
void setSelectionOperator(ISelectionOperator<T> selectionOperator):
void setWidth(int width):
void setHeight(int height):

In the following box is the code to create a Cellular Genetic Configuration Object.

CellularGeneticAlgorithmConfiguration<ILinearRepresentation<Boolean>,BinaryRepresentationFactory> configuration = 
      new  CellularGeneticAlgorithmConfiguration<ILinearRepresentation<Boolean>,BinaryRepresentationFactory>();
			
IEvaluationFunction<ILinearRepresentation<Boolean>> evaluationFunction = new CountOnesEvaluationFunction();
configuration.setEvaluationFunction(evaluationFunction);
			
int solutionSize = 1000;
BinaryRepresentationFactory solutionFactory = new BinaryRepresentationFactory(solutionSize);
configuration.setSolutionFactory(solutionFactory);
			
int numberGenerations = 250;
ITerminationCriteria terminationCriteria = new IterationTerminationCriteria(numberGenerations);
configuration.setTerminationCriteria(terminationCriteria);
			
configuration.setCellularAutomataType(CellularAutomataType.SYNCHRONOUS);
configuration.setNeighborhoodType(NeighborhoodType.NEWS);
configuration.setWidth(20);
configuration.setHeight(20);
configuration.setRadius(1);
			
configuration.setRandomNumberGenerator(new DefaultRandomNumberGenerator());
configuration.setProblemBaseDirectory("nullDirectory");
configuration.setAlgorithmStateFile("nullFile");
configuration.setSaveAlgorithmStateDirectoryPath("nullDirectory");
configuration.setPopulationSize(1000);
configuration.setAlgorithmResultWriterList(new ArrayList<IAlgorithmResultWriter<ILinearRepresentation<Boolean>>>());
configuration.setStatisticsConfiguration(new StatisticsConfiguration());
			
configuration.setSelectionOperator(new TournamentSelection<ILinearRepresentation<Boolean>>(1,2));
			
ReproductionOperatorContainer operatorContainer = new ReproductionOperatorContainer();
operatorContainer.addOperator(0.5,new UniformCrossover<Boolean>());
operatorContainer.addOperator(0.5,new BitFlipMutation(2));	
configuration.setReproductionOperatorContainer(operatorContainer);

Executing the Algorithm

As previously stated, the specific algorithm should be instantiated and the method run executed.

 IAlgorithm<ILinearRepresentation<Boolean>> algorithm = 
       new CellularGeneticAlgorithm<ILinearRepresentation<Boolean>,BinaryRepresentationFactory>(configuration);
 IAlgorithmResult<ILinearRepresentation<Boolean>> result = algorithm.run();
Personal tools