aligator  0.6.1
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"
8
9namespace aligator {
10
12template <typename Scalar> struct WorkspaceBaseTpl {
14
15protected:
16 // Whether the workspace was initialized.
18
19public:
21 std::size_t nsteps;
23 TrajOptDataTpl<Scalar> problem_data;
24
27 std::vector<VectorXs> trial_xs;
28 std::vector<VectorXs> trial_us;
30
32 std::vector<VectorXs> dyn_slacks;
33
35
36 explicit WorkspaceBaseTpl(const TrajOptProblemTpl<Scalar> &problem);
37
38 ~WorkspaceBaseTpl() = default;
39
40 bool isInitialized() const { return m_isInitialized; }
41
44 void cycleLeft();
45
49 void cycleAppend(shared_ptr<StageDataTpl<Scalar>> data) {
50 problem_data.stage_data.emplace_back(data);
51 this->cycleLeft();
52 problem_data.stage_data.pop_back();
53 }
54};
55
56/* impl */
57
58template <typename Scalar>
60 const TrajOptProblemTpl<Scalar> &problem)
61 : m_isInitialized(true), nsteps(problem.numSteps()), problem_data(problem) {
62 trial_xs.resize(nsteps + 1);
63 trial_us.resize(nsteps);
64 xs_default_init(problem, trial_xs);
65 us_default_init(problem, trial_us);
66}
67
68template <typename Scalar> void WorkspaceBaseTpl<Scalar>::cycleLeft() {
69 rotate_vec_left(problem_data.stage_data);
70
71 rotate_vec_left(trial_xs);
72 rotate_vec_left(trial_us);
73
74 rotate_vec_left(dyn_slacks, 1);
75}
76
77} // namespace aligator
78
79#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
80#include "./workspace-base.txx"
81#endif
Forward declarations.
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.
std::vector< shared_ptr< StageData > > stage_data
Data structs for each stage of the problem.
Base workspace struct for the algorithms.
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