moptipy.mo.problem package

Routines and tools for defining multi-objective optimization problems.

Submodules

moptipy.mo.problem.basic_mo_problem module

The base class for implementing multi-objective problems.

class moptipy.mo.problem.basic_mo_problem.BasicMOProblem(objectives, get_scalarizer=None, domination=CPUDispatcher(<function dominates>))[source]

Bases: MOProblem

The base class for implementing multi-objective optimization problems.

This class allows to construct a simple python function for scalarizing a vector of objective values in its constructor and also determines the right datatype for the objective vectors.

It therefore first obtains the type (integers or floats?) of the objective values as well as the bounds of the objective functions. This is used to determine the right numpy dtype for the objective vectors. We want to represent objective vectors as compact as possible and use an integer vector if possible.

Once this information is obtained, we invoke a call-back function get_scalarizer which should return a python function that computes the scalarization result, i.e., the single scalar value representing the vector of objective values in single-objective optimization. This function must be monotonous. If the bounds are finite, it is applied to the vector of lower and upper bounds to get the lower and upper bounds of the scalarization result.

Examples for implementing this class are class:~moptipy.mo.problem.weighted_sum.WeightedSum and Prioritize, which represent a multi-objective optimization problem either as weighted sum or by priorizing the objective value (via an internal weighted sum).

evaluate(x)[source]

Convert the multi-objective problem into a single-objective one.

This function first evaluates all encapsulated objectives and then scalarizes the result.

Parameters:

x – the candidate solution

Return type:

float | int

Returns:

the scalarized objective value

f_dimension()[source]

Obtain the number of objective functions.

Return type:

int

Returns:

the number of objective functions

f_dtype()[source]

Get the data type used in f_create.

Return type:

dtype

Returns:

the data type used by moptipy.api.mo_problem.MOProblem.f_create().

f_evaluate(x, fs)[source]

Perform the multi-objective evaluation of a solution.

Parameters:
  • x – the solution to be evaluated

  • fs (ndarray) – the array to receive the objective values

Return type:

int | float

Returns:

the scalarized objective values

initialize()[source]

Initialize the multi-objective problem.

Return type:

None

log_parameters_to(logger)[source]

Log the parameters of this function to the provided destination.

Parameters:

logger (KeyValueLogSection) – the logger for the parameters

Return type:

None

lower_bound()[source]

Get the lower bound of the scalarization result.

This function returns a theoretical limit for how good a solution could be at best. If no real limit is known, the function returns -inf.

Return type:

float | int

Returns:

the lower bound of the scalarization result

upper_bound()[source]

Get the upper bound of the scalarization result.

This function returns a theoretical limit for how bad a solution could be at worst. If no real limit is known, the function returns inf.

Return type:

float | int

Returns:

the upper bound of the scalarization result

validate(x)[source]

Validate an objective vector.

Parameters:

x (ndarray) – the objective vector

Raises:
  • TypeError – if the string is not an element of this space.

  • ValueError – if the shape of the vector is wrong or any of its element is not finite.

Return type:

None

moptipy.mo.problem.weighted_sum module

The weighted sum scalarization of multi-objective problems.

Here we provide two simple methods to scalarize multi-objective problems by using weights, namely

  • WeightedSum, a sum with arbitrary, user-defined weights of the objective values

  • Prioritize, a weighted sum of the objective values where the weights are automatically determined such that the first objective function is prioritized over the second one, the second one over the third, and so on.

class moptipy.mo.problem.weighted_sum.BasicWeightedSum(objectives, get_scalarizer, domination=CPUDispatcher(<function dominates>))[source]

Bases: BasicMOProblem

Base class for scalarizing objective values by a weighted sum.

This class brings the basic tools to scalarize vectors of objective values by computing weighted sums. This class should not be used directly. Instead, use its sub-classes WeightedSum and Prioritize.

log_parameters_to(logger)[source]

Log the parameters of this function to the provided destination.

Parameters:

logger (KeyValueLogSection) – the logger for the parameters

Return type:

None

weights: Final[tuple[int | float, ...] | None]

the internal weights

class moptipy.mo.problem.weighted_sum.Prioritize(objectives, domination=CPUDispatcher(<function dominates>))[source]

Bases: BasicWeightedSum

Prioritize the first objective over the second and so on.

class moptipy.mo.problem.weighted_sum.WeightedSum(objectives, weights=None, domination=CPUDispatcher(<function dominates>))[source]

Bases: BasicWeightedSum

Scalarize objective values by computing their weighted sum.