Sleipnir C++ API
|
#include <sleipnir/optimization/OptimizationProblem.hpp>
Public Member Functions | |
OptimizationProblem () noexcept=default | |
Variable | DecisionVariable () |
VariableMatrix | DecisionVariable (int rows, int cols=1) |
VariableMatrix | SymmetricDecisionVariable (int rows) |
void | Minimize (const Variable &cost) |
void | Minimize (Variable &&cost) |
void | Maximize (const Variable &objective) |
void | Maximize (Variable &&objective) |
void | SubjectTo (const EqualityConstraints &constraint) |
void | SubjectTo (EqualityConstraints &&constraint) |
void | SubjectTo (const InequalityConstraints &constraint) |
void | SubjectTo (InequalityConstraints &&constraint) |
SolverStatus | Solve (const SolverConfig &config=SolverConfig{}) |
template<typename F > requires requires(F callback, const SolverIterationInfo& info) { { callback(info) } -> std::same_as<void>; } | |
void | Callback (F &&callback) |
template<typename F > requires requires(F callback, const SolverIterationInfo& info) { { callback(info) } -> std::same_as<bool>; } | |
void | Callback (F &&callback) |
This class allows the user to pose a constrained nonlinear optimization problem in natural mathematical notation and solve it.
This class supports problems of the form:
minₓ f(x) subject to cₑ(x) = 0 cᵢ(x) ≥ 0
where f(x) is the scalar cost function, x is the vector of decision variables (variables the solver can tweak to minimize the cost function), cᵢ(x) are the inequality constraints, and cₑ(x) are the equality constraints. Constraints are equations or inequalities of the decision variables that constrain what values the solver is allowed to use when searching for an optimal solution.
The nice thing about this class is users don't have to put their system in the form shown above manually; they can write it in natural mathematical form and it'll be converted for them.
|
defaultnoexcept |
Construct the optimization problem.
|
inline |
Sets a callback to be called at each solver iteration.
The callback for this overload should return void.
callback | The callback. |
|
inline |
Sets a callback to be called at each solver iteration.
The callback for this overload should return bool.
callback | The callback. Returning true from the callback causes the solver to exit early with the solution it has so far. |
|
inline |
Create a decision variable in the optimization problem.
|
inline |
Create a matrix of decision variables in the optimization problem.
rows | Number of matrix rows. |
cols | Number of matrix columns. |
Tells the solver to maximize the output of the given objective function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
objective | The objective function to maximize. |
Tells the solver to maximize the output of the given objective function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
objective | The objective function to maximize. |
Tells the solver to minimize the output of the given cost function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
cost | The cost function to minimize. |
Tells the solver to minimize the output of the given cost function.
Note that this is optional. If only constraints are specified, the solver will find the closest solution to the initial conditions that's in the feasible set.
cost | The cost function to minimize. |
|
inline |
Solve the optimization problem. The solution will be stored in the original variables used to construct the problem.
config | Configuration options for the solver. |
|
inline |
Tells the solver to solve the problem while satisfying the given equality constraint.
constraint | The constraint to satisfy. |
|
inline |
Tells the solver to solve the problem while satisfying the given inequality constraint.
constraint | The constraint to satisfy. |
|
inline |
Tells the solver to solve the problem while satisfying the given equality constraint.
constraint | The constraint to satisfy. |
|
inline |
Tells the solver to solve the problem while satisfying the given inequality constraint.
constraint | The constraint to satisfy. |
|
inline |
Create a symmetric matrix of decision variables in the optimization problem.
Variable instances are reused across the diagonal, which helps reduce problem dimensionality.
rows | Number of matrix rows. |