Skip to content

Multiple objectives

Many problems have several goals that pull against each other, such as cost and quality. One solution dominates another (Pareto dominance) when it is at least as good in every objective and better in at least one. The solutions that no other solution dominates form the Pareto front: the best trade-offs, where improving one objective makes another worse. A multi-objective run returns an approximation of that front instead of a single best solution.

Defining the problem

Give the number of objectives with n_obj, or one sense per objective with sense=["min", "max"] (n_obj then follows from the list). With n_obj=m and a single sense, that sense applies to all objectives.

The objective returns a list or array with one value per objective. Do not return a tuple, because a tuple means (f, g) or (f, g, h) with constraints. The example below minimizes two objectives of five real variables in [0, 1] and uses Random Search as a quick baseline:

import numpy as np
import ypea


def zdt1_like(sol):
    x = sol.x
    g = 1 + 9 * np.mean(x[1:])
    return [x[0], g * (1 - np.sqrt(x[0] / g))]


problem = ypea.Problem(
    ypea.Real("x", shape=5, lb=0, ub=1),
    zdt1_like,
    n_obj=2,
    name="zdt1_like",
)
result = ypea.RandomSearch(max_nfe=5_000).solve(problem, seed=1)
print(result.summary())
RS on zdt1_like
  front: 19 solutions, 19 feasible
  objective ranges: [1.13392e-05, 0.910699], [0.428198, 6.46732]
  evaluations: 5000, iterations: 49, time: 0.0389 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own random numbers, so the front differs from Python's.

problem = ypea.Problem( ...
    vars=ypea.Real("x", shape=5, lb=0, ub=1), ...
    objective=@zdt1_like, ...
    n_obj=2, ...
    name="zdt1_like");
result = ypea.RandomSearch(max_nfe=5000).solve(problem, seed=1);
disp(result.summary())

function f = zdt1_like(sol)
x = sol.x;
g = 1 + 9 * mean(x(2:end));
f = [x(1), g * (1 - sqrt(x(1) / g))];
end
RS on zdt1_like
  front: 22 solutions, 22 feasible
  objective ranges: [4.71292e-05, 0.840833], [0.592926, 5.06194]
  evaluations: 5000, iterations: 49, time: 0.325 s, stopped by: max_nfe

The summary shows the size of the front and the range of each objective over it. An evaluation is one call of the objective function, and max_nfe is the budget of evaluations.

Constraints work as with one objective: return (f, g) or (f, g, h), where f is the list of objective values (see Objectives and constraints). A vectorized objective returns f with shape (n, m).

Algorithms

NSGAII, NSGAIII, MOEAD, MOPSO and SPEA2 solve only problems with several objectives. RandomSearch solves both kinds, which makes it a baseline. The other algorithms raise an error on a problem with several objectives.

To use a single-objective algorithm anyway, turn the problem into one objective with ypea.scalarize. The weighted sum minimizes sum(w_i * f_i) and reaches only the convex parts of a front. Tchebycheff minimizes max(w_i * |f_i - z_i|), where z is an ideal point at least as good as the best value of each objective, and it can reach every point. Each weight vector gives one point of the front:

import numpy as np
import ypea


def zdt1_like(sol):
    x = sol.x
    g = 1 + 9 * np.mean(x[1:])
    return [x[0], g * (1 - np.sqrt(x[0] / g))]


problem = ypea.Problem(ypea.Real("x", shape=5, lb=0, ub=1), zdt1_like, n_obj=2)
single = ypea.scalarize(problem, weights=[0.5, 0.5])                      # weighted sum
tcheb = ypea.scalarize(problem, [0.5, 0.5], "tchebycheff", ideal=[0, 0])  # Tchebycheff
result = ypea.LSHADE(max_nfe=5_000).solve(tcheb, seed=1)

best = result.best.solution
values = zdt1_like(best)  # both objectives of the best solution
print(best.x.round(3), np.round(values, 3))
[0.382 0.    0.    0.    0.   ] [0.382 0.382]
problem = ypea.Problem(vars=ypea.Real("x", shape=5, lb=0, ub=1), objective=@zdt1_like, n_obj=2);
single = ypea.scalarize(problem, [0.5 0.5]);                           % weighted sum
tcheb = ypea.scalarize(problem, [0.5 0.5], "tchebycheff", ideal=[0 0]);  % Tchebycheff
result = ypea.LSHADE(max_nfe=5000).solve(tcheb, seed=1);

best = result.best.solution;
values = zdt1_like(best);  % both objectives of the best solution
disp(round(best.x, 3))
disp(round(values, 3))

function f = zdt1_like(sol)
x = sol.x;
g = 1 + 9 * mean(x(2:end));
f = [x(1), g * (1 - sqrt(x(1) / g))];
end
    0.3820         0         0         0         0

    0.3820    0.3820

With equal weights and the ideal point (0, 0), Tchebycheff finds the point of the front where both objectives are equal.

The front

The run keeps every non-dominated solution it finds, updated after every evaluation. result.front holds them, sorted by the first objective. This example prints the size of the front and the objective values of its first three members, then the first member itself:

import numpy as np
import ypea


def zdt1_like(sol):
    x = sol.x
    g = 1 + 9 * np.mean(x[1:])
    return [x[0], g * (1 - np.sqrt(x[0] / g))]


problem = ypea.Problem(ypea.Real("x", shape=5, lb=0, ub=1), zdt1_like, n_obj=2)
result = ypea.RandomSearch(max_nfe=5_000).solve(problem, seed=1)
front = result.front
print(len(front), front.obj_values[:3].round(3))
print(front[0].solution.x.round(3), front[0].obj_value.round(3), front[0].feasible)
19 [[0.    6.467]
 [0.    5.841]
 [0.    5.603]]
[0.    0.697 0.19  0.804 0.742] [0.    6.467] True

Differs from Python: front.at(i) gives one solution, where Python indexes front[i]; MATLAB draws its own random numbers.

problem = ypea.Problem(vars=ypea.Real("x", shape=5, lb=0, ub=1), objective=@zdt1_like, n_obj=2);
result = ypea.RandomSearch(max_nfe=5000).solve(problem, seed=1);
front = result.front;
disp(length(front))
disp(round(front.obj_values(1:3, :), 3))
first = front.at(1);
disp(round(first.solution.x, 3))
disp(round(first.obj_value, 3))
disp(first.feasible)

function f = zdt1_like(sol)
x = sol.x;
g = 1 + 9 * mean(x(2:end));
f = [x(1), g * (1 - sqrt(x(1) / g))];
end
    22

         0    5.0620
         0    4.4700
    0.0010    3.3660

         0    0.3340    0.4160    0.9980    0.0630

         0    5.0620

   1
Field Shape Meaning
positions (k, code_size) the codes, the internal form of each solution with every entry in [0, 1]
obj_values (k, m) the objective values
violations (k,) the total constraint violations
solutions k the decoded solutions
feasible (k,) True for each feasible solution

front[i] is an Individual whose obj_value is an array. result.best, result.best_feasible and result.error are None, because no single solution is best.

The front uses constrained domination (Deb et al. 2002), whatever the problem's constraints setting. Once a feasible solution exists, the front holds only feasible solutions that no other member dominates. Before that, it holds the least violating solutions, and among equal violations the non-dominated ones. Duplicates do not enter. With constraints="penalty", the algorithms themselves compare solutions by Pareto dominance of the penalized objective values.

The front grows without limit by default. Multi-objective algorithms take max_archive, for example ypea.NSGAII(max_archive=100). After each batch of evaluations, the most crowded members (smallest crowding distance) are removed one at a time until the front fits. The extreme solutions of each objective always stay.

Front found by NSGA-II on ZDT1
The front of NSGA-II with default settings on ZDT1 (30 variables) after 20 000 evaluations, with the true front as a dashed line.

History and trace

result.history has one entry per iteration with archive_size (the size of the front) and best_violation (the smallest violation in it). best_obj_value is NaN.

The trace has one entry per solution that entered the front: trace_nfe (the evaluation that found it), trace_obj_value (shape (entries, m)), trace_violation, and trace_removed_nfe (the evaluation that pushed it out, or -1 if it is still in). history.front_at(nfe) returns the objective values of the front after nfe evaluations, so you can rebuild the front at any budget, for example to compute an indicator over the run. history.front_mask(nfe) gives the matching trace entries as a boolean mask, for example for trace_violation.

import numpy as np
import ypea


def zdt1_like(sol):
    x = sol.x
    g = 1 + 9 * np.mean(x[1:])
    return [x[0], g * (1 - np.sqrt(x[0] / g))]


problem = ypea.Problem(ypea.Real("x", shape=5, lb=0, ub=1), zdt1_like, n_obj=2)
result = ypea.RandomSearch(max_nfe=5_000).solve(problem, seed=1)
for nfe in (100, 1_000, 5_000):
    front = result.history.front_at(nfe)
    print(nfe, len(front), front.min(axis=0).round(3))
100 6 [0.024 1.103]
1000 8 [0.    0.727]
5000 19 [0.    0.428]

Differs from Python: MATLAB draws its own random numbers, so the fronts differ from Python's.

problem = ypea.Problem(vars=ypea.Real("x", shape=5, lb=0, ub=1), objective=@zdt1_like, n_obj=2);
result = ypea.RandomSearch(max_nfe=5000).solve(problem, seed=1);
checkpoints = [100, 1000, 5000];
for nfe = checkpoints
    front = result.history.front_at(nfe);
    fprintf("%d %d %s\n", nfe, size(front, 1), mat2str(round(min(front, [], 1), 3)));
end

function f = zdt1_like(sol)
x = sol.x;
g = 1 + 9 * mean(x(2:end));
f = [x(1), g * (1 - sqrt(x(1) / g))];
end
100 6 [0 1.149]
1000 16 [0 0.69]
5000 22 [0 0.593]

Each line shows the budget, the size of the front at that point, and the best value of each objective in it.

Ask and tell and experiments work with several objectives too: tell takes one list or array of objective values per solution, and experiments report IGD and hypervolume with the same statistical tests. The ZDT, DTLZ and WFG test problems, their true fronts, quality indicators and front plots are on Multi-objective benchmarks.

Operators for multi-objective algorithms

An operator creates new solutions from existing ones: crossover mixes two parents, and mutation changes one. The multi-objective genetic algorithms use simulated binary crossover (SBX) and polynomial mutation (Deb et al. 2002) by default, SBX and PolynomialMutation in ypea.operators. They work on the [0, 1] codes, so they apply to every variable type. crossover= and mutation= take other operators (see Operators as settings), and with space="native" non-real variables get operators made for their type (see Several objectives).

Distributions of SBX children and mutants
Where the children of SBX (left) and the mutants of polynomial mutation (right) land, with the operator applied on every draw: 20 000 parent pairs give 40 000 SBX children, and 20 000 mutations of 0.3. A larger eta (solid) keeps them closer to the parents.