aligator  0.10.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
traj-opt-problem.hpp
Go to the documentation of this file.
1
3#pragma once
4
7
8namespace aligator {
9
23template <typename _Scalar> struct TrajOptProblemTpl {
24 using Scalar = _Scalar;
29 using Manifold = ManifoldAbstractTpl<Scalar>;
33#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
36#pragma GCC diagnostic pop
37
93
95 xyz::polymorphic<UnaryFunction> init_constraint_;
97 std::vector<xyz::polymorphic<StageModel>> stages_;
99 xyz::polymorphic<CostAbstract> term_cost_;
103 VectorXs unone_;
104
106
108 TrajOptProblemTpl(xyz::polymorphic<UnaryFunction> init_constraint,
109 const std::vector<xyz::polymorphic<StageModel>> &stages,
110 xyz::polymorphic<CostAbstract> term_cost);
111
114 TrajOptProblemTpl(const ConstVectorRef &x0,
115 const std::vector<xyz::polymorphic<StageModel>> &stages,
116 xyz::polymorphic<CostAbstract> term_cost);
117
119
121 TrajOptProblemTpl(xyz::polymorphic<UnaryFunction> init_constraint,
122 xyz::polymorphic<CostAbstract> term_cost);
123
126 TrajOptProblemTpl(const ConstVectorRef &x0, const int nu,
127 xyz::polymorphic<Manifold> space,
128 xyz::polymorphic<CostAbstract> term_cost);
129
130 bool initCondIsStateError() const { return init_state_error_ != nullptr; }
131
133 void addStage(const xyz::polymorphic<StageModel> &stage);
134
136 ConstVectorRef getInitState() const {
137 if (!initCondIsStateError()) {
139 "Initial condition is not a StateErrorResidual.\n");
140 }
142 }
143
145 void setInitState(const ConstVectorRef &x0) {
146 if (!initCondIsStateError()) {
148 "Initial condition is not a StateErrorResidual.\n");
149 }
151 }
152
154 ALIGATOR_DEPRECATED void addTerminalConstraint(const StageConstraint &cstr);
155 void addTerminalConstraint(const xyz::polymorphic<StageFunction> &func,
156 const xyz::polymorphic<ConstraintSet> &set) {
157 this->term_cstrs_.pushBack(func, set);
158 }
161
162 std::size_t numSteps() const;
163
165 Scalar evaluate(const std::vector<VectorXs> &xs,
166 const std::vector<VectorXs> &us, Data &prob_data,
167 std::size_t num_threads = 1) const;
168
178 void computeDerivatives(const std::vector<VectorXs> &xs,
179 const std::vector<VectorXs> &us, Data &prob_data,
180 std::size_t num_threads = 1,
181 bool compute_second_order = true) const;
182
185 void replaceStageCircular(const xyz::polymorphic<StageModel> &model);
186
187 bool checkIntegrity() const;
188
189protected:
192};
193
194namespace internal {
195template <typename Scalar>
196auto problem_last_state_space_helper(const TrajOptProblemTpl<Scalar> &problem) {
197 return problem.term_cost_->space;
198}
199
201template <typename Scalar>
202int problem_last_ndx_helper(const TrajOptProblemTpl<Scalar> &problem) {
203 return problem_last_state_space_helper(problem)->ndx();
204}
205} // namespace internal
206
207} // namespace aligator
208
209#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
210#include "aligator/core/traj-opt-problem.txx"
211#endif
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
TrajOptProblemTpl(xyz::polymorphic< UnaryFunction > init_constraint, const std::vector< xyz::polymorphic< StageModel > > &stages, xyz::polymorphic< CostAbstract > term_cost)
TrajOptProblemTpl(const ConstVectorRef &x0, const std::vector< xyz::polymorphic< StageModel > > &stages, xyz::polymorphic< CostAbstract > term_cost)
Constructor for an initial value problem.
TrajOptProblemTpl(xyz::polymorphic< UnaryFunction > init_constraint, xyz::polymorphic< CostAbstract > term_cost)
TrajOptProblemTpl(const ConstVectorRef &x0, const int nu, xyz::polymorphic< Manifold > space, xyz::polymorphic< CostAbstract > term_cost)
Constructor for an initial value problem.
Main package namespace.
proxsuite::nlp::ConstraintSetBase< T > ConstraintSetTpl
TYPEDEFS FROM PROXNLP.
Definition fwd.hpp:38
Convenience class to manage a stack of constraints.
Definition fwd.hpp:101
ALIGATOR_DEPRECATED void pushBack(Cstr &&el)
Stage costs for control problems.
Definition fwd.hpp:62
Simple struct holding together a function and set, to describe a constraint.
Definition fwd.hpp:74
Class representing ternary functions .
Definition fwd.hpp:53
A stage in the control problem.
Definition fwd.hpp:90
Problem data struct.
Definition fwd.hpp:107
Trajectory optimization problem.
Definition fwd.hpp:104
xyz::polymorphic< CostAbstract > term_cost_
Terminal cost.
xyz::polymorphic< UnaryFunction > init_constraint_
Initial condition.
ConstraintStackTpl< Scalar > term_cstrs_
Terminal constraints.
Scalar evaluate(const std::vector< VectorXs > &xs, const std::vector< VectorXs > &us, Data &prob_data, std::size_t num_threads=1) const
Rollout the problem costs, constraints, dynamics, stage per stage.
void setInitState(const ConstVectorRef &x0)
Set initial state constraint.
ManifoldAbstractTpl< Scalar > Manifold
void addStage(const xyz::polymorphic< StageModel > &stage)
Add a stage to the control problem.
void replaceStageCircular(const xyz::polymorphic< StageModel > &model)
Pop out the first StageModel and replace by the supplied one; updates the supplied problem data (Traj...
void addTerminalConstraint(const xyz::polymorphic< StageFunction > &func, const xyz::polymorphic< ConstraintSet > &set)
std::size_t numSteps() const
std::vector< xyz::polymorphic< StageModel > > stages_
Stages of the control problem.
void computeDerivatives(const std::vector< VectorXs > &xs, const std::vector< VectorXs > &us, Data &prob_data, std::size_t num_threads=1, bool compute_second_order=true) const
Rollout the problem derivatives, stage per stage.
void removeTerminalConstraints()
Remove all terminal constraints.
StateErrorResidual * init_state_error_
Pointer to underlying state error residual.
ConstraintSetTpl< Scalar > ConstraintSet
ALIGATOR_DEPRECATED void addTerminalConstraint(const StageConstraint &cstr)
Add a terminal constraint for the model.
ConstVectorRef getInitState() const
Get initial state constraint.
VectorXs unone_
Dummy, "neutral" control value.
Represents unary functions of the form , with no control (or next-state) arguments.
Definition fwd.hpp:56