Sleipnir C++ API
Loading...
Searching...
No Matches
slp::Problem Class Reference

#include <sleipnir/optimization/problem.hpp>

Inheritance diagram for slp::Problem:
slp::OCP

Public Member Functions

 Problem () noexcept=default
 
Variable decision_variable ()
 
VariableMatrix decision_variable (int rows, int cols=1)
 
VariableMatrix symmetric_decision_variable (int rows)
 
void minimize (const Variable &cost)
 
void minimize (Variable &&cost)
 
void maximize (const Variable &objective)
 
void maximize (Variable &&objective)
 
void subject_to (const EqualityConstraints &constraint)
 
void subject_to (EqualityConstraints &&constraint)
 
void subject_to (const InequalityConstraints &constraint)
 
void subject_to (InequalityConstraints &&constraint)
 
ExpressionType cost_function_type () const
 
ExpressionType equality_constraint_type () const
 
ExpressionType inequality_constraint_type () const
 
ExitStatus solve (const Options &options=Options{})
 
template<typename F >
requires requires(F callback, const IterationInfo& info) { { callback(info) } -> std::same_as<void>; }
void add_callback (F &&callback)
 
template<typename F >
requires requires(F callback, const IterationInfo& info) { { callback(info) } -> std::same_as<bool>; }
void add_callback (F &&callback)
 
void clear_callbacks ()
 

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

◆ Problem()

slp::Problem::Problem ( )
defaultnoexcept

Construct the optimization problem.

Member Function Documentation

◆ add_callback() [1/2]

template<typename F >
requires requires(F callback, const IterationInfo& info) { { callback(info) } -> std::same_as<void>; }
void slp::Problem::add_callback ( F &&  callback)
inline

Adds a callback to be called at each solver iteration.

The callback for this overload should return void.

Parameters
callbackThe callback.

◆ add_callback() [2/2]

template<typename F >
requires requires(F callback, const IterationInfo& info) { { callback(info) } -> std::same_as<bool>; }
void slp::Problem::add_callback ( F &&  callback)
inline

Adds 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.

◆ clear_callbacks()

void slp::Problem::clear_callbacks ( )
inline

Clears the registered callbacks.

◆ cost_function_type()

ExpressionType slp::Problem::cost_function_type ( ) const
inline

Returns the cost function's type.

Returns
The cost function's type.

◆ decision_variable() [1/2]

Variable slp::Problem::decision_variable ( )
inline

Create a decision variable in the optimization problem.

Returns
A decision variable in the optimization problem.

◆ decision_variable() [2/2]

VariableMatrix slp::Problem::decision_variable ( 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.
Returns
A matrix of decision variables in the optimization problem.

◆ equality_constraint_type()

ExpressionType slp::Problem::equality_constraint_type ( ) const
inline

Returns the type of the highest order equality constraint.

Returns
The type of the highest order equality constraint.

◆ inequality_constraint_type()

ExpressionType slp::Problem::inequality_constraint_type ( ) const
inline

Returns the type of the highest order inequality constraint.

Returns
The type of the highest order inequality constraint.

◆ maximize() [1/2]

void slp::Problem::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 slp::Problem::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 slp::Problem::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 slp::Problem::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()

ExitStatus slp::Problem::solve ( const Options options = Options{})
inline

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

Parameters
optionsSolver options.
Returns
The solver status.

◆ subject_to() [1/4]

void slp::Problem::subject_to ( const EqualityConstraints constraint)
inline

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

Parameters
constraintThe constraint to satisfy.

◆ subject_to() [2/4]

void slp::Problem::subject_to ( const InequalityConstraints constraint)
inline

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

Parameters
constraintThe constraint to satisfy.

◆ subject_to() [3/4]

void slp::Problem::subject_to ( EqualityConstraints &&  constraint)
inline

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

Parameters
constraintThe constraint to satisfy.

◆ subject_to() [4/4]

void slp::Problem::subject_to ( InequalityConstraints &&  constraint)
inline

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

Parameters
constraintThe constraint to satisfy.

◆ symmetric_decision_variable()

VariableMatrix slp::Problem::symmetric_decision_variable ( 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.
Returns
A symmetric matrix of decision varaibles in the optimization problem.

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