11 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
18 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
24 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
27 this->
backend_->setInitialGuess(initialGuess);
30 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
38 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
41 bool debugPrint = this->
backend_->getSettings().debugPrint;
43 auto startPrepare = std::chrono::steady_clock::now();
45 if (!this->
backend_->isInitialized())
46 throw std::runtime_error(
"MultipleShooting is not initialized!");
49 throw std::runtime_error(
"MultipleShooting is not configured!");
53 int K = this->
backend_->getNumSteps();
54 int K_shot = this->
backend_->getNumStepsPerShot();
57 if (this->
backend_->iteration() == 0)
59 this->
backend_->rolloutShots(K_shot, K - 1);
62 auto start = std::chrono::steady_clock::now();
63 this->
backend_->setInputBoxConstraintsForLQOCProblem();
64 this->
backend_->setStateBoxConstraintsForLQOCProblem();
65 this->
backend_->computeLQApproximation(K_shot, K - 1);
66 auto end = std::chrono::steady_clock::now();
67 auto diff = end - start;
69 std::cout <<
"[MultipleShooting]: computing LQ Approximation from index " << K_shot <<
" to N-1 took " 70 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
73 std::cout <<
"[MultipleShooting]: Solving prepare stage of LQOC Problem" << std::endl;
75 start = std::chrono::steady_clock::now();
76 this->
backend_->prepareSolveLQProblem(K_shot);
77 end = std::chrono::steady_clock::now();
80 std::cout <<
"[MultipleShooting]: Prepare phase of LQOC problem took " 81 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
83 auto endPrepare = std::chrono::steady_clock::now();
85 std::cout <<
"[MultipleShooting]: prepareIteration() took " 86 << std::chrono::duration<double, std::milli>(endPrepare - startPrepare).count() <<
" ms" << std::endl;
91 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
94 int K_shot = this->
backend_->getNumStepsPerShot();
96 bool debugPrint = this->
backend_->getSettings().debugPrint;
98 auto startFinish = std::chrono::steady_clock::now();
101 if (this->
backend_->iteration() == 0)
103 this->
backend_->rolloutShots(0, K_shot - 1);
105 this->
backend_->computeDefectsNorm();
108 #ifdef MATLAB_FULL_LOG 109 if (this->
backend_->iteration() == 0)
113 auto start = std::chrono::steady_clock::now();
114 this->
backend_->computeLQApproximation(0, K_shot - 1);
115 auto end = std::chrono::steady_clock::now();
116 auto diff = end - start;
118 std::cout <<
"[MultipleShooting]: computing LQ approximation for first multiple-shooting interval took " 119 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
122 std::cout <<
"[MultipleShooting]: Finish phase LQOC Problem" << std::endl;
124 start = std::chrono::steady_clock::now();
125 this->
backend_->finishSolveLQProblem(K_shot - 1);
127 end = std::chrono::steady_clock::now();
130 std::cout <<
"[MultipleShooting]: Finish solving LQOC problem took " 131 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
133 start = std::chrono::steady_clock::now();
134 bool foundBetter = this->
backend_->lineSearch();
135 end = std::chrono::steady_clock::now();
138 std::cout <<
"[MultipleShooting]: Line search took " << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" 144 auto endFinish = std::chrono::steady_clock::now();
145 std::cout <<
"[MultipleShooting]: finishIteration() took " 146 << std::chrono::duration<double, std::milli>(endFinish - startFinish).count() <<
" ms" << std::endl;
152 #ifdef MATLAB_FULL_LOG 154 #endif //MATLAB_FULL_LOG 163 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
166 bool debugPrint = this->
backend_->getSettings().debugPrint;
168 auto startPrepare = std::chrono::steady_clock::now();
170 if (!this->
backend_->isInitialized())
171 throw std::runtime_error(
"MultipleShooting is not initialized!");
173 if (!this->
backend_->isConfigured())
174 throw std::runtime_error(
"MultipleShooting is not configured!");
178 int K = this->
backend_->getNumSteps();
179 int K_shot = this->
backend_->getNumStepsPerShot();
183 this->
backend_->rolloutShots(K_shot, K - 1);
185 auto start = std::chrono::steady_clock::now();
186 this->
backend_->setInputBoxConstraintsForLQOCProblem();
187 this->
backend_->setStateBoxConstraintsForLQOCProblem();
188 this->
backend_->computeLQApproximation(K_shot, K - 1);
189 auto end = std::chrono::steady_clock::now();
190 auto diff = end - start;
192 std::cout <<
"[MultipleShooting-MPC]: computing LQ approximation from index " << K_shot <<
" to N-1 took " 193 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
196 std::cout <<
"[MultipleShooting-MPC]: Solving prepare stage of LQOC Problem" << std::endl;
198 start = std::chrono::steady_clock::now();
199 this->
backend_->prepareSolveLQProblem(K_shot);
200 end = std::chrono::steady_clock::now();
203 std::cout <<
"[MultipleShooting-MPC]: Prepare phase of LQOC problem took " 204 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
207 auto endPrepare = std::chrono::steady_clock::now();
209 std::cout <<
"[MultipleShooting-MPC]: prepareIteration() took " 210 << std::chrono::duration<double, std::milli>(endPrepare - startPrepare).count() <<
" ms" << std::endl;
216 template <
size_t STATE_DIM,
size_t CONTROL_DIM,
size_t P_DIM,
size_t V_DIM,
typename SCALAR,
bool CONTINUOUS>
219 int K_shot = this->
backend_->getNumStepsPerShot();
221 bool debugPrint = this->
backend_->getSettings().debugPrint;
223 auto startFinish = std::chrono::steady_clock::now();
226 this->
backend_->rolloutShots(0, K_shot - 1);
228 this->
backend_->computeDefectsNorm();
231 #ifdef MATLAB_FULL_LOG 232 if (this->
backend_->iteration() == 0)
236 auto start = std::chrono::steady_clock::now();
237 this->
backend_->computeLQApproximation(0, K_shot - 1);
238 auto end = std::chrono::steady_clock::now();
239 auto diff = end - start;
241 std::cout <<
"[MultipleShooting-MPC]: computing LQ approximation for first multiple-shooting interval took " 242 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
245 std::cout <<
"[MultipleShooting-MPC]: Finish phase LQOC Problem" << std::endl;
247 start = std::chrono::steady_clock::now();
248 this->
backend_->finishSolveLQProblem(K_shot - 1);
250 end = std::chrono::steady_clock::now();
253 std::cout <<
"[MultipleShooting-MPC]: Finish solving LQOC problem took " 254 << std::chrono::duration<double, std::milli>(diff).count() <<
" ms" << std::endl;
258 start = std::chrono::steady_clock::now();
261 end = std::chrono::steady_clock::now();
264 std::cout <<
"[MultipleShooting-MPC]: Solution update took " << std::chrono::duration<double, std::milli>(diff).count()
265 <<
" ms" << std::endl;
270 auto endFinish = std::chrono::steady_clock::now();
271 std::cout <<
"[MultipleShooting-MPC]: finishIteration() took " 272 << std::chrono::duration<double, std::milli>(endFinish - startFinish).count() <<
" ms" << std::endl;
277 #ifdef MATLAB_FULL_LOG 279 #endif //MATLAB_FULL_LOG Definition: NLOCAlgorithm.hpp:19
virtual void prepareIteration() override
Definition: MultipleShooting-impl.hpp:39
MultipleShooting(std::shared_ptr< Backend_t > &backend_, const Settings_t &settings)
constructor
Definition: MultipleShooting-impl.hpp:12
virtual bool finishMPCIteration() override
finish iteration, dedicated to MPC
Definition: MultipleShooting-impl.hpp:217
virtual void configure(const Settings_t &settings) override
configure the solver
Definition: MultipleShooting-impl.hpp:19
Base::Policy_t Policy_t
Definition: MultipleShooting.hpp:31
std::shared_ptr< Backend_t > backend_
Definition: NLOCAlgorithm.hpp:47
Settings for the NLOptCon algorithm.
Definition: NLOptConSettings.hpp:198
virtual void prepareMPCIteration() override
prepare iteration, dedicated to MPC.
Definition: MultipleShooting-impl.hpp:164
virtual bool finishIteration() override
finish iteration for unconstrained MultipleShooting
Definition: MultipleShooting-impl.hpp:92
virtual void setInitialGuess(const Policy_t &initialGuess) override
set an initial guess
Definition: MultipleShooting-impl.hpp:25
virtual bool runIteration() override
runIteration combines prepareIteration and finishIteration
Definition: MultipleShooting-impl.hpp:31