aico_solver.cpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 // This code is based on algorithm developed by Marc Toussaint
31 // M. Toussaint: Robot Trajectory Optimization using Approximate Inference. In Proc. of the Int. Conf. on Machine Learning (ICML 2009), 1049-1056, ACM, 2009.
32 // http://ipvs.informatik.uni-stuttgart.de/mlr/papers/09-toussaint-ICML.pdf
33 // Original code available at http://ipvs.informatik.uni-stuttgart.de/mlr/marc/source-code/index.html
34 
37 
39 #include <exotica_core/server.h>
40 
42 
43 namespace exotica
44 {
45 void AICOSolver::Instantiate(const AICOSolverInitializer& init)
46 {
47  std::string mode = init.SweepMode;
48  if (mode == "Forwardly")
49  sweep_mode_ = FORWARD;
50  else if (mode == "Symmetric")
51  sweep_mode_ = SYMMETRIC;
52  else if (mode == "LocalGaussNewton")
53  sweep_mode_ = LOCAL_GAUSS_NEWTON;
54  else if (mode == "LocalGaussNewtonDamped")
55  sweep_mode_ = LOCAL_GAUSS_NEWTON_DAMPED;
56  else
57  {
58  ThrowNamed("Unknown sweep mode '" << init.SweepMode << "'");
59  }
60  max_backtrack_iterations_ = init.MaxBacktrackIterations;
61  minimum_step_tolerance_ = init.MinStep;
62  step_tolerance_ = init.StepTolerance;
63  function_tolerance_ = init.FunctionTolerance;
64  damping_init_ = init.Damping;
65  use_bwd_msg_ = init.UseBackwardMessage;
66  verbose_ = init.Verbose;
67 }
68 
69 AICOSolver::AICOSolver() = default;
70 
71 AICOSolver::~AICOSolver() = default;
72 
73 void AICOSolver::SpecifyProblem(PlanningProblemPtr problem)
74 {
75  if (problem->type() != "exotica::UnconstrainedTimeIndexedProblem")
76  {
77  ThrowNamed("This solver can't use problem of type '" << problem->type() << "'!");
78  }
79  MotionSolver::SpecifyProblem(problem);
80  prob_ = std::static_pointer_cast<UnconstrainedTimeIndexedProblem>(problem);
81 
82  InitMessages();
83 }
84 
85 void AICOSolver::Solve(Eigen::MatrixXd& solution)
86 {
87  prob_->PreUpdate();
88  prob_->ResetCostEvolution(GetNumberOfMaxIterations() + 1);
89  prob_->termination_criterion = TerminationCriterion::NotStarted;
90  planning_time_ = -1;
91 
92  Eigen::VectorXd q0 = prob_->ApplyStartState();
93  std::vector<Eigen::VectorXd> q_init = prob_->GetInitialTrajectory();
94 
95  // If the initial value of the initial trajectory does not equal the start
96  // state, assume that no initial guess is provided and fill the trajectory
97  // with the start state
98  if (!q0.isApprox(q_init[0]))
99  {
100  if (verbose_) HIGHLIGHT("AICO::Solve cold-started");
101  q_init.assign(prob_->GetT(), q0);
102  }
103  else
104  {
105  if (verbose_) HIGHLIGHT("AICO::Solve called with initial trajectory guess");
106  }
107 
108  prob_->SetStartState(q_init[0]);
109  prob_->ApplyStartState();
110 
111  // Check if the trajectory length has changed, if so update the messages.
112  if (prob_->GetT() != last_T_) InitMessages();
113 
114  Timer timer;
115  if (verbose_) ROS_WARN_STREAM("AICO: Setting up the solver");
116  update_count_ = 0;
117  damping = damping_init_;
118  double d;
119  if (prob_->GetT() <= 0)
120  {
121  ThrowNamed("Problem has not been initialized properly: T=0!");
122  }
123  iteration_count_ = -1;
124  InitTrajectory(q_init);
125  if (verbose_) ROS_WARN_STREAM("AICO: Solving");
126 
127  // Reset sweep and iteration count
128  sweep_ = 0;
129  iteration_count_ = 0;
130  while (iteration_count_ < GetNumberOfMaxIterations())
131  {
132  // Check whether user interrupted (Ctrl+C)
133  if (Server::IsRos() && !ros::ok())
134  {
135  if (debug_) HIGHLIGHT("Solving cancelled by user");
136  prob_->termination_criterion = TerminationCriterion::UserDefined;
137  break;
138  }
139 
140  d = Step();
141  if (d < 0)
142  {
143  ThrowNamed("Negative step size!");
144  }
145 
146  // 0. Check maximum backtrack iterations
147  if (damping != 0.0 && sweep_ >= max_backtrack_iterations_)
148  {
149  if (debug_) HIGHLIGHT("Maximum backtrack iterations reached, exiting.");
150  prob_->termination_criterion = TerminationCriterion::BacktrackIterationLimit;
151  break;
152  }
153 
154  // Check stopping criteria
155  if (iteration_count_ > 1)
156  {
157  // Check convergence if
158  // a) damping is on and the iteration has concluded (the sweep improved the cost)
159  // b) damping is off [each sweep equals one iteration]
160  if ((damping != 0.0 && sweep_improved_cost_) || !(damping != 0.0))
161  {
162  // 1. Check step tolerance
163  // || x_t-x_t-1 || <= stepTolerance * max(1, || x_t ||)
164  // TODO(#257): TODO(#256): move to Eigen::MatrixXd to make this easier to compute, in the meantime use old check
165  //
166  // TODO(#256): OLD TOLERANCE CHECK - TODO REMOVE
167  if (d < minimum_step_tolerance_)
168  {
169  if (debug_) HIGHLIGHT("Satisfied tolerance\titer=" << iteration_count_ << "\td=" << d << "\tminimum_step_tolerance=" << minimum_step_tolerance_);
170  prob_->termination_criterion = TerminationCriterion::StepTolerance;
171  break;
172  }
173 
174  // 2. Check function tolerance
175  // (f_t-1 - f_t) <= functionTolerance * max(1, abs(f_t))
176  if ((cost_prev_ - cost_) <= function_tolerance_ * std::max(1.0, std::abs(cost_)))
177  {
178  if (debug_) HIGHLIGHT("Function tolerance achieved: " << (cost_prev_ - cost_) << " <= " << function_tolerance_ * std::max(1.0, std::abs(cost_)));
179  prob_->termination_criterion = TerminationCriterion::FunctionTolerance;
180  break;
181  }
182  cost_prev_ = cost_;
183  }
184  }
185  }
186 
187  // Check whether maximum iteration count was reached
188  if (iteration_count_ == GetNumberOfMaxIterations())
189  {
190  if (debug_) HIGHLIGHT("Maximum iterations reached");
191  prob_->termination_criterion = TerminationCriterion::IterationLimit;
192  }
193 
194  Eigen::MatrixXd sol(prob_->GetT(), prob_->N);
195  for (int tt = 0; tt < prob_->GetT(); ++tt)
196  {
197  sol.row(tt) = q[tt];
198  }
199  solution = sol;
200  planning_time_ = timer.GetDuration();
201 }
202 
203 void AICOSolver::InitMessages()
204 {
205  if (prob_ == nullptr) ThrowNamed("Problem definition is a NULL pointer!");
206 
207  if (prob_->N < 1)
208  {
209  ThrowNamed("State dimension is too small: n=" << prob_->N);
210  }
211  if (prob_->GetT() < 2)
212  {
213  ThrowNamed("Number of time steps is too small: T=" << prob_->GetT());
214  }
215 
216  s.assign(prob_->GetT(), Eigen::VectorXd::Zero(prob_->N));
217  Sinv.assign(prob_->GetT(), Eigen::MatrixXd::Zero(prob_->N, prob_->N));
218  Sinv[0].diagonal().setConstant(1e10);
219  v.assign(prob_->GetT(), Eigen::VectorXd::Zero(prob_->N));
220  Vinv.assign(prob_->GetT(), Eigen::MatrixXd::Zero(prob_->N, prob_->N));
221  if (use_bwd_msg_)
222  {
223  if (bwd_msg_v_.rows() == prob_->N && bwd_msg_Vinv_.rows() == prob_->N && bwd_msg_Vinv_.cols() == prob_->N)
224  {
225  v[prob_->GetT() - 1] = bwd_msg_v_;
226  Vinv[prob_->GetT() - 1] = bwd_msg_Vinv_;
227  }
228  else
229  {
230  use_bwd_msg_ = false;
231  WARNING("Backward message initialisation skipped, matrices have incorrect dimensions.");
232  }
233  }
234  b.assign(prob_->GetT(), Eigen::VectorXd::Zero(prob_->N));
235  damping_reference_.assign(prob_->GetT(), Eigen::VectorXd::Zero(prob_->N));
236  Binv.assign(prob_->GetT(), Eigen::MatrixXd::Zero(prob_->N, prob_->N));
237  Binv[0].setIdentity();
238  Binv[0] = Binv[0] * 1e10;
239  r.assign(prob_->GetT(), Eigen::VectorXd::Zero(prob_->N));
240  R.assign(prob_->GetT(), Eigen::MatrixXd::Zero(prob_->N, prob_->N));
241  rhat = Eigen::VectorXd::Zero(prob_->GetT());
242  qhat.assign(prob_->GetT(), Eigen::VectorXd::Zero(prob_->N));
243  q = b;
244 
245  cost_control_.resize(prob_->GetT());
246  cost_control_.setZero();
247  cost_task_.resize(prob_->GetT());
248  cost_task_.setZero();
249 
250  q_stat_.resize(prob_->GetT());
251  for (int t = 0; t < prob_->GetT(); ++t)
252  {
253  q_stat_[t].resize(prob_->N);
254  }
255 
256  // Set last_T_ to the problem T
257  last_T_ = prob_->GetT();
258 }
259 
260 void AICOSolver::InitTrajectory(const std::vector<Eigen::VectorXd>& q_init)
261 {
262  if (q_init.size() != static_cast<std::size_t>(prob_->GetT()))
263  {
264  ThrowNamed("Incorrect number of timesteps provided!");
265  }
266  qhat = q_init;
267  q = q_init;
268  damping_reference_ = q_init;
269  b = q_init;
270  s = q_init;
271  v = q_init;
272  for (int t = 1; t < prob_->GetT(); ++t)
273  {
274  Sinv.at(t).setZero();
275  Sinv.at(t).diagonal().setConstant(damping);
276  }
277  for (int t = 0; t < prob_->GetT(); ++t)
278  {
279  Vinv.at(t).setZero();
280  Vinv.at(t).diagonal().setConstant(damping);
281  }
282  for (int t = 0; t < prob_->GetT(); ++t)
283  {
284  // Compute task message reference
285  UpdateTaskMessage(t, b[t], 0.0);
286  }
287 
288  // W is still writable, check dimension
289  if (prob_->W.rows() != prob_->N)
290  {
291  ThrowNamed(prob_->W.rows() << "!=" << prob_->N);
292  }
293 
294  // Set constant W,Win,H,Hinv
295  W = prob_->W;
296  Winv = W.inverse();
297 
298  cost_ = EvaluateTrajectory(b, true); // The problem will be updated via UpdateTaskMessage, i.e. do not update on this roll-out
299  cost_prev_ = cost_;
300  prob_->SetCostEvolution(0, cost_);
301  if (cost_ < 0) ThrowNamed("Invalid cost! " << cost_);
302  if (debug_) HIGHLIGHT("Initial cost, updates: " << update_count_ << ", cost_(ctrl/task/total): " << cost_control_.sum() << "/" << cost_task_.sum() << "/" << cost_);
303  RememberOldState();
304 }
305 
306 void AICOSolver::UpdateFwdMessage(int t)
307 {
308  Eigen::MatrixXd barS(prob_->N, prob_->N), St;
309  inverseSymPosDef(barS, Sinv[t - 1] + R[t - 1]);
310  s[t] = barS * (Sinv[t - 1] * s[t - 1] + r[t - 1]);
311  St = Winv + barS;
312  inverseSymPosDef(Sinv[t], St);
313 }
314 
315 void AICOSolver::UpdateBwdMessage(int t)
316 {
317  Eigen::MatrixXd barV(prob_->N, prob_->N), Vt;
318  if (t < prob_->GetT() - 1)
319  {
320  inverseSymPosDef(barV, Vinv[t + 1] + R[t + 1]);
321  v[t] = barV * (Vinv[t + 1] * v[t + 1] + r[t + 1]);
322  Vt = Winv + barV;
323  inverseSymPosDef(Vinv[t], Vt);
324  }
325  if (t == prob_->GetT() - 1)
326  {
327  if (!use_bwd_msg_)
328  {
329  v[t] = b[t];
330  Vinv[t].diagonal().setConstant(1);
331  }
332  else
333  {
334  v[prob_->GetT() - 1] = bwd_msg_v_;
335  Vinv[prob_->GetT() - 1] = bwd_msg_Vinv_;
336  }
337  }
338 }
339 
340 void AICOSolver::UpdateTaskMessage(int t,
341  const Eigen::Ref<const Eigen::VectorXd>& qhat_t, double tolerance,
342  double max_step_size)
343 {
344  Eigen::VectorXd diff = qhat_t - qhat[t];
345  if ((diff.array().abs().maxCoeff() < tolerance)) return;
346  double nrm = diff.norm();
347  if (max_step_size > 0. && nrm > max_step_size)
348  {
349  qhat[t] += diff * (max_step_size / nrm);
350  }
351  else
352  {
353  qhat[t] = qhat_t;
354  }
355 
356  prob_->Update(qhat[t], t);
357  ++update_count_;
358  double c = GetTaskCosts(t);
359  q_stat_[t].addw(c > 0 ? 1.0 / (1.0 + c) : 1.0, qhat_t);
360 }
361 
362 double AICOSolver::GetTaskCosts(int t)
363 {
364  double C = 0;
365  Eigen::MatrixXd Jt;
366  double prec;
367  rhat[t] = 0;
368  R[t].setZero();
369  r[t].setZero();
370  for (int i = 0; i < prob_->cost.num_tasks; ++i)
371  {
372  prec = prob_->cost.rho[t](i);
373  if (prec > 0)
374  {
375  int start = prob_->cost.indexing[i].start_jacobian;
376  int len = prob_->cost.indexing[i].length_jacobian;
377  Jt = prob_->cost.jacobian[t].middleRows(start, len).transpose();
378  C += prec * (prob_->cost.ydiff[t].segment(start, len)).squaredNorm();
379  R[t] += prec * Jt * prob_->cost.jacobian[t].middleRows(start, len);
380  r[t] += prec * Jt * (-prob_->cost.ydiff[t].segment(start, len) + prob_->cost.jacobian[t].middleRows(start, len) * qhat[t]);
381  rhat[t] += prec * (-prob_->cost.ydiff[t].segment(start, len) + prob_->cost.jacobian[t].middleRows(start, len) * qhat[t]).squaredNorm();
382  }
383  }
384  return prob_->get_ct() * C;
385 }
386 
387 void AICOSolver::UpdateTimestep(int t, bool update_fwd, bool update_bwd,
388  int max_relocation_iterations, double tolerance, bool force_relocation,
389  double max_step_size)
390 {
391  if (update_fwd) UpdateFwdMessage(t);
392  if (update_bwd) UpdateBwdMessage(t);
393 
394  if (damping != 0.0)
395  {
396  Binv[t] = Sinv[t] + Vinv[t] + R[t] + Eigen::MatrixXd::Identity(prob_->N, prob_->N) * damping;
397  AinvBSymPosDef(b[t], Binv[t], Sinv[t] * s[t] + Vinv[t] * v[t] + r[t] + damping * damping_reference_[t]);
398  }
399  else
400  {
401  Binv[t] = Sinv[t] + Vinv[t] + R[t];
402  AinvBSymPosDef(b[t], Binv[t], Sinv[t] * s[t] + Vinv[t] * v[t] + r[t]);
403  }
404 
405  for (int k = 0; k < max_relocation_iterations && !(Server::IsRos() && !ros::ok()); ++k)
406  {
407  if (!((!k && force_relocation) || (b[t] - qhat[t]).array().abs().maxCoeff() > tolerance)) break;
408 
409  UpdateTaskMessage(t, b.at(t), 0., max_step_size);
410 
411  //optional reUpdate fwd or bwd message (if the Dynamics might have changed...)
412  if (update_fwd) UpdateFwdMessage(t);
413  if (update_bwd) UpdateBwdMessage(t);
414 
415  if (damping != 0.0)
416  {
417  Binv[t] = Sinv[t] + Vinv[t] + R[t] + Eigen::MatrixXd::Identity(prob_->N, prob_->N) * damping;
418  AinvBSymPosDef(b[t], Binv[t], Sinv[t] * s[t] + Vinv[t] * v[t] + r[t] + damping * damping_reference_[t]);
419  }
420  else
421  {
422  Binv[t] = Sinv[t] + Vinv[t] + R[t];
423  AinvBSymPosDef(b[t], Binv[t], Sinv[t] * s[t] + Vinv[t] * v[t] + r[t]);
424  }
425  }
426 }
427 
428 void AICOSolver::UpdateTimestepGaussNewton(int t, bool update_fwd,
429  bool update_bwd, int max_relocation_iterations, double tolerance,
430  double max_step_size)
431 {
432  // TODO: implement UpdateTimestepGaussNewton
433  ThrowNamed("Not implemented yet!");
434 }
435 
436 double AICOSolver::EvaluateTrajectory(const std::vector<Eigen::VectorXd>& x,
437  bool skip_update)
438 {
439  if (verbose_) ROS_WARN_STREAM("Evaluating, iteration " << iteration_count_ << ", sweep " << sweep_);
440  Timer timer;
441 
442  q = x;
443 
444  // Perform update / roll-out
445  if (!skip_update)
446  {
447  for (int t = 0; t < prob_->GetT(); ++t)
448  {
449  ++update_count_;
450  if (!q[t].allFinite())
451  {
452  ThrowNamed("q[" << t << "] is not finite: " << q[t].transpose());
453  }
454  prob_->Update(q[t], t);
455  }
456  }
457  if (verbose_ && !skip_update) HIGHLIGHT("Roll-out took: " << timer.GetDuration());
458 
459  for (int t = 1; t < prob_->GetT(); ++t)
460  {
461  if (Server::IsRos() && !ros::ok()) return -1.0;
462 
463  // Control cost
464  cost_control_(t) = prob_->GetScalarTransitionCost(t);
465 
466  // Task cost
467  cost_task_(t) = prob_->GetScalarTaskCost(t);
468  }
469 
470  cost_ = cost_control_.sum() + cost_task_.sum();
471  return cost_;
472 }
473 
474 double AICOSolver::Step()
475 {
476  RememberOldState();
477  int t;
478  switch (sweep_mode_)
479  {
480  //NOTE: the dependence on (Sweep?..:..) could perhaps be replaced by (DampingReference.N?..:..)
481  case FORWARD:
482  for (t = 1; t < prob_->GetT(); ++t)
483  {
484  UpdateTimestep(t, true, false, 1, minimum_step_tolerance_, !iteration_count_, 1.); //relocate once on fwd Sweep
485  }
486  for (t = prob_->GetT() - 2; t > 0; t--)
487  {
488  UpdateTimestep(t, false, true, 0, minimum_step_tolerance_, false, 1.); //...not on bwd Sweep
489  }
490  break;
491  case SYMMETRIC:
492  // ROS_WARN_STREAM("Updating forward, iteration_count_ "<<iteration_count_);
493  for (t = 1; t < prob_->GetT(); ++t)
494  {
495  UpdateTimestep(t, true, false, 1, minimum_step_tolerance_, !iteration_count_, 1.); //relocate once on fwd & bwd Sweep
496  }
497  // ROS_WARN_STREAM("Updating backward, iteration_count_ "<<iteration_count_);
498  for (t = prob_->GetT() - 2; t > 0; t--)
499  {
500  UpdateTimestep(t, false, true, (iteration_count_ ? 1 : 0), minimum_step_tolerance_, false, 1.);
501  }
502  break;
503  case LOCAL_GAUSS_NEWTON:
504  for (t = 1; t < prob_->GetT(); ++t)
505  {
506  UpdateTimestep(t, true, false, (iteration_count_ ? 5 : 1), minimum_step_tolerance_, !iteration_count_, 1.); //relocate iteratively on
507  }
508  for (t = prob_->GetT() - 2; t > 0; t--)
509  {
510  UpdateTimestep(t, false, true, (iteration_count_ ? 5 : 0), minimum_step_tolerance_, false, 1.); //...fwd & bwd Sweep
511  }
512  break;
513  case LOCAL_GAUSS_NEWTON_DAMPED:
514  for (t = 1; t < prob_->GetT(); ++t)
515  {
516  UpdateTimestepGaussNewton(t, true, false, (iteration_count_ ? 5 : 1),
517  minimum_step_tolerance_, 1.); //GaussNewton in fwd & bwd Sweep
518  }
519  for (t = prob_->GetT() - 2; t > 0; t--)
520  {
521  UpdateTimestep(t, false, true, (iteration_count_ ? 5 : 0), minimum_step_tolerance_, false, 1.);
522  }
523  break;
524  default:
525  ThrowNamed("non-existing Sweep mode");
526  }
527  b_step_ = 0.0;
528  for (t = 0; t < static_cast<int>(b.size()); ++t)
529  {
530  b_step_ = std::max((b_old[t] - b[t]).array().abs().maxCoeff(), b_step_);
531  }
532  damping_reference_ = b;
533  // q is set inside of EvaluateTrajectory() function
534  cost_ = EvaluateTrajectory(b);
535  if (verbose_)
536  {
537  HIGHLIGHT("Iteration: " << iteration_count_ << ", Sweep: " << sweep_ << ", updates: " << update_count_ << ", cost(ctrl/task/total): " << cost_control_.sum() << "/" << cost_task_.sum() << "/" << cost_ << " (dq=" << b_step_ << ", damping=" << damping << ")");
538  }
539  else if (debug_ && sweep_ == 0)
540  {
541  HIGHLIGHT("Iteration: " << iteration_count_ << ", updates: " << update_count_ << ", cost(ctrl/task/total): " << cost_control_.sum() << "/" << cost_task_.sum() << "/" << cost_ << " (dq=" << b_step_ << ", damping=" << damping << ")");
542  }
543  if (cost_ < 0) return -1.0;
544  best_sweep_ = sweep_;
545 
546  // If damping (similar to line-search) is being used, consider reverting this step
547  if (damping != 0.0) PerhapsUndoStep();
548 
549  ++sweep_;
550  if (sweep_improved_cost_)
551  {
552  // HIGHLIGHT("Sweep improved cost, increasing iteration count and resetting sweep count");
553  ++iteration_count_;
554  sweep_ = 0;
555  prob_->SetCostEvolution(iteration_count_, cost_);
556  }
557 
558  return b_step_;
559 }
560 
561 void AICOSolver::RememberOldState()
562 {
563  s_old = s;
564  Sinv_old = Sinv;
565  v_old = v;
566  Vinv_old = Vinv;
567  r_old = r;
568  R_old = R;
569  Binv_old = Binv;
570  rhat_old = rhat;
571  b_old = b;
572  r_old = r;
573  q_old = q;
574  qhat_old = qhat;
575  cost_old_ = cost_;
576  cost_control_old_ = cost_control_;
577  cost_task_old_ = cost_task_;
578  best_sweep_old_ = best_sweep_;
579  b_step_old_ = b_step_;
580 }
581 
582 void AICOSolver::PerhapsUndoStep()
583 {
584  if (cost_ > cost_old_)
585  {
586  sweep_improved_cost_ = false;
587  damping *= 10.;
588  s = s_old;
589  Sinv = Sinv_old;
590  v = v_old;
591  Vinv = Vinv_old;
592  r = r_old;
593  R = R_old;
594  Binv = Binv_old;
595  rhat = rhat_old;
596  b = b_old;
597  r = r_old;
598  q = q_old;
599  qhat = qhat_old;
600  cost_ = cost_old_;
601  damping_reference_ = b_old;
602  cost_control_ = cost_control_old_;
603  cost_task_ = cost_task_old_;
604  best_sweep_ = best_sweep_old_;
605  b_step_ = b_step_old_;
606  if (verbose_) HIGHLIGHT("Reverting to previous line-search step (" << best_sweep_ << ")");
607  }
608  else
609  {
610  sweep_improved_cost_ = true;
611  damping /= 5.;
612  }
613 }
614 } // namespace exotica
d
#define HIGHLIGHT(x)
static void AinvBSymPosDef(T1 &x, const T2 &A, const T3 &b)
Computes the solution to the linear problem for symmetric positive definite matrix A...
Solves motion planning problem using Approximate Inference Control method.
Definition: aico_solver.h:72
XmlRpcServer s
IMETHOD Vector diff(const Vector &p_w_a, const Vector &p_w_b, double dt=1)
#define REGISTER_MOTIONSOLVER_TYPE(TYPE, DERIV)
#define ThrowNamed(m)
ROSCPP_DECL bool ok()
#define ROS_WARN_STREAM(args)
static void inverseSymPosDef(T1 &Ainv, const T2 &A)
Computes an inverse of a symmetric positive definite matrix.
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
Approximate Inference Control.
double GetDuration() const
std::shared_ptr< PlanningProblem > PlanningProblemPtr
r
#define WARNING(x)


exotica_aico_solver
Author(s):
autogenerated on Sat Apr 10 2021 02:35:19