Class BaseNSGAII<S extends org.uma.jmetal.solution.Solution<?>>
- Type Parameters:
S- the type of solutions handled by this algorithm, must extendSolution
- All Implemented Interfaces:
BaseLevelAlgorithm<S>
- Direct Known Subclasses:
BinaryNSGAII,DoubleNSGAII,PermutationNSGAII
This class provides a flexible and extensible foundation for building NSGA-II variants for different solution types. It manages the configuration and assembly of the main algorithmic components (selection, variation, replacement, evaluation, termination, etc.) using a parameter space abstraction. NSGA-II is a fast and elitist multi-objective genetic algorithm that uses a non-dominated sorting approach with crowding distance for maintaining diversity.
Key features of this implementation include:
- Fast non-dominated sorting for ranking solutions
- Crowding distance calculation for diversity preservation
- Configurable selection, crossover, and mutation operators
- Support for external archives
- Flexible termination conditions
Subclasses must implement the setNonConfigurableParameters() method to set any
parameters that are fixed or derived from the problem instance.
Typical usage involves:
- Creating a concrete subclass for a specific solution type (e.g., permutation, double)
- Configuring the parameter space and problem instance
- Calling
build()to obtain a ready-to-runEvolutionaryAlgorithminstance
Example usage:
// Create a problem instance
Problem<MySolution> problem = new MyProblem();
// Configure the algorithm
int populationSize = 100;
int maxEvaluations = 25000;
ParameterSpace parameterSpace = new ParameterSpace();
// Configure parameter space with desired components and parameters
// Create and run the algorithm
BaseNSGAII<MySolution> nsgaii = new MyNSGAII(problem, populationSize, maxEvaluations, parameterSpace);
nsgaii.run();
// Get results
List<MySolution> population = nsgaii.result();
- Since:
- version
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.uma.jmetal.util.densityestimator.DensityEstimator<S> The density estimator used for maintaining diversity in the population.protected org.uma.jmetal.util.archive.Archive<S> Optional external archive for storing non-dominated solutions.protected intThe maximum number of evaluations allowed for the algorithm.protected intThe size of the offspring population generated in each generation.protected final ParameterSpaceThe parameter space containing all configurable components and parameters.protected intThe size of the population.protected org.uma.jmetal.problem.Problem<S> The optimization problem to be solved.protected org.uma.jmetal.util.ranking.Ranking<S> The ranking strategy used for non-dominated sorting of solutions.protected org.uma.jmetal.util.comparator.MultiComparator<S> Comparator that combines ranking and crowding distance for solution comparison. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBaseNSGAII(int populationSize, ParameterSpace parameterSpace) Constructs a new BaseNSGAII instance with the specified population size and parameter space.protectedBaseNSGAII(org.uma.jmetal.problem.Problem<S> problem, int populationSize, int maximumNumberOfEvaluations, ParameterSpace parameterSpace) Constructs a fully configured BaseNSGAII instance ready for execution. -
Method Summary
Modifier and TypeMethodDescriptionorg.uma.jmetal.component.algorithm.EvolutionaryAlgorithm<S> build()Builds and configures the NSGA-II algorithm based on the current parameter space.protected org.uma.jmetal.component.catalogue.common.evaluation.Evaluation<S> createEvaluation(org.uma.jmetal.util.archive.Archive<S> archive) Creates the evaluation component for the algorithm.protected org.uma.jmetal.util.archive.Archive<S> Creates and configures the external archive if required by the parameter space.protected org.uma.jmetal.component.catalogue.common.solutionscreation.SolutionsCreation<S> Creates the initial solutions creation strategy using the configured parameter.protected org.uma.jmetal.component.catalogue.ea.replacement.Replacement<S> Creates the replacement operator for the algorithm using ranking and density estimators.protected org.uma.jmetal.component.catalogue.ea.selection.Selection<S> createSelection(org.uma.jmetal.component.catalogue.ea.variation.Variation<S> variation) Creates the selection operator for the algorithm using the configured selection parameter.protected org.uma.jmetal.component.catalogue.common.termination.TerminationCreates the termination condition for the algorithm.protected org.uma.jmetal.component.catalogue.ea.variation.Variation<S> Creates the variation operator for the algorithm using the configured variation parameter.Returns the parameter space used by this algorithm.protected abstract voidConfigures any parameters that are fixed or derived from the problem instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.uma.evolver.algorithm.base.BaseLevelAlgorithm
createInstance, parse
-
Field Details
-
parameterSpace
The parameter space containing all configurable components and parameters. -
ranking
protected org.uma.jmetal.util.ranking.Ranking<S extends org.uma.jmetal.solution.Solution<?>> rankingThe ranking strategy used for non-dominated sorting of solutions. -
densityEstimator
protected org.uma.jmetal.util.densityestimator.DensityEstimator<S extends org.uma.jmetal.solution.Solution<?>> densityEstimatorThe density estimator used for maintaining diversity in the population. -
rankingAndCrowdingComparator
protected org.uma.jmetal.util.comparator.MultiComparator<S extends org.uma.jmetal.solution.Solution<?>> rankingAndCrowdingComparatorComparator that combines ranking and crowding distance for solution comparison. -
problem
The optimization problem to be solved. -
populationSize
protected int populationSizeThe size of the population. -
offspringPopulationSize
protected int offspringPopulationSizeThe size of the offspring population generated in each generation. -
maximumNumberOfEvaluations
protected int maximumNumberOfEvaluationsThe maximum number of evaluations allowed for the algorithm. -
externalArchive
protected org.uma.jmetal.util.archive.Archive<S extends org.uma.jmetal.solution.Solution<?>> externalArchiveOptional external archive for storing non-dominated solutions.
-
-
Constructor Details
-
BaseNSGAII
Constructs a new BaseNSGAII instance with the specified population size and parameter space.This creates a partially configured instance. The
BaseLevelAlgorithm.createInstance(Problem, int)method must be called with a problem instance before the algorithm can be used.- Parameters:
populationSize- the size of the population to be used in the algorithm. Must be positive.parameterSpace- the parameter space containing configuration parameters for the algorithm. Must not be null.- Throws:
IllegalArgumentException- if populationSize is not positive or parameterSpace is null
-
BaseNSGAII
protected BaseNSGAII(org.uma.jmetal.problem.Problem<S> problem, int populationSize, int maximumNumberOfEvaluations, ParameterSpace parameterSpace) Constructs a fully configured BaseNSGAII instance ready for execution.- Parameters:
problem- the optimization problem to be solved. Must not be null.populationSize- the size of the population. Must be positive.maximumNumberOfEvaluations- the maximum number of evaluations allowed for the algorithm. Must be positive and greater than populationSize.parameterSpace- the parameter space containing configuration parameters for the algorithm. Must not be null.- Throws:
IllegalArgumentException- if any parameter is invalid (null or non-positive values where required)
-
-
Method Details
-
parameterSpace
Returns the parameter space used by this algorithm.- Specified by:
parameterSpacein interfaceBaseLevelAlgorithm<S extends org.uma.jmetal.solution.Solution<?>>- Returns:
- the parameter space containing all configurable components and parameters
-
build
Builds and configures the NSGA-II algorithm based on the current parameter space.This method initializes all necessary components for the NSGA-II algorithm, including:
- Ranking and density estimation strategies
- Population initialization
- Selection, crossover, and mutation operators
- Termination condition
- Optional external archive
- Specified by:
buildin interfaceBaseLevelAlgorithm<S extends org.uma.jmetal.solution.Solution<?>>- Returns:
- a fully configured EvolutionaryAlgorithm instance implementing NSGA-II
- Throws:
IllegalStateException- if required parameters are not properly configured
-
setNonConfigurableParameters
protected abstract void setNonConfigurableParameters()Configures any parameters that are fixed or derived from the problem instance.Subclasses must implement this method to set non-configurable parameters before building the algorithm. If there are not non-configurable parameters, the implementation of this method will be empty.
-
createExternalArchive
Creates and configures the external archive if required by the parameter space. The archive size is set according to the current population size.- Returns:
- the configured external archive, or
nullif not used
-
createTermination
protected org.uma.jmetal.component.catalogue.common.termination.Termination createTermination()Creates the termination condition for the algorithm. By default, termination is based on the maximum number of evaluations.- Returns:
- the termination condition
-
createEvaluation
protected org.uma.jmetal.component.catalogue.common.evaluation.Evaluation<S> createEvaluation(org.uma.jmetal.util.archive.Archive<S> archive) Creates the evaluation component for the algorithm. If an external archive is used, a sequential evaluation with archive is created; otherwise, a standard sequential evaluation is used.- Parameters:
archive- the external archive, ornullif not used- Returns:
- the evaluation component
-
createSelection
protected org.uma.jmetal.component.catalogue.ea.selection.Selection<S> createSelection(org.uma.jmetal.component.catalogue.ea.variation.Variation<S> variation) Creates the selection operator for the algorithm using the configured selection parameter. The mating pool size is obtained from the variation operator.- Parameters:
variation- the variation operator- Returns:
- the selection operator
-
createVariation
Creates the variation operator for the algorithm using the configured variation parameter. Sets the offspring population size as a non-configurable sub-parameter.- Returns:
- the variation operator
-
createInitialSolutions
protected org.uma.jmetal.component.catalogue.common.solutionscreation.SolutionsCreation<S> createInitialSolutions()Creates the initial solutions creation strategy using the configured parameter.- Returns:
- the solutions creation strategy
-
createReplacement
Creates the replacement operator for the algorithm using ranking and density estimators.- Returns:
- the replacement operator
-