Difference between revisions of "NSGAII - Configuring and Running"

From jecoliwiki
Jump to: navigation, search
(Created page with "Category:Howtos '''Non-Dominated Sorting Genetic Algorithm II''' __TOC__ == Configuration == The main steps involved in the configuration are: * the evaluation functi...")
 

Latest revision as of 16:29, 5 March 2013


Non-Dominated Sorting Genetic Algorithm II

Contents


[edit] Configuration

The main steps involved in the configuration are:

  • the evaluation function to use
  • the solution factory to create new solutions
  • the population size
  • the termination criteria of the algorithm (e.g. the number of iterations)
  • the selection operator
  • the reproduction operators (at least one crossover and one mutation)


[edit] An Example configuration (for the Counting Ones problem)

/**
* Creating the configuration object
*/
NSGAIIConfiguration<ILinearRepresentation<Boolean>,BinaryRepresentationFactory> configuration = new NSGAIIConfiguration<ILinearRepresentation<Boolean>,BinaryRepresentationFactory>();
 			
/**
* The Evaluation Function - notice that true or false must be supplied
* as an argument for maximization or minimization respectively
*/
 IEvaluationFunction<ILinearRepresentation<Boolean>> evaluationFunction = new CountOnesMOEvaluationFunction<ILinearRepresentation<Boolean>>(true);
configuration.setEvaluationFunction(evaluationFunction);

/**
* The size of the solutions to generate and the definition of the solution factory
*/
int solutionSize = 100;
 BinaryRepresentationFactory solutionFactory = new BinaryRepresentationFactory(solutionSize,2); // binary representation, two objectives
configuration.setSolutionFactory(solutionFactory);

/**
* Setting the population
*/
int populationSize = 100;
configuration.setInitialPopulationSize(populationSize);

/**
* Defining the termination criteria - in this example, the number of iterations
*/ 
int numberGenerations = 1000;
ITerminationCriteria terminationCriteria;
terminationCriteria = new IterationTerminationCriteria(numberGenerations);
configuration.setTerminationCriteria(terminationCriteria);
			
/**
* Setting the recombination parameters
* RecombinationParameters(num survivors, offspring size, elitism value, multiple offspring) 
*/
RecombinationParameters recombinationParameters = new RecombinationParameters(0,populationSize,0,true);
configuration.setRecombinationParameters(recombinationParameters);
			
/**
* The selection operator - The TournamentSelection2 is recommended to implement the correct NSGAII algorithm
*/
 configuration.setSelectionOperator(new TournamentSelection2<ILinearRepresentation<Boolean>>(1,2,randomNumberGenerator));


/**
* The reproduction operators - note that the probabilities for the operators in a container must sum 1
*/
 ReproductionOperatorContainer reproductionOperatorContainer = new ReproductionOperatorContainer(); 

/** the traditional one point crossover - will always be used, since NSGAII uses serial recombination (crossover+mutation)
 reproductionOperatorContainer.addOperator(0.5,new OnePointCrossover<Boolean>());

/** the bit-flip mutation - this is parameterised with the Representation used (Binary in this case)
 reproductionOperatorContainer.addOperator(0.5,new BitFlipMutation());

configuration.setReproductionOperatorContainer(reproductionOperatorContainer);
	
StatisticsConfiguration stats = new StatisticsConfiguration();
StatisticTypeMask mask = new StatisticTypeMask();
mask.setMaxFitnessValue(false);
mask.setMeanFitnessValue(false);
mask.setMinFitnessValue(false);
mask.setStdDevValue(false);
stats.setScreenStatisticsMask(mask);
configuration.setStatisticsConfiguration(stats); 

[edit] Running the Algorithm

To run the algorithm it suffices to instantiate the algorithm with the correct configuration object as a parameter and then invoke the method run().

See the example bellow (relative to the above configuration example)


/** instantiation of the algorithm */
 IAlgorithm<ILinearRepresentation<Boolean>> algorithm = new NSGAII<ILinearRepresentation<Boolean>,BinaryRepresentationFactory>(configuration);

/** running the algorithm and getting the results */
 IAlgorithmResult<ILinearRepresentation<Boolean>> result =  algorithm.run();
Personal tools