11 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
16 initialize(optConProblem, settings);
20 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
23 const std::string& settingsFile,
25 const std::string& ns)
30 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
35 nlocAlgorithm_ = std::shared_ptr<NLOCAlgorithm<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>>(
40 nlocAlgorithm_ = std::shared_ptr<NLOCAlgorithm<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>>(
45 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
57 setAlgorithm(settings);
61 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
65 throw std::runtime_error(
"cannot switch from ST to MT or vice versa. Please call initialize.");
69 setAlgorithm(settings);
73 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
80 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
87 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
94 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
101 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
105 auto startSolve = std::chrono::steady_clock::now();
109 auto endSolve = std::chrono::steady_clock::now();
110 std::cout <<
"[NLOC]: runIteration() took " 111 << std::chrono::duration<double, std::milli>(endSolve - startSolve).count() <<
" ms" << std::endl;
117 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
125 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
128 bool foundBetter =
true;
129 int numIterations = 0;
131 while (foundBetter && (numIterations < nlocBackend_->
getSettings().max_iterations))
138 return (numIterations > 1 || foundBetter || (numIterations == 1 && !foundBetter));
142 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
150 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
158 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
166 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
174 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
181 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
188 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
196 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
198 const typename OptConProblem_t::CostFunctionPtr_t& cf)
204 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
206 const typename OptConProblem_t::DynamicsPtr_t& dyn)
212 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
214 const typename OptConProblem_t::LinearPtr_t& lin)
220 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
227 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
235 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
236 const std::shared_ptr<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::Backend_t>&
243 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
252 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
261 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
270 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
279 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
280 std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
288 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
289 const std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
297 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
298 std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
306 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
307 const std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
314 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
315 std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
323 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
324 const std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
332 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
333 std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
341 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
342 const std::vector<typename NLOptConSolver<STATE_DIM, CONTROL_DIM, P_DIM, V_DIM, SCALAR, CONTINUOUS>::OptConProblem_t::
350 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
352 const std::string& fileName)
virtual const core::StateTrajectory< STATE_DIM, SCALAR > getStateTrajectory() const override
Definition: NLOptConSolver-impl.hpp:152
void initialize(const OptConProblem_t &optConProblem, const Settings_t &settings)
Definition: NLOptConSolver-impl.hpp:46
std::vector< typename OptConProblem_t::LinearPtr_t > & getLinearSystemsInstances() override
get reference to the linearized system
Definition: NLOptConSolver-impl.hpp:264
virtual SCALAR getTimeHorizon() const override
Get the time horizon the solver currently operates on.
Definition: NLOptConSolver-impl.hpp:175
void logSummaryToMatlab(const std::string &fileName)
logging a short summary to matlab
Definition: NLOptConSolver-impl.hpp:351
virtual const core::ControlTrajectory< CONTROL_DIM, SCALAR > getControlTrajectory() const override
Definition: NLOptConSolver-impl.hpp:160
const std::shared_ptr< Backend_t > & getBackend()
get a reference to the backend (
Definition: NLOptConSolver-impl.hpp:237
virtual void changeLinearSystem(const typename OptConProblem_t::LinearPtr_t &lin) override
Change the linear system.
Definition: NLOptConSolver-impl.hpp:213
std::vector< typename OptConProblem_t::ConstraintPtr_t > & getGeneralConstraintsInstances() override
get reference to the general constraints
Definition: NLOptConSolver-impl.hpp:335
NLOptConSolver(const OptConProblem_t &optConProblem, const Settings_t &settings)
constructor
Definition: NLOptConSolver-impl.hpp:12
std::vector< typename OptConProblem_t::DynamicsPtr_t > & getNonlinearSystemsInstances() override
get reference to the nonlinear system
Definition: NLOptConSolver-impl.hpp:246
NLOCAlgorithm_t::Policy_t Policy_t
Definition: NLOptConSolver.hpp:62
std::vector< typename OptConProblem_t::CostFunctionPtr_t > & getCostFunctionInstances() override
get reference to the cost function
Definition: NLOptConSolver-impl.hpp:282
bool isSingleShooting() const
return if this is a single-shooting algorithm (or not)
Definition: NLOptConSettings.hpp:306
virtual void changeNonlinearSystem(const typename OptConProblem_t::DynamicsPtr_t &dyn) override
Change the nonlinear system.
Definition: NLOptConSolver-impl.hpp:205
void configure(const Settings_t &settings) override
Definition: NLOptConSolver-impl.hpp:62
virtual void prepareIteration()
Definition: NLOptConSolver-impl.hpp:74
virtual void changeInitialState(const core::StateVector< STATE_DIM, SCALAR > &x0) override
Change the initial state for the optimal control problem.
Definition: NLOptConSolver-impl.hpp:189
void setInitialGuess(const Policy_t &initialGuess) override
Definition: NLOptConSolver-impl.hpp:118
Definition: SingleShooting.hpp:21
Definition: NLOCBackendST.hpp:25
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
CppAD::AD< CppAD::cg::CG< double > > SCALAR
virtual bool solve() override
Definition: NLOptConSolver-impl.hpp:126
virtual const core::tpl::TimeArray< SCALAR > & getTimeArray() const override
Definition: NLOptConSolver-impl.hpp:168
std::vector< typename OptConProblem_t::ConstraintPtr_t > & getStateBoxConstraintsInstances() override
get reference to the box constraints
Definition: NLOptConSolver-impl.hpp:317
std::vector< typename OptConProblem_t::ConstraintPtr_t > & getInputBoxConstraintsInstances() override
get reference to the box constraints
Definition: NLOptConSolver-impl.hpp:300
std::shared_ptr< Backend_t > nlocBackend_
the backend holding all the math operations
Definition: NLOptConSolver.hpp:247
virtual bool finishMPCIteration()
Definition: NLOptConSolver-impl.hpp:95
virtual bool runIteration() override
Definition: NLOptConSolver-impl.hpp:102
virtual SCALAR getCost() const override
Definition: NLOptConSolver-impl.hpp:221
virtual const Policy_t & getSolution() override
Definition: NLOptConSolver-impl.hpp:144
const Settings_t & getSettings()
get a reference to the current settings
Definition: NLOptConSolver-impl.hpp:229
virtual void changeCostFunction(const typename OptConProblem_t::CostFunctionPtr_t &cf) override
Change the cost function.
Definition: NLOptConSolver-impl.hpp:197
virtual bool finishIteration()
Definition: NLOptConSolver-impl.hpp:81
Definition: NLOCBackendMP.hpp:31
Base::OptConProblem_t OptConProblem_t
Definition: NLOptConSolver.hpp:59
virtual void changeTimeHorizon(const SCALAR &tf) override
Change the time horizon the solver operates on.
Definition: NLOptConSolver-impl.hpp:182
Definition: MultipleShooting.hpp:21
StateVector< state_dim > x0
Definition: ConstrainedNLOCTest.cpp:14
std::shared_ptr< NLOCAlgorithm_t > nlocAlgorithm_
the algorithm for sequencing the math operations in correct manner
Definition: NLOptConSolver.hpp:250
const bool verbose
Definition: ConstraintComparison.h:18
int nThreads
save the smallest eigenvalue of the Hessian
Definition: NLOptConSettings.hpp:272
Definition: NLOptConSolver.hpp:29
virtual void prepareMPCIteration()
Definition: NLOptConSolver-impl.hpp:88