NSGAII - Configuring and Running

From jecoliwiki
Jump to: navigation, search

Non-Dominated Sorting Genetic Algorithm II



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)

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);

* 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

* Setting the population
int populationSize = 100;

* Defining the termination criteria - in this example, the number of iterations
int numberGenerations = 1000;
ITerminationCriteria terminationCriteria;
terminationCriteria = new IterationTerminationCriteria(numberGenerations);
* Setting the recombination parameters
* RecombinationParameters(num survivors, offspring size, elitism value, multiple offspring) 
RecombinationParameters recombinationParameters = new RecombinationParameters(0,populationSize,0,true);
* 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());

StatisticsConfiguration stats = new StatisticsConfiguration();
StatisticTypeMask mask = new StatisticTypeMask();

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