Problem#
#include <pagmo/problem.hpp>
-
class problem#
Problem class.
This class represents a generic mathematical programming or evolutionary optimization problem in the form:
\[\begin{split} \begin{array}{rl} \mbox{find:} & \mathbf {lb} \le \mathbf x \le \mathbf{ub}\\ \mbox{to minimize: } & \mathbf f(\mathbf x, s) \in \mathbb R^{n_{obj}}\\ \mbox{subject to:} & \mathbf {c}_e(\mathbf x, s) = 0 \\ & \mathbf {c}_i(\mathbf x, s) \le 0 \end{array} \end{split}\]where \(\mathbf x \in \mathbb R^{n_{cx}} \times \mathbb Z^{n_{ix}}\) is called decision vector or chromosome, and is made of \(n_{cx}\) real numbers and \(n_{ix}\) integers (all represented as doubles). The total problem dimension is then indicated with \(n_x = n_{cx} + n_{ix}\). \(\mathbf{lb}, \mathbf{ub} \in \mathbb R^{n_{cx}} \times \mathbb Z^{n_{ix}}\) are the box-bounds, \( \mathbf f: \mathbb R^{n_{cx}} \times \mathbb Z^{n_{ix}} \rightarrow \mathbb R^{n_{obj}}\) define the objectives, \( \mathbf c_e: \mathbb R^{n_{cx}} \times \mathbb Z^{n_{ix}} \rightarrow \mathbb R^{n_{ec}}\) are non linear equality constraints, and \( \mathbf c_i: \mathbb R^{n_{cx}} \times \mathbb Z^{n_{ix}} \rightarrow \mathbb R^{n_{ic}}\) are non linear inequality constraints. Note that the objectives and constraints may also depend from an added value \(s\) seeding the values of any number of stochastic variables. This allows also for stochastic programming tasks to be represented by this class. A tolerance is also considered for all constraints and set, by default, to zero. It can be modified via the problem::set_c_tol() method.
In order to define an optimization problem in pagmo, the user must first define a class (or a struct) whose methods describe the properties of the problem and allow to compute the objective function, the gradient, the constraints, etc. In pagmo, we refer to such a class as a user-defined problem, or UDP for short. Once defined and instantiated, a UDP can then be used to construct an instance of this class, pagmo::problem, which provides a generic interface to optimization problems.
Every UDP must implement at least the following two methods:
vector_double fitness(const vector_double &) const; std::pair<vector_double, vector_double> get_bounds() const;
The
fitness()
method is expected to return the fitness of the input decision vector ( concatenating the objectives, the equality and the inequality constraints), whileget_bounds()
is expected to return the box bounds of the problem, \((\mathbf{lb}, \mathbf{ub})\), which also implicitly define the dimension of the problem. Thefitness()
andget_bounds()
methods of the UDP are accessible from the corresponding problem::fitness() and problem::get_bounds() methods (see their documentation for details). In addition to providing the above methods, a UDP must also be default, copy and move constructible.The two mandatory methods above allow to define a continuous, single objective, deterministic, derivative-free, unconstrained optimization problem. In order to consider more complex cases, the UDP may implement one or more of the following methods:
vector_double::size_type get_nobj() const; vector_double::size_type get_nec() const; vector_double::size_type get_nic() const; vector_double::size_type get_nix() const; vector_double batch_fitness(const vector_double &) const; bool has_batch_fitness() const; bool has_gradient() const; vector_double gradient(const vector_double &) const; bool has_gradient_sparsity() const; sparsity_pattern gradient_sparsity() const; bool has_hessians() const; std::vector<vector_double> hessians(const vector_double &) const; bool has_hessians_sparsity() const; std::vector<sparsity_pattern> hessians_sparsity() const; bool has_set_seed() const; void set_seed(unsigned); std::string get_name() const; std::string get_extra_info() const; thread_safety get_thread_safety() const;
See the documentation of the corresponding methods in this class for details on how the optional methods in the UDP are used by pagmo::problem.
Warning
The only operations allowed on a moved-from
pagmo::problem
are destruction, assignment, and the invocation of theis_valid()
member function. Any other operation will result in undefined behaviour.Public Functions
-
problem()#
Default constructor.
The default constructor will initialize a pagmo::problem containing a pagmo::null_problem.
- Throws
unspecified – any exception thrown by the constructor from UDP.
-
template<typename T, generic_ctor_enabler<T> = 0>
inline explicit problem(T &&x)# Constructor from a user-defined problem of type
T
.This constructor will construct a pagmo::problem from the UDP (user-defined problem)
x
of typeT
. In order for the construction to be successful, the UDP must implement a minimal set of methods, as described in the documentation of pagmo::problem. The constructor will examine the properties ofx
and store them as data members ofthis
.Note
This constructor is not enabled if, after the removal of cv and reference qualifiers,
T
is of typepagmo::problem
(that is, this constructor does not compete with the copy/move constructors ofpagmo::problem
), or ifT
does not satisfypagmo::is_udp
.- Parameters
x – the UDP.
- Throws
std::invalid_argument – in the following cases:
the number of objectives of the UDP is zero,
the number of objectives, equality or inequality constraints is larger than an implementation-defined value,
the problem bounds are invalid (e.g., they contain NaNs, the dimensionality of the lower bounds is different from the dimensionality of the upper bounds, the bounds relative to the integer part are not integers, etc. - note that infinite bounds are allowed),
the
gradient_sparsity()
andhessians_sparsity()
methods of the UDP fail basic sanity checks (e.g., they return vectors with repeated indices, they contain indices exceeding the problem’s dimensions, etc.).the integer part of the problem is larger than the problem size.
unspecified – any exception thrown by methods of the UDP invoked during construction or by memory errors in strings and standard containers.
-
problem(const problem&)#
Copy constructor.
The copy constructor will deep copy the input problem
other
.- Parameters
other – the problem to be copied.
- Throws
unspecified – any exception thrown by:
memory allocation errors in standard containers,
the copying of the internal UDP.
-
problem(problem&&) noexcept#
Move constructor.
- Parameters
other – the problem from which
this
will be move-constructed.
-
problem &operator=(problem&&) noexcept#
Move assignment operator.
- Parameters
other – the assignment target.
- Returns
a reference to
this
.
-
problem &operator=(const problem&)#
Copy assignment operator.
Copy assignment is implemented as a copy constructor followed by a move assignment.
- Parameters
other – the assignment target.
- Throws
unspecified – any exception thrown by the copy constructor.
- Returns
a reference to
this
.
-
template<typename T, generic_ctor_enabler<T> = 0>
inline problem &operator=(T &&x)# Assignment from a user-defined problem of type
T
.This operator will set the internal UDP to
x
by constructing a pagmo::problem fromx
, and then move-assigning the result tothis
.Note
This operator is not enabled if, after the removal of cv and reference qualifiers,
T
is of typepagmo::problem
(that is, this operator does not compete with the copy/move assignment operators ofpagmo::problem
), or ifT
does not satisfypagmo::is_udp
.- Parameters
x – the UDP.
- Throws
unspecified – any exception thrown by the constructor from UDP.
- Returns
a reference to
this
.
-
template<typename T>
inline const T *extract() const noexcept# Extract a const pointer to the UDP used for construction.
This method will extract a const pointer to the internal instance of the UDP. If
T
is not the same type as the UDP used during construction (after removal of cv and reference qualifiers), this method will returnnullptr
.Note
The returned value is a raw non-owning pointer: the lifetime of the pointee is tied to the lifetime of
this
, anddelete
must never be called on the pointer.- Returns
a const pointer to the internal UDP, or
nullptr
ifT
does not correspond exactly to the original UDP type used in the constructor.
-
template<typename T>
inline T *extract() noexcept# Extract a pointer to the UDP used for construction.
This method will extract a pointer to the internal instance of the UDP. If
T
is not the same type as the UDP used during construction (after removal of cv and reference qualifiers), this method will returnnullptr
.Note
The returned value is a raw non-owning pointer: the lifetime of the pointee is tied to the lifetime of
this
, anddelete
must never be called on the pointer.Note
The ability to extract a mutable pointer is provided only in order to allow to call non-const methods on the internal UDP instance. Assigning a new UDP via this pointer is undefined behaviour.
- Returns
a pointer to the internal UDP, or
nullptr
ifT
does not correspond exactly to the original UDP type used in the constructor.
-
template<typename T>
inline bool is() const noexcept# Check if the UDP used for construction is of type
T
.- Returns
true
if the UDP used for construction is of typeT
,false
otherwise.
-
vector_double fitness(const vector_double&) const#
Fitness.
This method will invoke the
fitness()
method of the UDP to compute the fitness of the input decision vectordv
. The return value of thefitness()
method of the UDP is expected to have a dimension of \(n_{f} = n_{obj} + n_{ec} + n_{ic}\) and to contain the concatenated values of \(\mathbf f, \mathbf c_e\) and \(\mathbf c_i\) (in this order). Equality constraints are all assumed in the form \(c_{e_i}(\mathbf x) = 0\) while inequalities are assumed in the form \(c_{i_i}(\mathbf x) <= 0\) so that negative values are associated to satisfied inequalities.In addition to invoking the
fitness()
method of the UDP, this method will perform sanity checks ondv
and on the returned fitness vector. A successful call of this method will increase the internal fitness evaluation counter (see problem::get_fevals()).- Parameters
dv – the decision vector.
- Throws
- Returns
the fitness of
dv
.
-
vector_double batch_fitness(const vector_double&) const#
Batch fitness.
This method implements the evaluation of multiple decision vectors in batch mode by invoking the
batch_fitness()
method of the UDP. Thebatch_fitness()
method of the UDP accepts in input a batch of decision vectors,dvs
, stored contiguously: for a problem with dimension \( n \), the first decision vector indvs
occupies the index range \( \left[0, n\right) \), the second decision vector occupies the range \( \left[n, 2n\right) \), and so on. The return value is the batch of fitness vectorsfvs
resulting from computing the fitness of the input decision vectors.fvs
is also stored contiguously: for a problem with fitness dimension \( f \), the first fitness vector will occupy the index range \( \left[0, f\right) \), the second fitness vector will occupy the range \( \left[f, 2f\right) \), and so on.If the UDP satisfies
pagmo::has_batch_fitness
, this method will forwarddvs
to thebatch_fitness()
method of the UDP after sanity checks. The output of thebatch_fitness()
method of the UDP will also be checked before being returned. If the UDP does not satisfypagmo::has_batch_fitness
, an error will be raised.A successful call of this method will increase the internal fitness evaluation counter (see problem::get_fevals()).
- Parameters
dvs – the input batch of decision vectors.
- Throws
std::invalid_argument – if either
dvs
or the return value are incompatible with the properties of this problem.not_implemented_error – if the UDP does not have a
batch_fitness()
method.unspecified – any exception thrown by the
batch_fitness()
method of the UDP.
- Returns
the fitnesses of the decision vectors in
dvs
.
-
inline bool has_batch_fitness() const#
Check if the UDP is capable of fitness evaluation in batch mode.
This method will return
true
if the UDP is capable of fitness evaluation in batch mode,false
otherwise.The batch fitness evaluation capability of the UDP is determined as follows:
if the UDP does not satisfy
pagmo::has_batch_fitness
, then this method will always returnfalse
;if the UDP satisfies
pagmo::has_batch_fitness
but it does not satisfypagmo::override_has_batch_fitness
, then this method will always returntrue
;if the UDP satisfies both
pagmo::has_batch_fitness
andpagmo::override_has_batch_fitness
, then this method will return the output of thehas_batch_fitness()
method of the UDP.
- Returns
a flag signalling the availability of fitness evaluation in batch mode in the UDP.
-
vector_double gradient(const vector_double&) const#
Gradient.
This method will compute the gradient of the input decision vector
dv
by invoking thegradient()
method of the UDP. Thegradient()
method of the UDP must return a sparse representation of the gradient: the \( k\)-th term of the gradient vector is expected to contain \( \frac{\partial f_i}{\partial x_j}\), where the pair \((i,j)\) is the \(k\)-th element of the sparsity pattern (collection of index pairs), as returned by problem::gradient_sparsity().If the UDP satisfies pagmo::has_gradient, this method will forward
dv
to thegradient()
method of the UDP after sanity checks. The output of thegradient()
method of the UDP will also be checked before being returned. If the UDP does not satisfy pagmo::has_gradient, an error will be raised.A successful call of this method will increase the internal gradient evaluation counter (see problem::get_gevals()).
- Parameters
dv – the decision vector whose gradient will be computed.
- Throws
std::invalid_argument – if either:
the length of
dv
differs from the value returned by get_nx(), orthe returned gradient vector does not have the same size as the vector returned by problem::gradient_sparsity().
not_implemented_error – if the UDP does not satisfy pagmo::has_gradient.
unspecified – any exception thrown by the
gradient()
method of the UDP.
- Returns
the gradient of
dv
.
-
inline bool has_gradient() const#
Check if the gradient is available in the UDP.
This method will return
true
if the gradient is available in the UDP,false
otherwise.The availability of the gradient is determined as follows:
if the UDP does not satisfy pagmo::has_gradient, then this method will always return
false
;if the UDP satisfies pagmo::has_gradient but it does not satisfy pagmo::override_has_gradient, then this method will always return
true
;if the UDP satisfies both pagmo::has_gradient and pagmo::override_has_gradient, then this method will return the output of the
has_gradient()
method of the UDP.
- Returns
a flag signalling the availability of the gradient in the UDP.
-
sparsity_pattern gradient_sparsity() const#
Gradient sparsity pattern.
This method will return the gradient sparsity pattern of the problem. The gradient sparsity pattern is a lexicographically sorted collection of the indices \((i,j)\) of the non-zero elements of \( g_{ij} = \frac{\partial f_i}{\partial x_j}\).
If problem::has_gradient_sparsity() returns
true
, then thegradient_sparsity()
method of the UDP will be invoked, and its result returned (after sanity checks). Otherwise, a a dense pattern is assumed and the returned vector will be \(((0,0),(0,1), ... (0,n_x-1), ...(n_f-1,n_x-1))\).- Throws
std::invalid_argument – if the sparsity pattern returned by the UDP is invalid (specifically, if it is not strictly sorted lexicographically, or if the indices in the pattern are incompatible with the properties of the problem, or if the size of the returned pattern is different from the size recorded upon construction).
unspecified – memory errors in standard containers.
- Returns
the gradient sparsity pattern.
-
inline bool has_gradient_sparsity() const#
Check if the gradient sparsity is available in the UDP.
This method will return
true
if the gradient sparsity is available in the UDP,false
otherwise.The availability of the gradient sparsity is determined as follows:
if the UDP does not satisfy pagmo::has_gradient_sparsity, then this method will always return
false
;if the UDP satisfies pagmo::has_gradient_sparsity but it does not satisfy pagmo::override_has_gradient_sparsity, then this method will always return
true
;if the UDP satisfies both pagmo::has_gradient_sparsity and pagmo::override_has_gradient_sparsity, then this method will return the output of the
has_gradient_sparsity()
method of the UDP.
Note
Regardless of what this method returns, the
problem::gradient_sparsity()
method will always return a sparsity pattern: if the UDP does not provide the gradient sparsity, PaGMO will assume that the sparsity pattern of the gradient is dense. Seeproblem::gradient_sparsity()
for more details.- Returns
a flag signalling the availability of the gradient sparsity in the UDP.
-
std::vector<vector_double> hessians(const vector_double&) const#
Hessians.
This method will compute the hessians of the input decision vector
dv
by invoking thehessians()
method of the UDP. Thehessians()
method of the UDP must return a sparse representation of the hessians: the element \( l\) of the returned vector contains \( h^l_{ij} = \frac{\partial f^2_l}{\partial x_i\partial x_j}\) in the order specified by the \( l\)-th element of the hessians sparsity pattern (a vector of index pairs \((i,j)\)) as returned by problem::hessians_sparsity(). Since the hessians are symmetric, their sparse representation contains only lower triangular elements.If the UDP satisfies pagmo::has_hessians, this method will forward
dv
to thehessians()
method of the UDP after sanity checks. The output of thehessians()
method of the UDP will also be checked before being returned. If the UDP does not satisfy pagmo::has_hessians, an error will be raised.A successful call of this method will increase the internal hessians evaluation counter (see problem::get_hevals()).
- Parameters
dv – the decision vector whose hessians will be computed.
- Throws
std::invalid_argument – if either:
the length of
dv
differs from the output of get_nx(), orthe length of the returned hessians does not match the corresponding hessians sparsity pattern dimensions, or
the size of the return value is not equal to the fitness dimension.
not_implemented_error – if the UDP does not satisfy pagmo::has_hessians.
unspecified – any exception thrown by the
hessians()
method of the UDP.
- Returns
the hessians of
dv
.
-
inline bool has_hessians() const#
Check if the hessians are available in the UDP.
This method will return
true
if the hessians are available in the UDP,false
otherwise.The availability of the hessians is determined as follows:
if the UDP does not satisfy pagmo::has_hessians, then this method will always return
false
;if the UDP satisfies pagmo::has_hessians but it does not satisfy pagmo::override_has_hessians, then this method will always return
true
;if the UDP satisfies both pagmo::has_hessians and pagmo::override_has_hessians, then this method will return the output of the
has_hessians()
method of the UDP.
- Returns
a flag signalling the availability of the hessians in the UDP.
-
std::vector<sparsity_pattern> hessians_sparsity() const#
Hessians sparsity pattern.
This method will return the hessians sparsity pattern of the problem. Each component \( l\) of the hessians sparsity pattern is a lexicographically sorted collection of the indices \((i,j)\) of the non-zero elements of \(h^l_{ij} = \frac{\partial f^l}{\partial x_i\partial x_j}\). Since the Hessian matrix is symmetric, only lower triangular elements are allowed.
If problem::has_hessians_sparsity() returns
true
, then thehessians_sparsity()
method of the UDP will be invoked, and its result returned (after sanity checks). Otherwise, a dense pattern is assumed and \(n_f\) sparsity patterns containing \(((0,0),(1,0), (1,1), (2,0) ... (n_x-1,n_x-1))\) will be returned.- Throws
std::invalid_argument – if a sparsity pattern returned by the UDP is invalid (specifically, if if it is not strictly sorted lexicographically, if the returned indices do not correspond to a lower triangular representation of a symmetric matrix, or if the size of the pattern differs from the size recorded upon construction).
- Returns
the hessians sparsity pattern.
-
inline bool has_hessians_sparsity() const#
Check if the hessians sparsity is available in the UDP.
This method will return
true
if the hessians sparsity is available in the UDP,false
otherwise.The availability of the hessians sparsity is determined as follows:
if the UDP does not satisfy pagmo::has_hessians_sparsity, then this method will always return
false
;if the UDP satisfies pagmo::has_hessians_sparsity but it does not satisfy pagmo::override_has_hessians_sparsity, then this method will always return
true
;if the UDP satisfies both pagmo::has_hessians_sparsity and pagmo::override_has_hessians_sparsity, then this method will return the output of the
has_hessians_sparsity()
method of the UDP.
Note
Regardless of what this method returns, the
problem::hessians_sparsity()
method will always return a vector of sparsity patterns: if the UDP does not provide the hessians sparsity, PaGMO will assume that the sparsity pattern of the hessians is dense. Seeproblem::hessians_sparsity()
for more details.- Returns
a flag signalling the availability of the hessians sparsity in the UDP.
-
inline vector_double::size_type get_nobj() const#
Number of objectives.
This method will return \( n_{obj}\), the number of objectives of the optimization problem. If the UDP satisfies the pagmo::has_get_nobj type traits, then the output of its
get_nobj()
method will be returned. Otherwise, this method will return 1.- Returns
the number of objectives of the problem.
-
inline vector_double::size_type get_nx() const#
Dimension.
- Returns
\( n_{x}\), the dimension of the problem as established by the length of the bounds returned by problem::get_bounds().
-
inline vector_double::size_type get_nix() const#
Integer Dimension.
This method will return \( n_{ix} \), the dimension of the integer part of the problem. If the UDP satisfies pagmo::has_integer_part, then the output of its
get_nix()
method will be returned. Otherwise, this method will return 0. Note that integer variables must be appended after continuous variables in the decision vector \( x \).- Returns
\( n_{ix}\), the integer dimension of the problem.
-
inline vector_double::size_type get_ncx() const#
Continuous Dimension.
- Returns
\( n_{cx}\), the continuous dimension of the problem as established by the relation \(n_{cx} = n_{x} - n_{ix} \).
- Returns
\( n_{cx}\), the continuous dimension of the problem.
-
inline vector_double::size_type get_nf() const#
Fitness dimension.
- Returns
\( n_{f}\), the dimension of the fitness, which is the sum of \(n_{obj}\), \(n_{ec}\) and \(n_{ic}\)
-
std::pair<vector_double, vector_double> get_bounds() const#
Box-bounds.
- Throws
unspecified – any exception thrown by memory errors in standard containers.
- Returns
\( (\mathbf{lb}, \mathbf{ub}) \), the box-bounds, as returned by the
get_bounds()
method of the UDP. Infinities in the bounds are allowed.
-
inline const vector_double &get_lb() const#
Lower bounds.
- Returns
a const reference to the vector of lower box bounds for this problem.
-
inline const vector_double &get_ub() const#
Upper bounds.
- Returns
a const reference to the vector of upper box bounds for this problem.
-
inline vector_double::size_type get_nec() const#
Number of equality constraints.
This method will return \( n_{ec} \), the number of equality constraints of the problem. If the UDP satisfies pagmo::has_e_constraints, then the output of its
get_nec()
method will be returned. Otherwise, this method will return 0.- Returns
the number of equality constraints of the problem.
-
inline vector_double::size_type get_nic() const#
Number of inequality constraints.
This method will return \( n_{ic} \), the number of inequality constraints of the problem. If the UDP satisfies pagmo::has_i_constraints, then the output of its
get_nic()
method will be returned. Otherwise, this method will return 0.- Returns
the number of inequality constraints of the problem.
-
void set_c_tol(const vector_double&)#
Set the constraint tolerance (from a vector of doubles).
- Parameters
c_tol – a vector containing the tolerances to use when checking for constraint feasibility.
- Throws
std::invalid_argument – if the size of
c_tol
differs from the number of constraints, or if any of its elements is negative or NaN.
-
void set_c_tol(double)#
Set the constraint tolerance (from a single double value).
- Parameters
c_tol – the tolerance to use when checking for all constraint feasibilities.
- Throws
std::invalid_argument – if
c_tol
is negative or NaN.
-
inline vector_double get_c_tol() const#
Get the constraint tolerance.
This method will return a vector of dimension \(n_{ec} + n_{ic}\) containing tolerances to be used when checking constraint feasibility. The constraint tolerance is zero-filled upon problem construction, and it can be set via problem::set_c_tol().
- Returns
a pagmo::vector_double containing the tolerances to use when checking for constraint feasibility.
-
inline vector_double::size_type get_nc() const#
Total number of constraints.
-
inline unsigned long long get_fevals() const#
Number of fitness evaluations.
Each time a call to problem::fitness() successfully completes, an internal counter is increased by one. The counter is initialised to zero upon problem construction and it is never reset. Copy and move operations copy the counter as well.
- Returns
the number of times problem::fitness() was successfully called.
-
inline void increment_fevals(unsigned long long n) const#
Increment the number of fitness evaluations.
This method will increase the internal counter of fitness evaluations by
n
.- Parameters
n – the amount by which the internal counter of fitness evaluations will be increased.
-
inline unsigned long long get_gevals() const#
Number of gradient evaluations.
Each time a call to problem::gradient() successfully completes, an internal counter is increased by one. The counter is initialised to zero upon problem construction and it is never reset. Copy and move operations copy the counter as well.
- Returns
the number of times problem::gradient() was successfully called.
-
inline unsigned long long get_hevals() const#
Number of hessians evaluations.
Each time a call to problem::hessians() successfully completes, an internal counter is increased by one. The counter is initialised to zero upon problem construction and it is never reset. Copy and move operations copy the counter as well.
- Returns
the number of times problem::hessians() was successfully called.
-
void set_seed(unsigned)#
Set the seed for the stochastic variables.
Sets the seed to be used in the fitness function to instantiate all stochastic variables. If the UDP satisfies pagmo::has_set_seed, then its
set_seed()
method will be invoked. Otherwise, an error will be raised.- Parameters
seed – seed.
- Throws
not_implemented_error – if the UDP does not satisfy pagmo::has_set_seed.
unspecified – any exception thrown by the
set_seed()
method of the UDP.
-
bool feasibility_x(const vector_double&) const#
Feasibility of a decision vector.
This method will check the feasibility of the fitness corresponding to a decision vector
x
against the tolerances returned by problem::get_c_tol().Note
One call of this method will cause one call to the fitness function.
- Parameters
x – a decision vector.
- Throws
unspecified – any exception thrown by problem::feasibility_f() or problem::fitness().
- Returns
true
if the decision vector results in a feasible fitness,false
otherwise.
-
bool feasibility_f(const vector_double&) const#
Feasibility of a fitness vector.
This method will check the feasibility of a fitness vector
f
against the tolerances returned by problem::get_c_tol().- Parameters
f – a fitness vector.
- Throws
std::invalid_argument – if the size of
f
is not the same as the output of problem::get_nf().- Returns
true
if the fitness vector is feasible,false
otherwise.
-
inline bool has_set_seed() const#
Check if a
set_seed()
method is available in the UDP.This method will return
true
if aset_seed()
method is available in the UDP,false
otherwise.The availability of the a
set_seed()
method is determined as follows:if the UDP does not satisfy pagmo::has_set_seed, then this method will always return
false
;if the UDP satisfies pagmo::has_set_seed but it does not satisfy pagmo::override_has_set_seed, then this method will always return
true
;if the UDP satisfies both pagmo::has_set_seed and pagmo::override_has_set_seed, then this method will return the output of the
has_set_seed()
method of the UDP.
- Returns
a flag signalling the availability of the
set_seed()
method in the UDP.
-
inline bool is_stochastic() const#
Alias for problem::has_set_seed().
- Returns
the output of problem::has_set_seed().
-
inline std::string get_name() const#
Problem’s name.
If the UDP satisfies pagmo::has_name, then this method will return the output of its
get_name()
method. Otherwise, an implementation-defined name based on the type of the UDP will be returned.- Throws
unspecified – any exception thrown by copying an
std::string
object.- Returns
the problem’s name.
-
std::string get_extra_info() const#
Problem’s extra info.
If the UDP satisfies pagmo::has_extra_info, then this method will return the output of its
get_extra_info()
method. Otherwise, an empty string will be returned.- Throws
unspecified – any exception thrown by the
get_extra_info()
method of the UDP.- Returns
extra info about the UDP.
-
inline thread_safety get_thread_safety() const#
Problem’s thread safety level.
If the UDP satisfies pagmo::has_get_thread_safety, then this method will return the output of its
get_thread_safety()
method. Otherwise, thread_safety::basic will be returned. That is, pagmo assumes by default that is it safe to operate concurrently on distinct UDP instances.- Returns
the thread safety level of the UDP.
-
bool is_valid() const#
Check if the problem is in a valid state.
- Returns
false
ifthis
was moved from,true
otherwise.
-
std::type_index get_type_index() const#
Get the type of the UDP.
New in version 2.15.
This function will return the type of the UDP stored within this problem instance.
- Returns
the type of the UDP.
-
const void *get_ptr() const#
Get a const pointer to the UDP.
New in version 2.15.
This function will return a raw const pointer to the internal UDP instance. Differently from
extract()
, this function does not require to pass the correct type in input. It is however the user’s responsibility to cast the returned void pointer to the correct type.Note
The returned value is a raw non-owning pointer: the lifetime of the pointee is tied to the lifetime of
this
, anddelete
must never be called on the pointer.- Returns
a pointer to the internal UDP.
-
void *get_ptr()#
Get a mutable pointer to the UDP.
New in version 2.15.
This function will return a raw pointer to the internal UDP instance. Differently from
extract()
, this function does not require to pass the correct type in input. It is however the user’s responsibility to cast the returned void pointer to the correct type.Note
The returned value is a raw non-owning pointer: the lifetime of the pointee is tied to the lifetime of
this
, anddelete
must never be called on the pointer.Note
The ability to extract a mutable pointer is provided only in order to allow to call non-const methods on the internal UDP instance. Assigning a new UDP via this pointer is undefined behaviour.
- Returns
a pointer to the internal UDP.
-
problem()#
Associated type traits#
-
template<typename T>
class has_batch_fitness# This type trait detects if
T
provides a member function whose signature is compatible withvector_double batch_fitness(const vector_double &) const;
The
batch_fitness()
member function is part of the interface for the definition of a user-defined problem (see theproblem
documentation for details).-
static const bool value#
The value of the type trait.
-
static const bool value#
-
template<typename T>
class override_has_batch_fitness# This type trait detects if
T
provides a member function whose signature is compatible withbool has_batch_fitness() const;
The
has_batch_fitness()
member function is part of the interface for the definition of a user-defined problem (see theproblem
documentation for details).-
static const bool value#
The value of the type trait.
-
static const bool value#