33 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR =
double>
37 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
63 std::vector<typename OptConProblem_t::DynamicsPtr_t> systemPtrs,
64 std::vector<typename OptConProblem_t::LinearPtr_t> linearPtrs,
65 std::vector<typename OptConProblem_t::CostFunctionPtr_t> costPtrs,
66 std::vector<typename OptConProblem_t::ConstraintPtr_t> inputBoxConstraints,
67 std::vector<typename OptConProblem_t::ConstraintPtr_t> stateBoxConstraints,
68 std::vector<typename OptConProblem_t::ConstraintPtr_t> generalConstraints,
69 const state_vector_t&
x0)
72 assert(systemPtrs.size() == settings_.
N_);
73 assert(linearPtrs.size() == settings_.
N_);
74 assert(costPtrs.size() == settings_.
N_);
83 controlSpliner_ = std::shared_ptr<ZeroOrderHoldSpliner<control_vector_t, SCALAR>>(
89 controlSpliner_ = std::shared_ptr<LinearSpliner<control_vector_t, SCALAR>>(
94 throw(std::runtime_error(
"Unknown spline type"));
98 size_t wLength = (settings.
N_ + 1) * (STATE_DIM + CONTROL_DIM);
101 throw std::runtime_error(
"We do not support adaptive time gridding");
104 this->
optVariables_ = std::shared_ptr<OptVectorDms<STATE_DIM, CONTROL_DIM, SCALAR>>(
109 if (inputBoxConstraints.size() > 0 || stateBoxConstraints.size() > 0 || generalConstraints.size() > 0)
112 optVariablesDms_, controlSpliner_, timeGrid_, settings_.
N_));
114 if (inputBoxConstraints.size() > 0)
115 discretizedConstraints_->setBoxConstraints(
119 if (stateBoxConstraints.size() > 0)
120 discretizedConstraints_->setBoxConstraints(
124 if (generalConstraints.size() > 0)
125 discretizedConstraints_->setGeneralConstraints(generalConstraints.front());
128 for (
size_t shotIdx = 0; shotIdx < settings_.
N_; shotIdx++)
130 std::shared_ptr<ControllerDms<STATE_DIM, CONTROL_DIM, SCALAR>> newController(
132 systemPtrs[shotIdx]->setController(newController);
133 linearPtrs[shotIdx]->setController(newController);
135 size_t nIntegrationSteps =
136 (timeGrid_->getShotEndTime(shotIdx) - timeGrid_->getShotStartTime(shotIdx)) / settings_.
dt_sim_ + 0.5;
140 costPtrs[shotIdx], optVariablesDms_, controlSpliner_, timeGrid_, shotIdx, settings_,
141 nIntegrationSteps)));
148 this->
costEvaluator_ = std::shared_ptr<CostEvaluatorSimple<STATE_DIM, CONTROL_DIM, SCALAR>>(
150 costPtrs.front(), optVariablesDms_, timeGrid_, settings_));
155 this->
costEvaluator_ = std::shared_ptr<CostEvaluatorFull<STATE_DIM, CONTROL_DIM, SCALAR>>(
157 costPtrs.front(), optVariablesDms_, controlSpliner_, shotContainers_, settings_));
161 throw(std::runtime_error(
"Unknown cost evaluation type"));
164 this->
constraints_ = std::shared_ptr<ConstraintsContainerDms<STATE_DIM, CONTROL_DIM, SCALAR>>(
166 optVariablesDms_, timeGrid_, shotContainers_, discretizedConstraints_,
x0, settings_));
179 controlSpliner_->computeSpline(optVariablesDms_->getOptimizedInputs().toImplementation());
180 for (
auto shotContainer : shotContainers_)
181 shotContainer->reset();
195 const state_vector_array_t&
getStateSolution() {
return optVariablesDms_->getOptimizedStates(); }
201 const control_vector_array_t&
getInputSolution() {
return optVariablesDms_->getOptimizedInputs(); }
219 const control_vector_array_t&
getInputTrajectory() {
return optVariablesDms_->getOptimizedInputs(); }
225 const time_array_t&
getTimeArray() {
return timeGrid_->toImplementation(); }
234 const control_vector_array_t& u_init_guess,
237 optVariablesDms_->setInitGuess(x_init_guess, u_init_guess);
260 optVariablesDms_->changeInitialState(x0);
271 std::shared_ptr<ConstraintDiscretizer<STATE_DIM, CONTROL_DIM, SCALAR>> discretizedConstraints_;
273 std::vector<std::shared_ptr<ShotContainer<STATE_DIM, CONTROL_DIM, SCALAR>>> shotContainers_;
274 std::shared_ptr<OptVectorDms<STATE_DIM, CONTROL_DIM, SCALAR>> optVariablesDms_;
275 std::shared_ptr<SplinerBase<control_vector_t, SCALAR>> controlSpliner_;
276 std::shared_ptr<tpl::TimeGrid<SCALAR>> timeGrid_;
278 state_vector_array_t stateSolutionDense_;
279 control_vector_array_t inputSolutionDense_;
280 time_array_t timeSolutionDense_;
ObjectiveType_t objectiveType_
Definition: DmsSettings.h:56
Definition: DmsSettings.h:26
Definition: DmsSettings.h:27
void changeTimeHorizon(const SCALAR tf)
Updates the timehorizon.
Definition: DmsProblem.h:251
The NLP base class. This class serves as abstract base class to use as an interface to the NLP solver...
Definition: Nlp.h:32
size_t getConstraintsCount() const
Returns the number of constraints in the NLP.
Definition: Nlp.h:212
const control_vector_array_t & getInputTrajectory()
Retrieves a dense input solution trajectory.
Definition: DmsProblem.h:219
void setInitialGuess(const state_vector_array_t &x_init_guess, const control_vector_array_t &u_init_guess, const time_array_t &t_init_guess=time_array_t(0.0))
Sets the initial guess of the optimization.
Definition: DmsProblem.h:233
Performs the full cost integration over the shots.
Definition: CostEvaluatorFull.h:32
DMS controller class.
Definition: ControllerDms.h:30
double dt_sim_
Definition: DmsSettings.h:59
Definition: DmsSettings.h:29
The spline implementation for the zero order hold spliner.
Definition: ZeroOrderHoldSpliner.h:22
const time_array_t & getTimeSolution()
Retrieves the solution time trajectory at every shot.
Definition: DmsProblem.h:207
DIMENSIONS::state_vector_t state_vector_t
Definition: DmsProblem.h:40
double T_
Definition: DmsSettings.h:52
Definition: DmsSettings.h:29
The linear spline implementation.
Definition: LinearSpliner.h:22
This class is a wrapper around the NLP Optvector. It wraps the Vectors from the NLP solvers into stat...
Definition: OptVectorDms.h:37
This class sets up the DMS problem.
Definition: DmsProblem.h:34
std::shared_ptr< DiscreteCostEvaluatorBase< SCALAR > > costEvaluator_
Ptr to cost evaluator, which approximates the cost evaluation for the discrete problem.
Definition: Nlp.h:491
This class performs the state and the sensitivity integration on a shot.
Definition: ShotContainer.h:32
size_t N_
Definition: DmsSettings.h:51
Definition: DmsSettings.h:26
std::shared_ptr< OptVector< SCALAR > > optVariables_
Ptr to optimization variable container, which holds the optimization variables used in the NLP solver...
Definition: Nlp.h:494
const state_vector_array_t & getStateTrajectory()
Retrieves a dense state solution trajectory.
Definition: DmsProblem.h:213
DIMENSIONS::time_array_t time_array_t
Definition: DmsProblem.h:44
const state_vector_array_t & getStateSolution()
Retrieves the solution state trajectory at every shot.
Definition: DmsProblem.h:195
CppAD::AD< CppAD::cg::CG< double > > SCALAR
bool parametersOk() const
Definition: DmsSettings.h:86
const time_array_t & getTimeArray()
Retrieves a dense time solution trajectory.
Definition: DmsProblem.h:225
const control_vector_array_t & getInputSolution()
Retrieves the solution control trajectory at every shot.
Definition: DmsProblem.h:201
ContinuousOptConProblem< STATE_DIM, CONTROL_DIM, SCALAR > OptConProblem_t
Definition: DmsProblem.h:46
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
Definition: TimeGrid.h:27
Container class for the constraints used in DMS.
Definition: ConstraintsContainerDms.h:35
DIMENSIONS::control_vector_t control_vector_t
Definition: DmsProblem.h:42
void updateProblem() override
{ This method gets called at each update of the Optimization variables. This can be used to distribut...
Definition: DmsProblem.h:177
void printSolution()
Prints the solution trajectories.
Definition: DmsProblem.h:266
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: DmsProblem.h:39
void configure(const DmsSettings &settings)
Updates the settings.
Definition: DmsProblem.h:189
SplineType_t splineType_
Definition: DmsSettings.h:54
void changeInitialState(const state_vector_t &x0)
Updates the initial state.
Definition: DmsProblem.h:257
Defines the DMS settings.
Definition: DmsSettings.h:23
Evaluates the cost at the shots and performs some interpolation in between.
Definition: CostEvaluatorSimple.h:33
The class takes continuous constraints defined with the constraint toolbox and discretizes them over ...
Definition: ConstraintDiscretizer.h:30
DmsProblem(DmsSettings settings, std::vector< typename OptConProblem_t::DynamicsPtr_t > systemPtrs, std::vector< typename OptConProblem_t::LinearPtr_t > linearPtrs, std::vector< typename OptConProblem_t::CostFunctionPtr_t > costPtrs, std::vector< typename OptConProblem_t::ConstraintPtr_t > inputBoxConstraints, std::vector< typename OptConProblem_t::ConstraintPtr_t > stateBoxConstraints, std::vector< typename OptConProblem_t::ConstraintPtr_t > generalConstraints, const state_vector_t &x0)
Custom constructor, sets up the objects needed for the Dms algorithm depending on the settings...
Definition: DmsProblem.h:62
const core::Time getTimeHorizon() const
Return the timehorizon of the problem.
Definition: DmsProblem.h:245
DIMENSIONS::control_vector_array_t control_vector_array_t
Definition: DmsProblem.h:41
DIMENSIONS::state_vector_array_t state_vector_array_t
Definition: DmsProblem.h:43
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
~DmsProblem() override=default
Destructor.
std::shared_ptr< DiscreteConstraintContainerBase< SCALAR > > constraints_
Ptr to constraint container, which contains the discretized constraints for the problem.
Definition: Nlp.h:497
CostEvaluationType_t costEvaluationType_
Definition: DmsSettings.h:55
Definition: OptConProblemBase.h:40