This class allows the user to pose and solve a constrained optimal control problem (OCP) in a variety of ways.
More...
|
| OCP (int num_states, int num_inputs, std::chrono::duration< double > dt, int num_steps, function_ref< VariableMatrix(const VariableMatrix &x, const VariableMatrix &u)> dynamics, DynamicsType dynamics_type=DynamicsType::EXPLICIT_ODE, TimestepMethod timestep_method=TimestepMethod::FIXED, TranscriptionMethod method=TranscriptionMethod::DIRECT_TRANSCRIPTION) |
| Build an optimization problem using a system evolution function (explicit ODE or discrete state transition function).
|
|
| OCP (int num_states, int num_inputs, std::chrono::duration< double > dt, int num_steps, function_ref< VariableMatrix(const Variable &t, const VariableMatrix &x, const VariableMatrix &u, const Variable &dt)> dynamics, DynamicsType dynamics_type=DynamicsType::EXPLICIT_ODE, TimestepMethod timestep_method=TimestepMethod::FIXED, TranscriptionMethod method=TranscriptionMethod::DIRECT_TRANSCRIPTION) |
| Build an optimization problem using a system evolution function (explicit ODE or discrete state transition function).
|
|
template<typename T >
requires ScalarLike<T> || MatrixLike<T> |
void | constrain_initial_state (const T &initial_state) |
| Utility function to constrain the initial state.
|
|
template<typename T >
requires ScalarLike<T> || MatrixLike<T> |
void | constrain_final_state (const T &final_state) |
| Utility function to constrain the final state.
|
|
void | for_each_step (const function_ref< void(const VariableMatrix &x, const VariableMatrix &u)> callback) |
| Set the constraint evaluation function.
|
|
void | for_each_step (const function_ref< void(const Variable &t, const VariableMatrix &x, const VariableMatrix &u, const Variable &dt)> callback) |
| Set the constraint evaluation function.
|
|
template<typename T >
requires ScalarLike<T> || MatrixLike<T> |
void | set_lower_input_bound (const T &lower_bound) |
| Convenience function to set a lower bound on the input.
|
|
template<typename T >
requires ScalarLike<T> || MatrixLike<T> |
void | set_upper_input_bound (const T &upper_bound) |
| Convenience function to set an upper bound on the input.
|
|
void | set_min_timestep (std::chrono::duration< double > min_timestep) |
| Convenience function to set a lower bound on the timestep.
|
|
void | set_max_timestep (std::chrono::duration< double > max_timestep) |
| Convenience function to set an upper bound on the timestep.
|
|
VariableMatrix & | X () |
| Get the state variables.
|
|
VariableMatrix & | U () |
| Get the input variables.
|
|
VariableMatrix & | dt () |
| Get the timestep variables.
|
|
VariableMatrix | initial_state () |
| Convenience function to get the initial state in the trajectory.
|
|
VariableMatrix | final_state () |
| Convenience function to get the final state in the trajectory.
|
|
| Problem () noexcept=default |
| Construct the optimization problem.
|
|
Variable | decision_variable () |
| Create a decision variable in the optimization problem.
|
|
VariableMatrix | decision_variable (int rows, int cols=1) |
| Create a matrix of decision variables in the optimization problem.
|
|
VariableMatrix | symmetric_decision_variable (int rows) |
| Create a symmetric matrix of decision variables in the optimization problem.
|
|
void | minimize (const Variable &cost) |
| Tells the solver to minimize the output of the given cost function.
|
|
void | minimize (Variable &&cost) |
| Tells the solver to minimize the output of the given cost function.
|
|
void | maximize (const Variable &objective) |
| Tells the solver to maximize the output of the given objective function.
|
|
void | maximize (Variable &&objective) |
| Tells the solver to maximize the output of the given objective function.
|
|
void | subject_to (const EqualityConstraints &constraint) |
| Tells the solver to solve the problem while satisfying the given equality constraint.
|
|
void | subject_to (EqualityConstraints &&constraint) |
| Tells the solver to solve the problem while satisfying the given equality constraint.
|
|
void | subject_to (const InequalityConstraints &constraint) |
| Tells the solver to solve the problem while satisfying the given inequality constraint.
|
|
void | subject_to (InequalityConstraints &&constraint) |
| Tells the solver to solve the problem while satisfying the given inequality constraint.
|
|
ExpressionType | cost_function_type () const |
| Returns the cost function's type.
|
|
ExpressionType | equality_constraint_type () const |
| Returns the type of the highest order equality constraint.
|
|
ExpressionType | inequality_constraint_type () const |
| Returns the type of the highest order inequality constraint.
|
|
ExitStatus | solve (const Options &options=Options{}, bool spy=false) |
| Solve the optimization problem.
|
|
template<typename F >
requires requires(F callback, const IterationInfo& info) { { callback(info) } -> std::same_as<void>; } |
void | add_callback (F &&callback) |
| Adds a callback to be called at the beginning of each solver iteration.
|
|
template<typename F >
requires requires(F callback, const IterationInfo& info) { { callback(info) } -> std::same_as<bool>; } |
void | add_callback (F &&callback) |
| Adds a callback to be called at the beginning of each solver iteration.
|
|
void | clear_callbacks () |
| Clears the registered callbacks.
|
|
This class allows the user to pose and solve a constrained optimal control problem (OCP) in a variety of ways.
The system is transcripted by one of three methods (direct transcription, direct collocation, or single-shooting) and additional constraints can be added.
In direct transcription, each state is a decision variable constrained to the integrated dynamics of the previous state. In direct collocation, the trajectory is modeled as a series of cubic polynomials where the centerpoint slope is constrained. In single-shooting, states depend explicitly as a function of all previous states and all previous inputs.
Explicit ODEs are integrated using RK4.
For explicit ODEs, the function must be in the form dx/dt = f(t, x, u). For discrete state transition functions, the function must be in the form xₖ₊₁ = f(t, xₖ, uₖ).
Direct collocation requires an explicit ODE. Direct transcription and single-shooting can use either an ODE or state transition function.
https://underactuated.mit.edu/trajopt.html goes into more detail on each transcription method.