evomo.algorithms.nsga2#

Classes#

NSGA2

A tensorized implementation of the Non-dominated Sorting Genetic Algorithm II (NSGA-II)

Module Contents#

class evomo.algorithms.nsga2.NSGA2(pop_size: int, n_objs: int, lb: torch.Tensor, ub: torch.Tensor, selection_op: Callable | None = None, mutation_op: Callable | None = None, crossover_op: Callable | None = None, device: torch.device | None = None)#

Bases: evox.core.Algorithm

A tensorized implementation of the Non-dominated Sorting Genetic Algorithm II (NSGA-II) for multi-objective optimization problems.

References:
[1] K. Deb, A. Pratap, S. Agarwal, and T. Meyarivan, “A fast and elitist multiobjective genetic algorithm: NSGA-II,”

IEEE Transactions on Evolutionary Computation, vol. 6, no. 2, pp. 182-197, 2002. Available: https://ieeexplore.ieee.org/document/996017

[2] Z. Liang, H. Li, N. Yu, K. Sun, and R. Cheng, “Bridging Evolutionary Multiobjective Optimization and

GPU Acceleration via Tensorization,” IEEE Transactions on Evolutionary Computation, 2025. Available: https://ieeexplore.ieee.org/document/10944658

Initialize NSGA-II with rank and crowding-distance selection.

Parameters:
  • pop_size (int) – Required. Requested number of candidate solutions. Use a positive integer; algorithm-specific minimums and reference-vector sampling are described below.

  • n_objs (int) – Required. Number of objectives, matching the second dimension of the problem’s objective tensor. Objectives are minimized; this library targets two or more objectives.

  • lb (torch.Tensor) – Required. Lower decision bounds of shape (D,), where D is the number of decision variables. Use floating-point bounds with the same shape, dtype and device as ub, and lb <= ub elementwise.

  • ub (torch.Tensor) – Required. Upper decision bounds of shape (D,). The decision dimension is inferred from the bounds, rather than passed separately. Match lb in shape, dtype and device.

  • selection_op (Callable or None) – Default: None. Mating selection callable selection_op(pop_size, keys) -> indices. keys is a list of one-dimensional sort-key tensors for crowding distance, rank and, when present, constraints. Return pop_size parent indices on the population device. None selects EvoX’s tournament_selection_multifit. This does not replace environmental selection.

  • mutation_op (Callable or None) – Default: None. Mutation callable mutation_op(offspring, lb, ub) -> mutated_offspring. Input and output are decision tensors of shape (B, D); preserve device and return an appropriate decision dtype. None selects EvoX’s polynomial_mutation.

  • crossover_op (Callable or None) – Default: None. Crossover callable crossover_op(parents) -> offspring receiving a two-dimensional decision tensor. None selects EvoX’s simulated_binary. Preserve the decision dimension and device, and produce the offspring count expected by this algorithm.

  • device (torch.device or None) – Default: None. Execution device. None uses torch.get_default_device(); it does not infer the device from the bounds. Bounds are copied to this device. Pass torch.device('cuda') explicitly for GPU execution.

Note

Use this algorithm through a workflow that connects the problem’s evaluation method. Call workflow.init_step() before workflow.step() or compiling the step. Evaluation accepts an objective tensor of shape (B, n_objs) or (fitness, constraint_violation); violations are retained in selection.

init_step()#

Perform the initialization step of the workflow.

step()#

Advance optimization and update population and fitness state in place.

Invoke through workflow.step() after initialization. The caller controls termination.

Returns:

None; results are stored in algorithm state.