Ipopt#
#include <pagmo/algorithms/ipopt.hpp>
-
class ipopt : public pagmo::not_population_based#
Ipopt.
New in version 2.2.
This class is a user-defined algorithm (UDA) that wraps the Ipopt (Interior Point OPTimizer) solver, a software package for large-scale nonlinear optimization. Ipopt is a powerful solver that is able to handle robustly and efficiently constrained nonlinear optimization problems at high dimensionalities.
Ipopt supports only single-objective minimisation, and it requires the availability of the gradient in the optimisation problem. If possible, for best results the Hessians should be provided as well (but Ipopt can estimate numerically the Hessians if needed).
In order to support pagmo’s population-based optimisation model, ipopt::evolve() will select a single individual from the input pagmo::population to be optimised. If the optimisation produces a better individual (as established by pagmo::compare_fc()), the optimised individual will be inserted back into the population. The selection and replacement strategies can be configured via set_selection(const std::string &), set_selection(population::size_type), set_replacement(const std::string &) and set_replacement(population::size_type).
Public Types
-
using log_line_type = std::tuple<unsigned long, double, vector_double::size_type, double, bool>#
Single data line for the algorithm’s log.
A log data line is a tuple consisting of:
the number of objective function evaluations made so far,
the objective function value for the current decision vector,
the number of constraints violated by the current decision vector,
the constraints violation norm for the current decision vector,
a boolean flag signalling the feasibility of the current decision vector.
-
using log_type = std::vector<log_line_type>#
Log type.
The algorithm log is a collection of ipopt::log_line_type data lines, stored in chronological order during the optimisation if the verbosity of the algorithm is set to a nonzero value (see ipopt::set_verbosity()).
Public Functions
-
population evolve(population) const#
Evolve population.
This method will select an individual from
pop
, optimise it with Ipopt, replace an individual inpop
with the optimised individual, and finally returnpop
. The individual selection and replacement criteria can be set via set_selection(const std::string &), set_selection(population::size_type), set_replacement(const std::string &) and set_replacement(population::size_type). The return status of the Ipopt optimisation run will be recorded (it can be fetched with get_last_opt_result()).- Parameters
pop – the population to be optimised.
- Throws
std::invalid_argument – in the following cases:
the population’s problem is multi-objective or it does not provide the gradient,
the setup of the Ipopt solver options fails (e.g., an invalid option was specified by the user),
the components of the individual selected for optimisation contain NaNs or they are outside the problem’s bounds,
the exact evaluation of the Hessians was requested, but the problem does not support it.
std::runtime_error – if the initialization of the Ipopt solver fails.
unspecified – any exception thrown by the public interface of pagmo::problem or pagmo::not_population_based.
- Returns
the optimised population.
-
inline Ipopt::ApplicationReturnStatus get_last_opt_result() const#
Get the result of the last optimisation.
- Returns
the result of the last evolve() call, or
Ipopt::Solve_Succeeded
if no optimisations have been run yet.
-
inline std::string get_name() const#
Get the algorithm’s name.
- Returns
"Ipopt"
.
-
std::string get_extra_info() const#
Get extra information about the algorithm.
- Returns
a human-readable string containing useful information about the algorithm’s properties (e.g., the Ipopt optimisation options, the selection/replacement policies, etc.).
-
inline void set_verbosity(unsigned n)#
Set verbosity.
This method will set the algorithm’s verbosity. If
n
is zero, no output is produced during the optimisation and no logging is performed. Ifn
is nonzero, then everyn
objective function evaluations the status of the optimisation will be both printed to screen and recorded internally. See ipopt::log_line_type and ipopt::log_type for information on the logging format. The internal log can be fetched via get_log().Example (verbosity 1):
Theobjevals: objval: violated: viol. norm: 1 48.9451 1 1.25272 i 2 30.153 1 0.716591 i 3 26.2884 1 1.04269 i 4 14.6958 2 7.80753 i 5 14.7742 2 5.41342 i 6 17.093 1 0.0905025 i 7 17.1772 1 0.0158448 i 8 17.0254 2 0.0261289 i 9 17.0162 2 0.00435195 i 10 17.0142 2 0.000188461 i 11 17.014 1 1.90997e-07 i 12 17.014 0 0
i
at the end of some rows indicates that the decision vector is infeasible. Feasibility is checked against the problem’s tolerance.By default, the verbosity level is zero.
Note
Ipopt supports its own logging format and protocol, including the ability to print to screen and write to file. Ipopt’s screen logging is disabled by default (i.e., the Ipopt verbosity setting is set to 0 - see
pagmo::ipopt
). On-screen logging can be enabled via the"print_level"
string option.Warning
The number of constraints violated, the constraints violation norm and the feasibility flag stored in the log are all determined via the facilities and the tolerances specified within
pagmo::problem
. That is, they might not necessarily be consistent with Ipopt’s notion of feasibility. See the explanation of how the"constr_viol_tol"
numeric option is handled inpagmo::ipopt
.- Parameters
n – the desired verbosity level.
-
inline const log_type &get_log() const#
Get the optimisation log.
See ipopt::log_type for a description of the optimisation log. Logging is turned on/off via set_verbosity().
- Returns
a const reference to the log.
-
void set_string_option(const std::string&, const std::string&)#
Set string option.
This method will set the optimisation string option
name
tovalue
. The optimisation options are passed to the Ipopt API when calling evolve().- Parameters
name – of the option.
value – of the option.
-
void set_integer_option(const std::string&, Ipopt::Index)#
Set integer option.
This method will set the optimisation integer option
name
tovalue
. The optimisation options are passed to the Ipopt API when calling evolve().- Parameters
name – of the option.
value – of the option.
-
void set_numeric_option(const std::string&, double)#
Set numeric option.
This method will set the optimisation numeric option
name
tovalue
. The optimisation options are passed to the Ipopt API when calling evolve().- Parameters
name – of the option.
value – of the option.
-
void set_string_options(const std::map<std::string, std::string>&)#
Set string options.
This method will set the optimisation string options contained in
m
. It is equivalent to calling set_string_option() passing all the name-value pairs inm
as arguments.- Parameters
m – the name-value map that will be used to set the options.
-
void set_integer_options(const std::map<std::string, Ipopt::Index>&)#
Set integer options.
This method will set the optimisation integer options contained in
m
. It is equivalent to calling set_integer_option() passing all the name-value pairs inm
as arguments.- Parameters
m – the name-value map that will be used to set the options.
-
void set_numeric_options(const std::map<std::string, double>&)#
Set numeric options.
This method will set the optimisation numeric options contained in
m
. It is equivalent to calling set_numeric_option() passing all the name-value pairs inm
as arguments.- Parameters
m – the name-value map that will be used to set the options.
-
std::map<std::string, std::string> get_string_options() const#
Get string options.
- Returns
the name-value map of optimisation string options.
-
std::map<std::string, Ipopt::Index> get_integer_options() const#
Get integer options.
- Returns
the name-value map of optimisation integer options.
-
std::map<std::string, double> get_numeric_options() const#
Get numeric options.
- Returns
the name-value map of optimisation numeric options.
-
void reset_string_options()#
Clear all string options.
-
void reset_integer_options()#
Clear all integer options.
-
void reset_numeric_options()#
Clear all numeric options.
-
inline thread_safety get_thread_safety() const#
Thread safety level.
According to the official Ipopt documentation, it is not safe to use Ipopt in a multithreaded environment.
- Returns
thread_safety::none.
-
void set_random_sr_seed(unsigned)#
Set the seed for the
"random"
selection/replacement policies.- Parameters
seed – the value that will be used to seed the random number generator used by the
"random"
selection/replacement policies.
-
void set_selection(const std::string&)#
Set the individual selection policy.
This method will set the policy that is used to select the individual that will be optimised when calling the
evolve()
method of the algorithm.The input string must be one of
"best"
,"worst"
and"random"
:"best"
will select the best individual in the population,"worst"
will select the worst individual in the population,"random"
will randomly choose one individual in the population.
set_random_sr_seed() can be used to seed the random number generator used by the
"random"
policy.Instead of a selection policy, a specific individual in the population can be selected via set_selection(population::size_type).
- Parameters
select – the selection policy.
- Throws
std::invalid_argument – if
select
is not one of"best"
,"worst"
or"random"
.
-
inline void set_selection(population::size_type n)#
Set the individual selection index.
This method will set the index of the individual that is selected for optimisation in the
evolve()
method of the algorithm.- Parameters
n – the index in the population of the individual to be selected for optimisation.
-
boost::any get_selection() const#
Get the individual selection policy or index.
This method will return a
boost::any
containing either the individual selection policy (as anstd::string
) or the individual selection index (as a population::size_type). The selection policy or index is set via set_selection(const std::string &) and set_selection(population::size_type).- Returns
the individual selection policy or index.
-
void set_replacement(const std::string&)#
Set the individual replacement policy.
This method will set the policy that is used in the
evolve()
method of the algorithm to select the individual that will be replaced by the optimised individual.The input string must be one of
"best"
,"worst"
and"random"
:"best"
will select the best individual in the population,"worst"
will select the worst individual in the population,"random"
will randomly choose one individual in the population.
set_random_sr_seed() can be used to seed the random number generator used by the
"random"
policy.Instead of a replacement policy, a specific individual in the population can be selected via set_replacement(population::size_type).
- Parameters
replace – the replacement policy.
- Throws
std::invalid_argument – if
replace
is not one of"best"
,"worst"
or"random"
.
-
inline void set_replacement(population::size_type n)#
Set the individual replacement index.
This method will set the index of the individual that is replaced after the optimisation in the
evolve()
method of the algorithm.- Parameters
n – the index in the population of the individual to be replaced after the optimisation.
-
boost::any get_replacement() const#
Get the individual replacement policy or index.
This method will return a
boost::any
containing either the individual replacement policy (as anstd::string
) or the individual replacement index (as a population::size_type). The replacement policy or index is set via set_replacement(const std::string &) and set_replacement(population::size_type).- Returns
the individual replacement policy or index.
-
using log_line_type = std::tuple<unsigned long, double, vector_double::size_type, double, bool>#