Sleipnir C++ API
Loading...
Searching...
No Matches
sleipnir::OptimizationProblem Class Reference

#include <sleipnir/optimization/OptimizationProblem.hpp>

Inheritance diagram for sleipnir::OptimizationProblem:
sleipnir::OCPSolver

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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ OptimizationProblem()

sleipnir::OptimizationProblem::OptimizationProblem ( )
defaultnoexcept

Construct the optimization problem.

Member Function Documentation

◆ Callback() [1/2]

template<typename F >
requires requires(F callback, const SolverIterationInfo& info) { { callback(info) } -> std::same_as<void>; }
void sleipnir::OptimizationProblem::Callback ( F &&  callback)
inline

Sets a callback to be called at each solver iteration.

The callback for this overload should return void.

Parameters
callbackThe callback.

◆ Callback() [2/2]

template<typename F >
requires requires(F callback, const SolverIterationInfo& info) { { callback(info) } -> std::same_as<bool>; }
void sleipnir::OptimizationProblem::Callback ( F &&  callback)
inline

Sets a callback to be called at each solver iteration.

The callback for this overload should return bool.

Parameters
callbackThe callback. Returning true from the callback causes the solver to exit early with the solution it has so far.

◆ DecisionVariable() [1/2]

Variable sleipnir::OptimizationProblem::DecisionVariable ( )
inline

Create a decision variable in the optimization problem.

◆ DecisionVariable() [2/2]

VariableMatrix sleipnir::OptimizationProblem::DecisionVariable ( int  rows,
int  cols = 1 
)
inline

Create a matrix of decision variables in the optimization problem.

Parameters
rowsNumber of matrix rows.
colsNumber of matrix columns.

◆ Maximize() [1/2]

void sleipnir::OptimizationProblem::Maximize ( const Variable objective)
inline

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.

Parameters
objectiveThe objective function to maximize.

◆ Maximize() [2/2]

void sleipnir::OptimizationProblem::Maximize ( Variable &&  objective)
inline

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.

Parameters
objectiveThe objective function to maximize.

◆ Minimize() [1/2]

void sleipnir::OptimizationProblem::Minimize ( const Variable cost)
inline

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.

Parameters
costThe cost function to minimize.

◆ Minimize() [2/2]

void sleipnir::OptimizationProblem::Minimize ( Variable &&  cost)
inline

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.

Parameters
costThe cost function to minimize.

◆ Solve()

SolverStatus sleipnir::OptimizationProblem::Solve ( const SolverConfig config = SolverConfig{})
inline

Solve the optimization problem. The solution will be stored in the original variables used to construct the problem.

Parameters
configConfiguration options for the solver.

◆ SubjectTo() [1/4]

void sleipnir::OptimizationProblem::SubjectTo ( const EqualityConstraints constraint)
inline

Tells the solver to solve the problem while satisfying the given equality constraint.

Parameters
constraintThe constraint to satisfy.

◆ SubjectTo() [2/4]

void sleipnir::OptimizationProblem::SubjectTo ( const InequalityConstraints constraint)
inline

Tells the solver to solve the problem while satisfying the given inequality constraint.

Parameters
constraintThe constraint to satisfy.

◆ SubjectTo() [3/4]

void sleipnir::OptimizationProblem::SubjectTo ( EqualityConstraints &&  constraint)
inline

Tells the solver to solve the problem while satisfying the given equality constraint.

Parameters
constraintThe constraint to satisfy.

◆ SubjectTo() [4/4]

void sleipnir::OptimizationProblem::SubjectTo ( InequalityConstraints &&  constraint)
inline

Tells the solver to solve the problem while satisfying the given inequality constraint.

Parameters
constraintThe constraint to satisfy.

◆ SymmetricDecisionVariable()

VariableMatrix sleipnir::OptimizationProblem::SymmetricDecisionVariable ( int  rows)
inline

Create a symmetric matrix of decision variables in the optimization problem.

Variable instances are reused across the diagonal, which helps reduce problem dimensionality.

Parameters
rowsNumber of matrix rows.

The documentation for this class was generated from the following file: