Constrained optimization utilities#

pygmo.compare_fc(f1, f2, nec, tol)#

Compares two fitness vectors in a single-objective, constrained, case.

The following strict ordering is used:

  • \(f_1 \prec f_2\) if \(f_1\) is feasible and \(f_2\) is not.

  • \(f_1 \prec f_2\) if \(f_1\) is they are both infeasible, but \(f_1\) violates fewer constraints than \(f_2\), or in case they both violate the same number of constraints, if the \(L_2\) norm of the overall constraint violation is smaller.

  • \(f_1 \prec f_2\) if both fitness vectors are feasible and the objective value in \(f_1\) is smaller than the objectve value in \(f_2\)

Note

The fitness vectors are assumed to contain exactly one objective, nec equality constraints and the rest (if any) inequality constraints.

Parameters
  • f1 (array-like object) – the first fitness vector

  • f2 (array-like object) – the second fitness vector

  • nec (int) – the number of equality consraints in the fitness vectors

  • tol (array-like object) – tolerances to be accounted for in the constraints

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

  • ValueError – if f1 and f2 do not have equal size \(n\), if f1 does not have at least size 1, if nec is larger than \(n-1\) (too many constraints) or if the size of tol is not \(n - 1\)

  • TypeError – if f1, f2 or tol cannot be converted to a vector of floats

Returns

True if f1 is better than f2, False otherwise.

Return type

bool

Examples

>>> import pygmo as pg
>>> pg.compare_fc(f1 = [1,1,1], f2 = [1,2.1,-1.2], nec = 1, tol = [0]*2)
False

pygmo.sort_population_con(input_f, nec, tol)#

Sorts a population (intended here as a 2D array-like containing fitness vectors) assuming a single-objective, constrained case.

The following strict ordering is used (same as the one used in pygmo.compare_fc()):

  • \(f_1 \prec f_2\) if \(f_1\) is feasible and \(f_2\) is not.

  • \(f_1 \prec f_2\) if \(f_1\) is they are both infeasible, but \(f_1\) violates fewer constraints than \(f_2\), or in case they both violate the same number of constraints, if the \(L_2\) norm of the overall constraint violation is smaller.

  • \(f_1 \prec f_2\) if both fitness vectors are feasible and the objective value in \(f_1\) is smaller than the objectve value in \(f_2\)

Note

The fitness vectors are assumed to contain exactly one objective, nec equality constraints and the rest (if any) inequality constraints.

Parameters
  • input_f (2-D array-like object) – the fitness vectors

  • nec (int) – the number of equality constraints in the fitness vectors

  • tol (array-like object) – tolerances to be accounted for in the constraints

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

  • ValueError – if the input fitness vectors do not have all the same size \(n >=1\), or if nec is larger than \(n-1\) (too many constraints) or if the size of tol is not equal to \(n-1\)

  • TypeError – if input_f cannot be converted to a vector of vector of floats or tol cannot be converted to a vector of floats.

Returns

the indexes of the sorted fitnesses vectors.

Return type

list of 1D NumPy int array

Examples

>>> import pygmo as pg
>>> idxs = pg.sort_population_con(input_f = [[1.2,0.1,-1],[0.2,1.1,1.1],[2,-0.5,-2]], nec = 1, tol = [1e-8]*2)
>>> print(idxs)
[0 2 1]