aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
workspace-base.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include "aligator/fwd.hpp"
9
10namespace aligator {
11
13template <typename Scalar> struct WorkspaceBaseTpl {
15
16protected:
17 // Whether the workspace was initialized.
19
20public:
22 std::size_t nsteps;
25
28 std::vector<VectorXs> trial_xs;
29 std::vector<VectorXs> trial_us;
31
33 std::vector<VectorXs> dyn_slacks;
34
36
37 explicit WorkspaceBaseTpl(const TrajOptProblemTpl<Scalar> &problem);
38
39 ~WorkspaceBaseTpl() = default;
40
41 bool isInitialized() const { return m_isInitialized; }
42
45 void cycleLeft();
46
50 void cycleAppend(shared_ptr<StageDataTpl<Scalar>> data) {
51 problem_data.stage_data.emplace_back(data);
52 this->cycleLeft();
53 problem_data.stage_data.pop_back();
54 }
55};
56
57/* impl */
58
59template <typename Scalar>
61 const TrajOptProblemTpl<Scalar> &problem)
62 : m_isInitialized(true), nsteps(problem.numSteps()), problem_data(problem) {
63 trial_xs.resize(nsteps + 1);
64 trial_us.resize(nsteps);
65 xs_default_init(problem, trial_xs);
66 us_default_init(problem, trial_us);
67}
68
69template <typename Scalar> void WorkspaceBaseTpl<Scalar>::cycleLeft() {
70 rotate_vec_left(problem_data.stage_data);
71
72 rotate_vec_left(trial_xs);
73 rotate_vec_left(trial_us);
74
75 rotate_vec_left(dyn_slacks, 1);
76}
77
78} // namespace aligator
79
80#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
81#include "./workspace-base.txx"
82#endif
Forward declarations.
Utils for model-predictive control.
Main package namespace.
void rotate_vec_left(std::vector< T, Alloc > &v, long n_head=0, long n_tail=0)
Simply rotate an entire std::vector to the left.
Definition mpc-util.hpp:17
void us_default_init(const TrajOptProblemTpl< Scalar > &problem, std::vector< typename math_types< Scalar >::VectorXs > &us)
Default-initialize a controls trajectory from the neutral element of each control space.
void xs_default_init(const TrajOptProblemTpl< Scalar > &problem, std::vector< typename math_types< Scalar >::VectorXs > &xs)
Default-intialize a trajectory to the neutral states for each state space at each stage.
Common utilities for all solvers.
Data struct for stage models StageModelTpl.
Definition fwd.hpp:96
Problem data struct.
Definition fwd.hpp:110
std::vector< shared_ptr< StageData > > stage_data
Data structs for each stage of the problem.
Trajectory optimization problem.
Definition fwd.hpp:107
std::size_t nsteps
Number of steps in the problem.
std::vector< VectorXs > trial_us
TrajOptDataTpl< Scalar > problem_data
Problem data.
void cycleLeft()
Cycle the workspace data to the left.
std::vector< VectorXs > dyn_slacks
Dynamical infeasibility gaps.
void cycleAppend(shared_ptr< StageDataTpl< Scalar > > data)
Same as cycleLeft(), but add a StageDataTpl to problem_data.
std::vector< VectorXs > trial_xs