List of problems#

Problems implemented in Python#

class pygmo.decorator_problem(prob=None, **kwargs)#

Decorator meta-problem.

New in version 2.9.

This meta-problem allows to apply arbitrary transformations to the functions of a PyGMO problem via Python decorators.

The decorators are passed as keyword arguments during initialisation, and they must be named after the function they are meant to decorate plus the _decorator suffix. For instance, we can define a minimal decorator for the fitness function as follows:

>>> def f_decor(orig_fitness_function):
...     def new_fitness_function(self, dv):
...         print("Evaluating dv: {}".format(dv))
...         return orig_fitness_function(self, dv)
...     return new_fitness_function

This decorator will print the input decision vector dv before invoking the original fitness function. We can then construct a decorated Rosenbrock problem as follows:

>>> from pygmo import decorator_problem, problem, rosenbrock
>>> dprob = problem(decorator_problem(rosenbrock(), fitness_decorator=f_decor))

We can then verify that calling the fitness function of dprob will print the decision vector before returning the fitness value:

>>> fv = dprob.fitness([1, 2])
Evaluating dv: [1. 2.]
>>> print(fv)
[100.]

An extended tutorial on the usage of this class is available in PyGMO’s documentation.

All the functions in the public API of a UDP can be decorated (see the documentation of pygmo.problem for the full list). Note that the public API of decorator_problem includes the UDP public API: there is a fitness() method, methods to query the problem’s properties, sparsity-related methods, etc. In order to avoid duplication, we do not repeat here the documentation of the UDP API and we document instead only the few methods which are specific to decorator_problem. Users can refer to the documentation of pygmo.problem for detailed information on the UDP API.

Both prob and the decorators will be deep-copied inside the instance upon construction. As usually done in meta-problems, this class will store as an internal data member a problem containing a copy of prob (this is commonly referred to as the inner problem of the meta-problem). The inner problem is accessible via the inner_problem read-only property.

Parameters
  • prob – a problem or a user-defined problem, either C++ or Python (if prob is None, a null_problem will be used in its stead)

  • kwargs – the dictionary of decorators to be applied to the functions of the input problem

Raises
  • TypeError – if at least one of the values in kwargs is not callable

  • unspecified – any exception thrown by the constructor of problem or the deep copy of prob or kwargs

get_decorator(fname)#

Get the decorator for the function called fname.

This method will return a copy of the decorator that has been registered upon construction for the function called fname. If no decorator for fname has been specified during construction, None will be returned.

>>> from pygmo import decorator_problem, problem, rosenbrock
>>> def f_decor(orig_fitness_function):
...     def new_fitness_function(self, dv):
...         print("Evaluating dv: {}".format(dv))
...         return orig_fitness_function(self, dv)
...     return new_fitness_function
>>> dprob = decorator_problem(rosenbrock(), fitness_decorator=f_decor)
>>> dprob.get_decorator("fitness") 
<function ...>
>>> dprob.get_decorator("gradient") is None
True
Parameters

fname (str) – the name of the function whose decorator will be returned

Returns

a copy of the decorator registered for fname, or None if no decorator for fname has been registered

Raises
  • TypeError – if fname is not a string

  • unspecified – any exception thrown by the deep copying of the decorator for fname

property inner_problem#

Inner problem of the meta-problem.

This read-only property gives direct access to the problem stored within this meta-problem.

Returns

a reference to the inner problem

Return type

problem

class pygmo.constant_arguments(prob, fixed_arguments: List[Optional[float]])#

Meta problem that sets some arguments of the original problem to constants

New in version 2.19.

If good values for some of the dimensions of a problem are known, this wrapper allows to reduce the dimensions of the search space and is an alternative to restricting a value using identical lower and upper bounds.

We can construct an instance of this problem by passing the original problem, and a list of containing one entry for each argument, either the fixed argument for this dimension or None if the argument should remain free:

>>> from pygmo import constant_arguments, problem, rosenbrock
>>> cprob = problem(constant_arguments(rosenbrock(dim=3), fixed_arguments=[1, None, None]))

We now see that the new problem has two dimensions, since the original problem had three and we fixed one:

>>> cprob.get_nx()
2
Parameters
  • prob – a problem or a user-defined problem, either C++ or Python (if prob is None, a null_problem will be used in its stead)

  • fixed_arguments – a list of values, one for each dimension of the wrapped problem. Each value should be either a float, if the argument should be fixed to this value, or None, if it should remain free

Raises
  • ValueError – if the lengths of fixed_arguments differs from the number of dimensions of the wrapped problem

  • ValueError – if any of the fixed arguments violate the bounds of the wrapped problem

  • ValueError – if a problem with nix() > 0 is passed

  • unspecified – any exception thrown by the constructor of problem or the deep copy of prob

get_full_x(x) List[float]#

Get the full x for a given x of lower dimension

Problems exposed from C++#

class pygmo.null_problem(nobj=1, nec=0, nic=0)#

The null problem.

A problem used in the default-initialization of pygmo.problem and of the meta-problems.

Parameters
  • nobj (int) – the number of objectives

  • nec (int) – the number of equality constraints

  • nic (int) – the number of inequality constraintsctives

Raises
  • ValueError – if nobj, nec, nic are negative or greater than an implementation-defined value or if nobj is zero

  • unspecified – any exception thrown by failures at the intersection between C++ and Python (e.g., type conversion errors, mismatched function signatures, etc.)


class pygmo.cec2014(prob_id=1, dim=2)#

New in version 2.8.

The CEC 2014 problem suite (continuous, box-bounded, single-objective problems)

Parameters
  • prob_id (int) – problem id (one of [1..30])

  • dim (int) – number of dimensions (one of [2, 10, 20, 30, 50, 100])

Raises
  • OverflowError – if dim or prob_id are negative or greater than an implementation-defined value

  • ValueError – if prob_id is not in [1..28] or if dim is not in [2, 10, 20, 30, 50, 100] or if dim is 2 and prob_id is in [17,18,19,20,21,22,29,30]

See also the docs of the C++ class pagmo::cec2014.


class pygmo.cec2013(prob_id=1, dim=2)#

The CEC 2013 problem suite (continuous, box-bounded, single-objective problems)

Parameters
  • prob_id (int) – problem id (one of [1..28])

  • dim (int) – number of dimensions (one of [2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])

Raises
  • OverflowError – if dim or prob_id are negative or greater than an implementation-defined value

  • ValueError – if prob_id is not in [1..28] or if dim is not in [2, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

See also the docs of the C++ class pagmo::cec2013.


class pygmo.cec2006(prob_id=1)#

The CEC 2006 problem suite (continuous, constrained, single-objective problems)

Parameters

prob_id (int) – problem id (one of [1..24])

Raises
  • OverflowError – if prob_id is negative or greater than an implementation-defined value

  • ValueError – if prob_id is not in [1..24]

See also the docs of the C++ class pagmo::cec2006.

best_known()#

The best known solution for the CEC 2006 problem.

Returns

the best known solution for the CEC 2006 problem

Return type

1D NumPy float array


class pygmo.cec2009(prob_id = 1, is_constrained = false, dim = 30u)#

The CEC 2009 problem suite (continuous, constrained, single-objective problems)

Parameters
  • prob_id (int) – problem id (one of [1..10])

  • is_constrained (bool) – selects the constrained version of the problems

  • dim (int) – problem dimension

Raises
  • OverflowError – if prob_id or dim are negative or greater than an implementation-defined value

  • ValueError – if prob_id is not in [1..10] or if dim is zero

See also the docs of the C++ class pagmo::cec2009.


class pygmo.rosenbrock(dim=2)#

The Rosenbrock problem.

Parameters

dim (int) – problem dimension

Raises
  • OverflowError – if dim is negative or greater than an implementation-defined value

  • ValueError – if dim is less than 2

See also the docs of the C++ class pagmo::rosenbrock.

best_known()#

The best known solution for the Rosenbrock problem.

Returns

the best known solution for the Rosenbrock problem

Return type

1D NumPy float array


class pygmo.rastrigin(dim=1)#

The Rastrigin problem.

See pagmo::rastrigin.

best_known()#

The best known solution for the Rastrigin problem.

Returns

the best known solution for the Rastrigin problem

Return type

1D NumPy float array


class pygmo.minlp_rastrigin(dim_c=1, dim_i=1)#

The scalable MINLP Rastrigin problem.

Parameters
  • dim_c (int) – MINLP continuous dimension

  • dim_i (int) – MINLP integer dimension

Raises
  • OverflowError – if dim_c / dim_i is negative or greater than an implementation-defined value

  • ValueError – if dim_c + dim_i is less than 1

See also the docs of the C++ class pagmo::minlp_rastrigin.


class pygmo.schwefel(dim=1)#

The Schwefel problem.

See pagmo::schwefel.

best_known()#

The best known solution for the Schwefel problem.

Returns

the best known solution for the Schwefel problem

Return type

1D NumPy float array


class pygmo.ackley(dim=1)#

The Ackley problem.

See pagmo::ackley.

best_known()#

The best known solution for the Ackley problem.

Returns

the best known solution for the Ackley problem

Return type

1D NumPy float array


class pygmo.griewank(dim=1)#

The Griewank problem.

See pagmo::griewank.

best_known()#

The best known solution for the Griewank problem.

Returns

the best known solution for the Griewank problem

Return type

1D NumPy float array


class pygmo.lennard_jones(atoms=3)#

The Lennard Jones Cluster problem.

See pagmo::lennard_jones.


class pygmo.golomb_ruler(order, upper_bound)#

The Golomb Ruler Problem.

See pagmo::golomb_ruler.


class pygmo.zdt(prob_id=1, param=30)#

The ZDT problem.

See pagmo::zdt.

p_distance(point)#

p_distance(pop)

Convergence metric for decision vectors (0 = on the optimal front)

Introduced by Martens and Izzo, this metric is able to measure “a distance” of any point from the pareto front of any DTLZ problem analytically.

Parameters
  • point (array-like object) – decision vector for which the p distance is requested

  • pop (population) – population for which the average p distance is requested

Returns

the distance (or average distance) from the Pareto front

Return type

float

See also the docs of the C++ class p_distance()


class pygmo.dtlz(prob_id=1, dim=5, fdim=3, alpha=100)#

The DTLZ problem suite problem.

Parameters
  • prob_id (int) – DTLZ problem id

  • dim (int) – problem dimension

  • fdim (int) – number of objectives

  • alpha (int) – controls density of solutions (used only by DTLZ4)

Raises
  • OverflowError – if prob_id, dim, fdim or alpha are negative or greater than an implementation-defined value

  • ValueError – if prob_id is not in [1..7], fdim is smaller than 2, dim is smaller or equal to fdim.

See also the docs of the C++ class pagmo::dtlz.

p_distance(point)#

p_distance(pop)

Convergence metric for decision vectors (0 = on the optimal front)

Introduced by Martens and Izzo, this metric is able to measure “a distance” of any point from the pareto front of any DTLZ problem analytically.

Parameters
  • point (array-like object) – decision vector for which the p distance is requested

  • pop (population) – population for which the average p distance is requested

Returns

the distance (or average distance) from the Pareto front

Return type

float

See also the docs of the C++ class p_distance()

plot(pop, az=40, comp=[0, 1, 2])#

Plots solutions to the DTLZ problems in three dimensions. The Pareto Front is also visualized if the problem id is 2,3 or 4.

Parameters
  • pop (population) – population of solutions to a dtlz problem

  • az (float) – angle of view on which the 3d-plot is created

  • comp (list) – indexes the fitness dimension for x,y and z axis in that order

Returns

the current axes instance on the current figure

Raises

ValueError – if pop does not contain a DTLZ problem (veryfied by its name only) or if comp is not of length 3

Examples

>>> import pygmo as pg
>>> udp = pg.dtlz(prob_id = 1, fdim =3, dim = 5)
>>> pop = pg.population(udp, 40)
>>> udp.plot(pop) 

class pygmo.inventory(weeks=4, sample_size=10, seed=random)#

The inventory problem.

See pagmo::inventory.


class pygmo.hock_schittkowski_71#

The Hock-schittkowski 71 problem.

See pagmo::hock_schittkowski_71.

best_known()#

The best known solution for the Hock-schittkowski 71 problem.

Returns

the best known solution for the Hock-schittkowski 71 problem

Return type

1D NumPy float array


class pygmo.luksan_vlcek1(dim=3)#

Implementation of Example 5.1 in the report from Luksan and Vlcek.

The problem is also known as the Chained Rosenbrock function with trigonometric-exponential constraints.

Its formulation in pygmo is written as:

\[\begin{split}\begin{array}{rl} \mbox{find:} & -5 \le x_i \le 5, \forall i=1..n \\ \mbox{to minimize: } & \sum_{i=1}^{n-1}\left[100\left(x_i^2-x_{i+1}\right)^2 + \left(x_i-1\right)^2\right] \\ \mbox{subject to:} & 3x_{k+1}^3+2x_{k+2}-5+\sin(x_{k+1}-x_{k+2})\sin(x_{k+1}+x_{k+2}) + \\ & +4x_{k+1}-x_k\exp(x_k-x_{k+1})-3 = 0, \forall k=1..n-2 \end{array}\end{split}\]

See: Luksan, L., and Jan Vlcek. “Sparse and partially separable test problems for unconstrained and equality constrained optimization.” (1999). http://hdl.handle.net/11104/0123965

Parameters

dim (int) – problem dimension

Raises

OverflowError – if dim is negative or greater than an implementation-defined value

See also the docs of the C++ class pagmo::luksan_vlcek1.


class pygmo.translate(prob=None, translation=[0.0])#

The translate meta-problem.

This meta-problem translates the whole search space of an input pygmo.problem or user-defined problem (UDP) by a fixed translation vector. translate objects are user-defined problems that can be used in the construction of a pygmo.problem.

Parameters
  • prob – a user-defined problem (either Python or C++), or an instance of problem (if prob is None, a null_problem will be used in its stead)

  • translation (array-like object) – an array containing the translation to be applied

Raises
  • ValueError – if the length of translation is not equal to the dimension of prob

  • unspecified – any exception thrown by: * the constructor of pygmo.problem, * the constructor of the underlying C++ class, * failures at the intersection between C++ and Python (e.g., type conversion errors, mismatched function signatures, etc.)

property inner_problem#

Inner problem of the meta-problem.

This read-only property gives direct access to the problem stored within this meta-problem.

Returns

a reference to the inner problem

Return type

problem

property translation#

Translation vector.

This read-only property contains an array of float representing the translation vector used in the construction of this problem.

Returns

the translation vector

Return type

1D NumPy float array


class pygmo.decompose(prob=None, weight=[0.5, 0.5], z=[0.0, 0.0], method='weighted', adapt_ideal=False)#

The decompose meta-problem.

This meta-problem decomposes a multi-objective input user-defined problem, resulting in a single-objective user-defined problem with a fitness function combining the original fitness functions. In particular, three different decomposition methods are here made available:

  • weighted decomposition,

  • Tchebycheff decomposition,

  • boundary interception method (with penalty constraint).

In the case of \(n\) objectives, we indicate with: \(\mathbf f(\mathbf x) = [f_1(\mathbf x), \ldots, f_n(\mathbf x)]\) the vector containing the original multiple objectives, with: \(\boldsymbol \lambda = (\lambda_1, \ldots, \lambda_n)\) an \(n\)-dimensional weight vector and with: \(\mathbf z^* = (z^*_1, \ldots, z^*_n)\) an \(n\)-dimensional reference point. We also ussume \(\lambda_i > 0, \forall i=1..n\) and \(\sum_i \lambda_i = 1\).

The decomposed problem is thus a single objective optimization problem having the following single objective, according to the decomposition method chosen:

  • weighted decomposition: \(f_d(\mathbf x) = \boldsymbol \lambda \cdot \mathbf f\),

  • Tchebycheff decomposition: \(f_d(\mathbf x) = \max_{1 \leq i \leq m} \lambda_i \vert f_i(\mathbf x) - z^*_i \vert\),

  • boundary interception method (with penalty constraint): \(f_d(\mathbf x) = d_1 + \theta d_2\),

where \(d_1 = (\mathbf f - \mathbf z^*) \cdot \hat {\mathbf i}_{\lambda}\), \(d_2 = \vert (\mathbf f - \mathbf z^*) - d_1 \hat {\mathbf i}_{\lambda})\vert\) and \(\hat {\mathbf i}_{\lambda} = \frac{\boldsymbol \lambda}{\vert \boldsymbol \lambda \vert}\).

The reference point \(z^*\) is often taken as the ideal point and as such it may be allowed to change during the course of the optimization / evolution. The argument adapt_ideal activates this behaviour so that whenever a new ideal point is found \(z^*\) is adapted accordingly.

The use of decompose discards gradients and hessians so that if the original user defined problem implements them, they will not be available in the decomposed problem. The reason for this behaviour is that the Tchebycheff decomposition is not differentiable. Also, the use of this class was originally intended for derivative-free optimization.

See: “Q. Zhang – MOEA/D: A Multiobjective Evolutionary Algorithm Based on Decomposition”

See: https://en.wikipedia.org/wiki/Multi-objective_optimization#Scalarizing

Parameters
  • prob – a user-defined problem (either Python or C++), or an instance of problem (if prob is None, a null_problem will be used in its stead)

  • weight (array-like object) – the vector of weights \(\boldsymbol \lambda\)

  • z (array-like object) – the reference point \(\mathbf z^*\)

  • method (str) – a string containing the decomposition method chosen

  • adapt_ideal (bool) – when True, the reference point is adapted at each fitness evaluation to be the ideal point

Raises
  • ValueError – if either: * prob is single objective or constrained, * method is not one of ['weighted', 'tchebycheff', 'bi'], * weight is not of size \(n\), * z is not of size \(n\) * weight is not such that \(\lambda_i > 0, \forall i=1..n\), * weight is not such that \(\sum_i \lambda_i = 1\)

  • unspecified – any exception thrown by: * the constructor of pygmo.problem, * the constructor of the underlying C++ class, * failures at the intersection between C++ and Python (e.g., type conversion errors, mismatched function signatures, etc.)

property inner_problem#

Inner problem of the meta-problem.

This read-only property gives direct access to the problem stored within this meta-problem.

Returns

a reference to the inner problem

Return type

problem

original_fitness(x)#

Fitness of the original problem.

Returns the fitness of the original multi-objective problem used to construct the decomposed problem.

Parameters

x (array-like object) – input decision vector

Returns

the fitness of the original multi-objective problem

Return type

1D NumPy float array

Raises

unspecified – any exception thrown by the original fitness computation, or by failures at the intersection between C++ and Python (e.g., type conversion errors, mismatched function signatures, etc.)

property z#

Current reference point.

This read-only property contains the reference point to be used for the decomposition. This is only used for Tchebycheff and boundary interception decomposition methods.

The reference point is adapted at each call of the fitness.

Returns

the reference point

Return type

1D NumPy float array

Raises

unspecified – any exception thrown by failures at the intersection between C++ and Python (e.g., type conversion errors, mismatched function signatures, etc.)


class pygmo.unconstrain(prob=None, method='death penalty', weights=[])#

The unconstrain meta-problem.

This meta-problem transforms a constrained problem into an unconstrained problem applying one of the following methods:

  • Death penalty: simply penalizes all objectives by the same high value if the fitness vector is infeasible.

  • Kuri’s death penalty: defined by Angel Kuri Morales et al., penalizes all objectives according to the rate of satisfied constraints.

  • Weighted violations penalty: penalizes all objectives by the weighted sum of the constraint violations.

  • Ignore the constraints: simply ignores the constraints.

  • Ignore the objectives: ignores the objectives and defines as a new single objective the overall constraints violation (i.e. the sum of the L2 norms of the equalities and inequalities violations)

The use of unconstrain discards gradients and hessians so that if the original user defined problem implements them, they will not be available in the unconstrained problem. The reason for this behaviour is that, in general, the methods implemented may not be differentiable. Also, the use of this class was originally intended for derivative-free optimization.

See: Coello Coello, C. A. (2002). Theoretical and numerical constraint-handling techniques used with evolutionary algorithms: a survey of the state of the art. Computer methods in applied mechanics and engineering, 191(11), 1245-1287.

See: Kuri Morales, A. and Quezada, C.C. A Universal eclectic genetic algorithm for constrained optimization, Proceedings 6th European Congress on Intelligent Techniques & Soft Computing, EUFIT’98, 518-522, 1998.

Parameters
  • prob – a problem or a user-defined problem, either C++ or Python (if prob is None, a null_problem will be used in its stead)

  • method (str) – a string containing the unconstrain method chosen, one of ['death penalty', 'kuri', 'weighted', 'ignore_c', 'ignore_o']

  • weights (array-like object) – the vector of weights to be used if the method chosen is 'weighted'

Raises
  • ValueError – if either: * prob is unconstrained, * method is not one of ['death penalty', 'kuri', 'weighted', 'ignore_c', 'ignore_o'], * weight is not of the same size as the problem constraints (if the method 'weighted' is selected), or not empty otherwise.

  • unspecified – any exception thrown by: * the constructor of pygmo.problem, * the constructor of the underlying C++ class, * failures at the intersection between C++ and Python (e.g., type conversion errors, mismatched function signatures, etc.)

property inner_problem#

Inner problem of the meta-problem.

This read-only property gives direct access to the problem stored within this meta-problem.

Returns

a reference to the inner problem

Return type

problem


class pygmo.wfg(prob_id=1, dim_dvs=5, dim_obj=3, dim_k=4)#

The WFG problem suite.

Parameters
  • prob_id (int) – WFG problem id

  • dim_dvs (int) – decision vector size

  • dim_obj (int) – number of objectives

  • dim_k (int) – position parameter

Raises
  • OverflowError – if prob_id, dim_dvs, dim_obj or dim_k are negative or greater than an implementation-defined value

  • ValueError – if prob_id is not in [1, …, 9], dim_dvs is smaller than 1, dim_obj is smaller than 2, dim_k is smaller than 1 or bigger or equal to dim_dvs or if dim_k*mod(*dim_obj-1) is different than zero. Also, when prob_id equals to 2 or 3, if (dim_dvs-dim_k)mod(2) is different than zero.

See also the docs of the C++ class pagmo::wfg.