Optimist
0.0.0
A C++ library for optimization
|
Class container for the generic root-finding/optimization problem solver. More...
#include <Solver.hh>
Public Member Functions | |
Solver () | |
Solver (FunctionWrapper function, const InputType &x_ini, InputType &x_sol) | |
Solver (FunctionWrapper function, FirstDerivativeWrapper first_derivative, const InputType &x_ini, InputType &x_sol) | |
Solver (FunctionWrapper function, FirstDerivativeWrapper first_derivative, SecondDerivativeWrapper second_derivative, const InputType &x_ini, InputType &x_sol) | |
const InputType & | lower_bound () const |
void | lower_bound (const InputType &t_lower_bound) |
const InputType & | upper_bound () const |
void | upper_bound (const InputType &t_upper_bound) |
void | bounds (const InputType &t_lower_bound, const InputType &t_upper_bound) |
constexpr Integer | input_dimension () const |
constexpr Integer | output_dimension () const |
Integer | function_evaluations () const |
void | max_function_evaluations (Integer t_max_function_evaluations) |
Integer | max_function_evaluations () const |
Integer | iterations () const |
Integer | max_iterations () const |
void | max_iterations (Integer t_max_iterations) |
Real | alpha () const |
void | alpha (Real t_alpha) |
Integer | relaxations () const |
Integer | max_relaxations () const |
void | max_relaxations (Integer t_max_relaxations) |
Real | tolerance () const |
void | tolerance (Real t_tolerance) |
void | verbose_mode (bool t_verbose) |
bool | verbose_mode () const |
void | enable_verbose_mode () |
void | disable_verbose_mode () |
void | damped_mode (bool t_damped) |
bool | damped_mode () const |
void | enable_damped_mode () |
void | disable_damped_mode () |
std::string | task () const |
void | task (std::string t_task) |
bool | converged () const |
const TraceType & | trace () const |
std::ostream & | ostream () const |
void | ostream (std::ostream &t_ostream) |
bool | solve (FunctionWrapper function, const InputType &x_ini, InputType &x_sol) |
bool | solve (FunctionWrapper function, FirstDerivativeWrapper first_derivative, const InputType &x_ini, InputType &x_sol) |
bool | solve (FunctionWrapper function, FirstDerivativeWrapper first_derivative, SecondDerivativeWrapper second_derivative, const InputType &x_ini, InputType &x_sol) |
template<Integer FunInDim, Integer FunOutDim, typename DerivedFunction> | |
bool | rootfind (Function< Real, FunInDim, FunOutDim, DerivedFunction > const &function, const InputType &x_ini, InputType &x_sol) |
template<Integer FunInDim, Integer FunOutDim, typename DerivedFunction> | |
bool | optimize (Function< Real, FunInDim, FunOutDim, DerivedFunction > const &function, const InputType &x_ini, InputType &x_sol) |
std::string | name () const |
Protected Types | |
using | InputType = typename std::conditional_t<SolInDim == 1, Real, Eigen::Vector<Real, SolInDim>> |
using | OutputType = typename std::conditional_t<SolOutDim == 1, Real, Eigen::Vector<Real, SolOutDim>> |
using | TraceType = typename std::vector<InputType> |
using | FirstDerivativeType = std::conditional_t<SolInDim == 1 && SolOutDim == 1, Real, Eigen::Matrix<Real, SolOutDim, SolInDim>> |
using | SecondDerivativeType |
using | FunctionWrapper = typename std::function<void(const InputType &, OutputType &)> |
using | FirstDerivativeWrapper = typename std::function<void(const InputType &, FirstDerivativeType &)> |
using | SecondDerivativeWrapper = typename std::function<void(const InputType &, SecondDerivativeType &)> |
Protected Attributes | |
InputType | m_lower_bound |
InputType | m_upper_bound |
Integer | m_function_evaluations {0} |
Integer | m_first_derivative_evaluations {0} |
Integer | m_second_derivative_evaluations {0} |
Integer | m_max_function_evaluations {1000} |
Integer | m_max_first_derivative_evaluations {1000} |
Integer | m_max_second_derivative_evaluations {1000} |
Integer | m_iterations {0} |
Integer | m_max_iterations {100} |
Real | m_alpha {0.8} |
Integer | m_relaxations {0} |
Integer | m_max_relaxations {10} |
Real | m_tolerance {EPSILON_LOW} |
bool | m_verbose {false} |
bool | m_damped {true} |
std::ostream * | m_ostream {&std::cout} |
std::string | m_task {"Undefined"} |
bool | m_converged {false} |
TraceType | m_trace |
The solvers implemented in Optimist
are derived from the Solver
class, which provides a common interface for solving nonlinear systems of equations. The Solver
class is an abstract base class that defines the methods and attributes required by the derived classes. The derived classes implement the specific algorithms for solving the nonlinear systems of equations.
This class provides a base class for developing solvers that handle a generic function \(\mathbf{f}(\mathbf{x}): \mathbb{R}^{n} \rightarrow \mathbb{R}^{m}\). In general, the derived classes are designed to solve root-finding problems of the form
\[ \mathbf{f}(\mathbf{x}) = \mathbf{0} \text{,} \quad \text{with} \quad \mathbf{f}: \mathbb{R}^{n} \rightarrow \mathbb{R}^{n} \text{,} \]
as well as optimization problems of the form
\[ \min_{\mathbf{x}} f(\mathbf{x}) \text{,} \quad f: \mathbb{R}^{n} \rightarrow \mathbb{R} \text{.} \]
If \(n > 1\) the solver is a multi-dimensional solver, otherwise, it is a scalar solver. The linear algebra operations are performed using the Eigen
library, which provides a high-level interface for matrix operations. Otherwise, for \(n = 1\), the base type changes to Real
, a scalar type defined in the Optimist
library.
Real | Scalar number type. |
SolInDim | The root-finding/optimization problem input dimension. |
SolOutDim | The root-finding/optimization problem output dimension. |
DerivedSolver | Derived solver class. |
|
protected |
First derivative type.
|
protected |
First derivative type.
|
protected |
Function type.
|
protected |
Basic constants. Input type.
|
protected |
Output type.
|
protected |
Second derivative type.
|
protected |
Second derivative type.
|
protected |
Input trace type.
|
inline |
Class constructor for the nonlinear solver.
|
inline |
Class constructor for the nonlinear solver.
[in] | function | Function wrapper. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
|
inline |
Class constructor for the nonlinear solver.
[in] | function | Function wrapper. |
[in] | first_derivative | First derivative wrapper. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
|
inline |
Class constructor for the nonlinear solver.
[in] | function | Function wrapper. |
[in] | first_derivative | First derivative wrapper. |
[in] | second_derivative | The second derivative wrapper. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
|
inline |
Get relaxation factor \( \alpha \).
|
inline |
Set relaxation factor \( \alpha \).
[in] | t_alpha | The relaxation factor \( \alpha \). |
|
inlineprotected |
Print the table bottom solver information.
|
inline |
Set the bounds.
[in] | t_lower_bound | The lower bound. |
[in] | t_upper_bound | The upper bound. |
|
inline |
Get the convergence boolean flag.
|
inlineprotected |
Damp the step using the affine invariant criterion.
[in] | function | Function wrapper. |
[in] | x_old | Old point. |
[in] | function_old | Old function value. |
[in] | step_old | Old step. |
[in] | x_new | New point. |
[in] | function_new | New function value. |
[out] | step_new | New step. |
|
inline |
Get the damped mode boolean flag.
|
inline |
Set the damped mode boolean flag.
[in] | t_damped | The damped mode boolean flag. |
|
inline |
Disable solver's damped mode.
|
inline |
Disable solver's verbose mode.
|
inline |
Enable solver's damped mode.
|
inline |
Enable solver's verbose mode.
|
inlineprotected |
Evaluate the first derivative.
[in] | function | First derivative wrapper. |
[in] | x | Input point. |
[out] | out | First derivative value. |
|
inlineprotected |
|
inlineprotected |
Evaluate the second derivative.
[in] | function | Second derivative wrapper. |
[in] | x | Input point. |
[out] | out | Second derivative value. |
|
inlineprotected |
Get the number of function derivative evaluations.
|
inline |
Get the number of function evaluations.
|
inlineprotected |
Print the table header solver information.
|
inlineprotected |
Print the solver information during the algorithm iterations.
|
inlineconstexpr |
Get the input dimension of the function.
|
inline |
Get the number of algorithm iterations.
|
inline |
Get the lower bound.
|
inline |
Set the lower bound.
[in] | t_lower_bound | The lower bound. |
|
inlineprotected |
Get the number of maximum allowed first derivative evaluations.
|
inlineprotected |
Set the number of maximum allowed first derivative evaluations.
[in] | first_derivative_evaluations | The number of maximum allowed first derivative evaluations. |
|
inline |
Get the number of maximum allowed function evaluations.
|
inline |
Set the number of maximum allowed function evaluations.
[in] | t_max_function_evaluations | The number of maximum allowed function evaluations. |
|
inline |
Get the number of maximum allowed iterations.
|
inline |
Set the number of maximum allowed iterations.
[in] | t_max_iterations | The number of maximum allowed iterations. |
|
inline |
Get the number of maximum allowed relaxations.
|
inline |
Set the number of maximum allowed relaxations.
[in] | t_max_relaxations | The number of maximum allowed relaxations. |
|
inlineprotected |
Get the number of maximum allowed second derivative evaluations.
|
inlineprotected |
Set the number of maximum allowed second derivative evaluations.
[in] | second_derivative_evaluations | The number of maximum allowed second derivative evaluations. |
|
inline |
Get the solver name.
|
inline |
Solve the optimization problem given a function class.
[in] | function | Function class. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
FunInDim | The function output dimension. |
FunOutDim | The function output dimension. |
DerivedFunction | Derived function class. |
|
inline |
Get the output stream for verbose mode.
|
inline |
Set the output stream for verbose mode.
[in] | t_ostream | The output stream for verbose mode. |
|
inlineconstexpr |
Get the output dimension of the function.
|
inline |
Get the number of algorithm relaxations.
|
inlineprotected |
Reset solver internal counters and variables.
|
inline |
Solve the root-finding problem given a function class.
[in] | function | Function class. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
FunInDim | The function output dimension. |
FunOutDim | The function output dimension. |
DerivedFunction | Derived function class. |
|
inlineprotected |
Get the number of second derivative evaluations.
|
inlineprotected |
Solve the root-finding/optimization problem given a function class.
[in] | function | Function class. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
[in] | is_optimization | Boolean flag for optimization. |
FunInDim | The function output dimension. |
FunOutDim | The function output dimension. |
DerivedFunction | Derived function class. |
|
inline |
Solve the root-finding/optimization problem given the function, and without derivatives.
[in] | function | Function wrapper. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
|
inline |
Solve the root-finding/optimization problem given the function, and its first derivative.
[in] | function | Function wrapper. |
[in] | first_derivative | First derivative wrapper |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
|
inline |
Solve the root-finding/optimization problem given the function, and its first and second derivatives.
[in] | function | Function wrapper. |
[in] | first_derivative | First derivative wrapper. |
[in] | second_derivative | The second derivative wrapper. |
[in] | x_ini | Initialization point. |
[out] | x_sol | Solution point. |
|
inlineprotected |
Update the history of the solver with the current point and function value.
[in] | x | The point \( \mathbf{x} \). |
|
inline |
Get the task name.
|
inline |
Set the task name.
[in] | t_task | The task name. |
|
inline |
Get the tolerance \( \epsilon \).
|
inline |
Set the tolerance \( \epsilon \) for which the nonlinear solver stops, i.e., \( \left\| \mathbf{F}(\mathbf{x}) \right\|_{2} < \epsilon \).
[in] | t_tolerance | The tolerance \( \epsilon \). |
|
inline |
Get the trace of input values during the algorithm iterations.
|
inline |
Get the upper bound.
|
inline |
Set the upper bound.
[in] | t_upper_bound | The upper bound. |
|
inline |
Get the verbose mode boolean flag.
|
inline |
Set the verbose mode boolean flag.
[in] | t_verbose | The verbose mode boolean flag. |
|
protected |
Relaxation factor \( \alpha \).
|
protected |
Convergence boolean flag.
|
protected |
Damped mode boolean flag.
|
protected |
First derivative evaluations.
|
protected |
Function evaluations.
|
protected |
Algorithm iterations.
|
protected |
Lower bound.
|
protected |
Maximum allowed first derivative evaluations.
|
protected |
Maximum allowed function evaluations.
|
protected |
Maximum allowed algorithm iterations.
|
protected |
Maximum allowed algorithm relaxations.
|
protected |
Maximum allowed second derivative evaluations.
|
protected |
Output stream for verbose mode.
|
protected |
Algorithm relaxations.
|
protected |
Second derivative evaluations.
|
protected |
Task name.
|
protected |
Solver tolerance \( \epsilon \) for convergence.
|
protected |
Trace for points \( \mathbf{x} \) values.
|
protected |
Upper bound.
|
protected |
Verbose mode boolean flag.