31 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR =
double>
35 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
73 size_t nIntegrationSteps)
74 : controlledSystem_(controlledSystem),
75 linearSystem_(linearSystem),
78 controlSpliner_(controlSpliner),
83 costIntegrationCount_(0),
84 sensIntegrationCount_(0),
85 costSensIntegrationCount_(0),
87 discreteQ_(state_vector_t::Zero()),
88 discreteR_(control_vector_t::Zero()),
89 discreteRNext_(control_vector_t::Zero())
91 if (shotNr_ >= settings.
N_)
92 throw std::runtime_error(
"Dms Shot Integrator: shot index >= settings.N_ - check your settings.");
98 integratorCT_ = std::allocate_shared<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>,
99 Eigen::aligned_allocator<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>>>(
100 Eigen::aligned_allocator<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>>(),
106 integratorCT_ = std::allocate_shared<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>,
107 Eigen::aligned_allocator<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>>>(
108 Eigen::aligned_allocator<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>>(),
114 throw std::runtime_error(
"Currently we do not support adaptive integrators in dms");
119 std::cerr <<
"... ERROR: unknown integration type. Exiting" << std::endl;
124 tStart_ = timeGrid_->getShotStartTime(shotNr_);
128 nSteps_ = nIntegrationSteps;
131 integratorCT_->setLinearSystem(linearSystem_);
134 integratorCT_->setCostFunction(costFct_);
142 if ((w_->getUpdateCount() != integrationCount_))
144 integrationCount_ = w_->getUpdateCount();
145 state_vector_t initState = w_->getOptimizedState(shotNr_);
146 integratorCT_->integrate(
147 initState, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_), stateSubsteps_, timeSubsteps_);
153 if ((w_->getUpdateCount() != costIntegrationCount_))
155 costIntegrationCount_ = w_->getUpdateCount();
158 integratorCT_->integrateCost(cost_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
167 if ((w_->getUpdateCount() != sensIntegrationCount_))
169 sensIntegrationCount_ = w_->getUpdateCount();
171 discreteA_.setIdentity();
172 discreteB_.setZero();
173 integratorCT_->linearize();
174 integratorCT_->integrateSensitivityDX0(discreteA_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
175 integratorCT_->integrateSensitivityDU0(discreteB_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
179 discreteBNext_.setZero();
180 integratorCT_->integrateSensitivityDUf(discreteBNext_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
187 if ((w_->getUpdateCount() != costSensIntegrationCount_))
189 costSensIntegrationCount_ = w_->getUpdateCount();
191 discreteQ_.setZero();
192 discreteR_.setZero();
193 integratorCT_->integrateCostSensitivityDX0(discreteQ_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
194 integratorCT_->integrateCostSensitivityDU0(discreteR_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
198 discreteRNext_.setZero();
199 integratorCT_->integrateCostSensitivityDUf(discreteRNext_, tStart_, nSteps_,
SCALAR(settings_.
dt_sim_));
206 integratorCT_->clearStates();
207 integratorCT_->clearSensitivities();
208 integratorCT_->clearLinearization();
260 const state_vector_array_t&
getXHistory()
const {
return stateSubsteps_; }
268 inputSubsteps_.clear();
269 for (
size_t t = 0;
t < timeSubsteps_.size(); ++
t)
271 inputSubsteps_.push_back(controlSpliner_->evalSpline(timeSubsteps_[
t], shotNr_));
273 return inputSubsteps_;
322 std::shared_ptr<ct::core::ControlledSystem<STATE_DIM, CONTROL_DIM, SCALAR>> controlledSystem_;
323 std::shared_ptr<ct::core::LinearSystem<STATE_DIM, CONTROL_DIM, SCALAR>> linearSystem_;
324 std::shared_ptr<ct::optcon::CostFunctionQuadratic<STATE_DIM, CONTROL_DIM, SCALAR>> costFct_;
325 std::shared_ptr<OptVectorDms<STATE_DIM, CONTROL_DIM, SCALAR>> w_;
326 std::shared_ptr<SplinerBase<control_vector_t, SCALAR>> controlSpliner_;
327 std::shared_ptr<tpl::TimeGrid<SCALAR>> timeGrid_;
329 const size_t shotNr_;
332 size_t integrationCount_;
333 size_t costIntegrationCount_;
334 size_t sensIntegrationCount_;
335 size_t costSensIntegrationCount_;
338 state_vector_array_t stateSubsteps_;
339 control_vector_array_t inputSubsteps_;
340 time_array_t timeSubsteps_;
343 state_matrix_t discreteA_;
344 state_control_matrix_t discreteB_;
345 state_control_matrix_t discreteBNext_;
349 state_vector_t discreteQ_;
350 control_vector_t discreteR_;
351 control_vector_t discreteRNext_;
353 std::shared_ptr<SensitivityIntegratorCT<STATE_DIM, CONTROL_DIM, SCALAR>> integratorCT_;
const state_matrix_t & getdXdSiIntegrated()
Returns the integrated ODE sensitivity with respect to the discretized state s_i. ...
Definition: ShotContainer.h:229
Definition: DmsSettings.h:26
Definition: DmsSettings.h:28
const control_vector_t & getdLdQip1Integrated() const
Returns to cost gradient with respect to q_{i+1} integrated over the shot.
Definition: ShotContainer.h:308
const state_vector_array_t & getXHistory() const
Returns the integrated ODE sensitivity with respect to the time segments h_i.
Definition: ShotContainer.h:260
DIMENSIONS::control_vector_t control_vector_t
Definition: ShotContainer.h:40
double dt_sim_
Definition: DmsSettings.h:59
const control_vector_t & getdLdQiIntegrated() const
Returns the cost gradient with respect to q_i integrated over the shot.
Definition: ShotContainer.h:301
Abstract base class for the control input splining between the DMS shots.
Definition: SplinerBase.h:20
void integrateCostSensitivities()
Definition: ShotContainer.h:185
const state_vector_t & getStateIntegrated()
Returns the integrated state.
Definition: ShotContainer.h:216
Definition: DmsSettings.h:29
DIMENSIONS::time_array_t time_array_t
Definition: ShotContainer.h:43
This class is a wrapper around the NLP Optvector. It wraps the Vectors from the NLP solvers into stat...
Definition: OptVectorDms.h:37
clear all close all load ct GNMSLog0 mat reformat t
Definition: gnmsPlot.m:6
Definition: DmsSettings.h:28
This class performs the state and the sensitivity integration on a shot.
Definition: ShotContainer.h:32
const SCALAR getCostIntegrated() const
Gets the cost integrated.
Definition: ShotContainer.h:287
size_t N_
Definition: DmsSettings.h:51
void integrateShot()
Performs the state integration between the shots.
Definition: ShotContainer.h:140
Describes a cost function with a quadratic approximation, i.e. one that can compute first and second ...
Definition: CostFunctionQuadratic.hpp:29
CppAD::AD< CppAD::cg::CG< double > > SCALAR
void integrateSensitivities()
Performs the state and the sensitivity integration between the shots.
Definition: ShotContainer.h:165
DIMENSIONS::state_vector_t state_vector_t
Definition: ShotContainer.h:39
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
ShotContainer(std::shared_ptr< ct::core::ControlledSystem< STATE_DIM, CONTROL_DIM, SCALAR >> controlledSystem, std::shared_ptr< ct::core::LinearSystem< STATE_DIM, CONTROL_DIM, SCALAR >> linearSystem, std::shared_ptr< ct::optcon::CostFunctionQuadratic< STATE_DIM, CONTROL_DIM, SCALAR >> costFct, std::shared_ptr< OptVectorDms< STATE_DIM, CONTROL_DIM, SCALAR >> w, std::shared_ptr< SplinerBase< control_vector_t, SCALAR >> controlSpliner, std::shared_ptr< tpl::TimeGrid< SCALAR >> timeGrid, size_t shotNr, DmsSettings settings, size_t nIntegrationSteps)
Custom constructor.
Definition: ShotContainer.h:65
Definition: TimeGrid.h:27
const state_control_matrix_t & getdXdQip1Integrated()
Returns the integrated ODE sensitivity with respect to the discretized inputs q_{i+1}.
Definition: ShotContainer.h:243
DIMENSIONS::control_vector_array_t control_vector_array_t
Definition: ShotContainer.h:42
SplineType_t splineType_
Definition: DmsSettings.h:54
DIMENSIONS::state_control_matrix_array_t state_control_matrix_array_t
Definition: ShotContainer.h:49
void integrateCost()
Definition: ShotContainer.h:151
const SCALAR getIntegrationTimeFinal()
Returns the end time of the integration.
Definition: ShotContainer.h:222
DIMENSIONS::state_control_matrix_t state_control_matrix_t
Definition: ShotContainer.h:46
Defines the DMS settings.
Definition: DmsSettings.h:23
const state_control_matrix_t & getdXdQiIntegrated()
Returns the integrated ODE sensitivity with respect to the discretized inputs q_i.
Definition: ShotContainer.h:236
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: ShotContainer.h:37
DIMENSIONS::state_matrix_t state_matrix_t
Definition: ShotContainer.h:45
const state_vector_t & getdLdSiIntegrated() const
Returns the cost gradient with respect to s_i integrated over the shot.
Definition: ShotContainer.h:294
CostEvaluationType_t costEvaluationType_
Definition: DmsSettings.h:55
const time_array_t & getTHistory() const
Returns the time trajectory used during the integration.
Definition: ShotContainer.h:281
DIMENSIONS::state_matrix_array_t state_matrix_array_t
Definition: ShotContainer.h:48
void reset()
Definition: ShotContainer.h:204
IntegrationType_t integrationType_
Definition: DmsSettings.h:58
DIMENSIONS::state_vector_array_t state_vector_array_t
Definition: ShotContainer.h:41
const control_vector_array_t & getUHistory()
Returns the control input trajectory used during the state integration.
Definition: ShotContainer.h:266
Definition: DmsSettings.h:28