14 #include <ct/optcon/nlp/Nlp> 33 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR =
double>
36 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
58 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
typename SCALAR =
double>
60 DmsPolicy<STATE_DIM, CONTROL_DIM, SCALAR>,
67 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
83 typedef DmsPolicy<STATE_DIM, CONTROL_DIM, SCALAR>
Policy_t;
94 : nlpSolver_(nullptr), settings_(settingsDms)
97 this->setProblem(problem);
101 settingsDms, this->systems_, this->linearSystems_, this->costFunctions_, this->inputBoxConstraints_,
102 this->stateBoxConstraints_, this->generalConstraints_, x0_));
106 nlpSolver_ = std::shared_ptr<SnoptSolver>(
new SnoptSolver(dmsProblem_, settingsDms.solverSettings_));
108 nlpSolver_ = std::shared_ptr<IpoptSolver>(
new IpoptSolver(dmsProblem_, settingsDms.solverSettings_));
110 std::cout <<
"Unknown solver type... Exiting" << std::endl;
112 configure(settingsDms);
123 dmsProblem_->configure(settings);
124 dmsProblem_->changeTimeHorizon(tf_);
125 dmsProblem_->changeInitialState(x0_);
130 if (!nlpSolver_->isInitialized())
131 nlpSolver_->configure(settings_.solverSettings_);
133 return nlpSolver_->solve();
138 policy_.
xSolution_ = dmsProblem_->getStateSolution();
139 policy_.uSolution_ = dmsProblem_->getInputSolution();
140 policy_.tSolution_ = dmsProblem_->getTimeSolution();
152 dmsProblem_->getTimeArray(), dmsProblem_->getInputTrajectory());
166 dmsProblem_->changeTimeHorizon(tf);
173 dmsProblem_->changeInitialState(x0);
178 this->getCostFunctionInstances().resize(settings_.N_);
180 for (
size_t i = 0;
i < settings_.N_;
i++)
181 this->getCostFunctionInstances()[
i] =
typename Base::OptConProblem_t::CostFunctionPtr_t(cf->clone());
186 this->getNonlinearSystemsInstances().resize(settings_.N_);
189 for (
size_t i = 0;
i < settings_.N_;
i++)
190 this->getNonlinearSystemsInstances()[
i] =
typename Base::OptConProblem_t::DynamicsPtr_t(dyn->clone());
195 this->getLinearSystemsInstances().resize(settings_.N_);
198 for (
size_t i = 0;
i < settings_.N_;
i++)
199 this->getLinearSystemsInstances()[
i] =
typename Base::OptConProblem_t::LinearPtr_t(lin->clone());
204 this->getInputBoxConstraintsInstances().push_back(
205 typename Base::OptConProblem_t::ConstraintPtr_t(con->clone()));
210 this->getStateBoxConstraintsInstances().push_back(
211 typename Base::OptConProblem_t::ConstraintPtr_t(con->clone()));
216 this->getGeneralConstraintsInstances().push_back(
typename Base::OptConProblem_t::ConstraintPtr_t(con->clone()));
232 return linearSystems_;
237 return costFunctions_;
241 return costFunctions_;
246 return inputBoxConstraints_;
251 return inputBoxConstraints_;
256 return stateBoxConstraints_;
261 return stateBoxConstraints_;
266 return generalConstraints_;
270 return generalConstraints_;
275 std::shared_ptr<DmsProblem<STATE_DIM, CONTROL_DIM, SCALAR>> dmsProblem_;
276 std::shared_ptr<tpl::NlpSolver<SCALAR>> nlpSolver_;
277 DmsSettings settings_;
284 std::vector<typename OptConProblem_t::DynamicsPtr_t> systems_;
285 std::vector<typename OptConProblem_t::LinearPtr_t> linearSystems_;
286 std::vector<typename OptConProblem_t::CostFunctionPtr_t> costFunctions_;
287 std::vector<typename OptConProblem_t::ConstraintPtr_t> inputBoxConstraints_;
288 std::vector<typename OptConProblem_t::ConstraintPtr_t> stateBoxConstraints_;
289 std::vector<typename OptConProblem_t::ConstraintPtr_t> generalConstraints_;
void changeGeneralConstraints(const typename Base::OptConProblem_t::ConstraintPtr_t con) override
Definition: DmsSolver.h:214
const core::tpl::TimeArray< SCALAR > & getTimeArray() const override
Definition: DmsSolver.h:155
void changeTimeHorizon(const SCALAR &tf) override
Change the time horizon the solver operates on.
Definition: DmsSolver.h:162
Definition: OptConSolver.h:39
bool solve() override
Definition: DmsSolver.h:128
const std::vector< typename OptConProblem_t::ConstraintPtr_t > & getGeneralConstraintsInstances() const override
Definition: DmsSolver.h:268
DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: DmsSolver.h:76
const std::vector< typename OptConProblem_t::DynamicsPtr_t > & getNonlinearSystemsInstances() const override
Definition: DmsSolver.h:224
std::vector< typename OptConProblem_t::ConstraintPtr_t > & getInputBoxConstraintsInstances() override
Direct accessor to the box constraint instances.
Definition: DmsSolver.h:244
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef DmsDimensions< STATE_DIM, CONTROL_DIM, SCALAR > DIMENSIONS
Definition: DmsSolver.h:37
const std::vector< typename OptConProblem_t::ConstraintPtr_t > & getInputBoxConstraintsInstances() const override
Definition: DmsSolver.h:249
DmsPolicy< STATE_DIM, CONTROL_DIM, SCALAR > Policy_t
Definition: DmsSolver.h:83
DIMENSIONS::control_vector_t control_vector_t
Definition: DmsSolver.h:79
DIMENSIONS::state_vector_t state_vector_t
Definition: DmsSolver.h:77
void configure(const DmsSettings &settings) override
Definition: DmsSolver.h:121
std::vector< typename OptConProblem_t::ConstraintPtr_t > & getStateBoxConstraintsInstances() override
Definition: DmsSolver.h:254
void changeNonlinearSystem(const typename Base::OptConProblem_t::DynamicsPtr_t &dyn) override
Definition: DmsSolver.h:184
void printSolution()
Prints out the solution trajectories of the DMS problem.
Definition: DmsSolver.h:222
The DMS policy used as a solution container.
Definition: DmsSolver.h:34
const std::vector< typename OptConProblem_t::CostFunctionPtr_t > & getCostFunctionInstances() const override
Definition: DmsSolver.h:239
std::vector< typename OptConProblem_t::CostFunctionPtr_t > & getCostFunctionInstances() override
Direct accessor to the cost function instances.
Definition: DmsSolver.h:235
This class sets up the DMS problem.
Definition: DmsProblem.h:34
DIMENSIONS::control_vector_array_t control_vector_array_t
Definition: DmsSolver.h:39
control_vector_array_t uSolution_
Definition: DmsSolver.h:43
DIMENSIONS::control_vector_array_t control_vector_array_t
Definition: DmsSolver.h:78
std::vector< typename OptConProblem_t::DynamicsPtr_t > & getNonlinearSystemsInstances() override
Direct accessor to the system instances.
Definition: DmsSolver.h:223
DIMENSIONS::state_vector_array_t state_vector_array_t
Definition: DmsSolver.h:38
CppAD::AD< CppAD::cg::CG< double > > SCALAR
const std::vector< typename OptConProblem_t::LinearPtr_t > & getLinearSystemsInstances() const override
Definition: DmsSolver.h:230
void changeLinearSystem(const typename Base::OptConProblem_t::LinearPtr_t &lin) override
Definition: DmsSolver.h:193
Defines basic types used in the DMS algorithm.
Definition: DmsDimensions.h:18
void changeStateBoxConstraints(const typename Base::OptConProblem_t::ConstraintPtr_t con) override
Definition: DmsSolver.h:208
void changeInitialState(const core::StateVector< STATE_DIM, SCALAR > &x0) override
Change the initial state for the optimal control problem.
Definition: DmsSolver.h:169
for i
Definition: mpc_unittest_plotting.m:14
time_array_t tSolution_
Definition: DmsSolver.h:44
void changeInputBoxConstraints(const typename Base::OptConProblem_t::ConstraintPtr_t con) override
Definition: DmsSolver.h:202
DmsSolver(const ContinuousOptConProblem< STATE_DIM, CONTROL_DIM, SCALAR > problem, DmsSettings settingsDms)
Custom constructor, converts the optcon problem to a DMS problem.
Definition: DmsSolver.h:93
DIMENSIONS::state_vector_array_t state_vector_array_t
Definition: DmsSolver.h:80
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef OptConSolver< DmsSolver< STATE_DIM, CONTROL_DIM, SCALAR >, DmsPolicy< STATE_DIM, CONTROL_DIM, SCALAR >, DmsSettings, STATE_DIM, CONTROL_DIM > Base
Definition: DmsSolver.h:74
ContinuousOptConProblem< STATE_DIM, CONTROL_DIM, SCALAR > OptConProblem_t
Definition: DmsSolver.h:85
state_vector_array_t xSolution_
Definition: DmsSolver.h:42
const std::vector< typename OptConProblem_t::ConstraintPtr_t > & getStateBoxConstraintsInstances() const override
Definition: DmsSolver.h:259
tpl::IpoptSolver< double > IpoptSolver
Definition: IpoptSolver.h:200
Defines the DMS settings.
Definition: DmsSettings.h:23
std::vector< typename OptConProblem_t::ConstraintPtr_t > & getGeneralConstraintsInstances() override
Direct accessor to the general constraints.
Definition: DmsSolver.h:264
Class to solve a specfic DMS problem.
Definition: DmsSolver.h:59
Definition: SnoptSolver.h:297
DIMENSIONS::time_array_t time_array_t
Definition: DmsSolver.h:81
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
SCALAR getTimeHorizon() const override
Get the time horizon the solver currently operates on.
Definition: DmsSolver.h:161
const Policy_t & getSolution() override
Definition: DmsSolver.h:136
void setInitialGuess(const Policy_t &initialGuess) override
Definition: DmsSolver.h:156
std::vector< typename OptConProblem_t::LinearPtr_t > & getLinearSystemsInstances() override
Direct accessor to the linear system instances.
Definition: DmsSolver.h:229
const core::ControlTrajectory< CONTROL_DIM, SCALAR > getControlTrajectory() const override
Definition: DmsSolver.h:149
Definition: OptConProblemBase.h:40
DIMENSIONS::time_array_t time_array_t
Definition: DmsSolver.h:40
const core::StateTrajectory< STATE_DIM, SCALAR > getStateTrajectory() const override
Definition: DmsSolver.h:144
void changeCostFunction(const typename Base::OptConProblem_t::CostFunctionPtr_t &cf) override
Definition: DmsSolver.h:176