Skip to content

Non-dominated Sorting Genetic Algorithm II ​

Multi-Objective

Non-dominated Sorting Genetic Algorithm II (NSGA-II) multi-objective optimizer.

Algorithm Overview ​

This module implements the NSGA-II algorithm, one of the most popular and highly-cited multi-objective evolutionary optimization algorithms.

NSGA-II uses fast non-dominated sorting and crowding distance assignment to maintain a well-spread Pareto-optimal front while efficiently converging to the true Pareto front.

Usage ​

python
from opt.multi_objective.nsga_ii import NSGAII
from opt.benchmark.functions import sphere

optimizer = NSGAII(
    func=sphere,
    lower_bound=-5.12,
    upper_bound=5.12,
    dim=10,
    max_iter=500,
    population_size=50,
)

best_solution, best_fitness = optimizer.search()
print(f"Best solution: {best_solution}")
print(f"Best fitness: {best_fitness:.6e}")

Parameters ​

ParameterTypeDefaultDescription
objectivesSequence[Callable]RequiredList of objective functions to minimize.
lower_boundfloatRequiredLower bound of search space.
upper_boundfloatRequiredUpper bound of search space.
dimintRequiredProblem dimensionality.
max_iterint200Maximum number of generations.
seedint | NoneNone**REQUIRED for BBOB compliance.
population_sizeint100Number of individuals in population.
crossover_probfloat_CROSSOVER_PROBABILITYSBX crossover probability.
mutation_probfloat | NoneNonePolynomial mutation probability per dimension.
tournament_sizeint_TOURNAMENT_SIZEBinary tournament selection size.
eta_cfloat_SBX_DISTRIBUTION_INDEXSBX distribution index.
eta_mfloat_POLYNOMIAL_MUTATION_INDEXPolynomial mutation distribution index.

Algorithm Metadata ​

PropertyValue
Algorithm NameNon-dominated Sorting Genetic Algorithm II
AcronymNSGA-II
Year Introduced2002
AuthorsDeb, Kalyanmoy; Pratap, Amrit; Agarwal, Sameer; Meyarivan, T
Algorithm ClassMulti-Objective
ComplexityO(mNΒ²) per generation
PropertiesPopulation-based, Derivative-free
ImplementationPython 3.10+
COCO CompatibleYes

Mathematical Formulation ​

Pareto Dominance: Solution x1 dominates x2 if:

βˆ€i:fi(x1)≀fi(x2)βˆ§βˆƒj:fj(x1)<fj(x2)

Non-dominated Sorting: Population sorted into fronts F1,F2,...,Fk where F1 contains non-dominated solutions (Pareto front).

Crowding Distance: For solution i in front F , on objective m :

dim=fmi+1βˆ’fmiβˆ’1fmmaxβˆ’fmmin

Total crowding distance: di=βˆ‘m=1Mdim

Selection: Binary tournament based on:

  1. Pareto rank (lower is better)
  2. Crowding distance (higher is better for diversity)

Constraint handling:

  • Boundary conditions: Clamping to bounds after crossover/mutation
  • Feasibility enforcement: SBX and polynomial mutation respect bounds

Hyperparameters ​

ParameterDefaultBBOB RecommendedDescription
population_size10010*dimNumber of individuals
max_iter20010000Maximum generations
crossover_prob0.90.9SBX crossover probability
mutation_prob1/dim1/dimPolynomial mutation probability
tournament_size22Binary tournament size
eta_c2015-30SBX distribution index
eta_m2015-30Mutation distribution index

Sensitivity Analysis:

  • eta_c, eta_m: Medium impact - controls offspring spread
  • population_size: High impact - larger populations improve diversity
  • Recommended tuning ranges: eta∈[10,30] , pop∈[50,200]

COCO/BBOB Benchmark Settings ​

Search Space:

  • Dimensions tested: 2, 3, 5, 10, 20, 40
  • Bounds: Function-specific (typically [0, 1] for ZDT, [-5, 5] for DTLZ)
  • Instances: 15 per function (BBOB multi-objective standard)

Evaluation Budget:

  • Budget: dimΓ—10000 function evaluations
  • Independent runs: 15 (for statistical significance)
  • Seeds: 0-14 (reproducibility requirement)

Performance Metrics (Multi-Objective):

  • Hypervolume (HV): Volume dominated by Pareto front
  • Inverted Generational Distance (IGD): Distance to reference front
  • Spread: Distribution uniformity metric
  • Epsilon Indicator: Convergence quality measure

Raises ​

ValueError: If search space is invalid or function evaluation fails.

Notes ​

  • Returns first Pareto front (rank 0) solutions
  • Uses self.seed for all random number generation
  • BBOB: Returns Pareto front after max_iter generations

Computational Complexity:

  • Time per generation: O(mN2) where m = objectives, N = population
  • Space complexity: O(mN) for population and fitness storage
  • BBOB budget usage: Typically 60-80% of dim*10000 budget for convergence

BBOB Performance Characteristics (Multi-Objective):

  • Best function classes: Separable, low-dimensional (2-3 objectives)
  • Weak function classes: Many-objective (>3), highly multimodal
  • Typical Hypervolume: 85-95% of reference front (bi-objective, dim=5)
  • IGD competitive with MOEA/D on ZDT/DTLZ benchmarks

Convergence Properties:

  • Convergence rate: Typically linear to Pareto front
  • Diversity: Excellent via crowding distance mechanism
  • Premature convergence risk: Low due to elitism and diversity preservation

Reproducibility:

  • Deterministic: Yes - Same seed guarantees identical Pareto fronts
  • BBOB compliance: seed parameter required for 15 independent runs
  • Initialization: Uniform random sampling in [lower_bound, upper_bound]
  • RNG usage: numpy.random.default_rng(self.seed) throughout

Pareto Front Characteristics:

  • Non-dominated sorting: Fast O(mNΒ²) algorithm ensures accurate ranking
  • Crowding distance: Maintains well-spread solutions along Pareto front
  • Elitism: Combines parent and offspring, selects best N individuals
  • Diversity maintenance: Boundary solutions get infinite crowding distance

Implementation Details:

  • Parallelization: Not supported (sequential evaluation)
  • Constraint handling: Clamping to bounds after SBX/polynomial mutation
  • Numerical stability: Uses epsilon (1e-14) to prevent division by zero

Known Limitations:

  • Performance degrades with >3 objectives (many-objective problems)
  • Crowding distance less effective in high-dimensional objective spaces
  • BBOB known issues: May struggle with disconnected Pareto fronts

Version History:

  • v0.1.0: Initial implementation with BBOB multi-objective compliance

References ​

[1] Deb, K., Pratap, A., Agarwal, S., & Meyarivan, T. (2002). "A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II." IEEE Transactions on Evolutionary Computation, 6(2), 182-197. https://doi.org/10.1109/4235.996017

[2] Hansen, N., Auger, A., Ros, R., Mersmann, O., TuΕ‘ar, T., Brockhoff, D. (2021). "COCO: A platform for comparing continuous optimizers in a black-box setting." Optimization Methods and Software, 36(1), 114-144. https://doi.org/10.1080/10556788.2020.1808977

COCO Data Archive:

Implementation:

  • Original NSGA-II: KanGAL Lab, IIT Kanpur
  • This implementation: Based on [1] with BBOB multi-objective compliance

See Also ​

MOEAD: Decomposition-based multi-objective algorithm BBOB Comparison: Faster on many-objective problems, NSGA-II better for 2-3 objectives with complex Pareto fronts

SPEA2: Strength Pareto Evolutionary Algorithm 2 BBOB Comparison: Similar performance, SPEA2 uses archive with density-based truncation vs NSGA-II crowding distance

AbstractMultiObjectiveOptimizer: Base class for multi-objective optimizers opt.benchmark.functions: BBOB-compatible multi-objective test functions

Related Multi-Objective Algorithms:

  • Evolutionary: MOEAD, SPEA2
  • Indicator-based: IBEA, SMS-EMOA
  • Decomposition: MOEA/D, RVEA

Benchmark Performance ​

Not covered by the benchmark suite

The benchmark suite compares single-objective optimizers on one scalar fitness. Multi-objective optimizers return a Pareto front and are not part of it.


Source Code

View the implementation: nsga_ii.py

Released under the MIT License.