trajectory_optimizer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Software License Agreement (BSD License) *
3  * Copyright (C) 2016 by Horatiu George Todoran <todorangrg@gmail.com> *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions *
7  * are met: *
8  * *
9  * 1. Redistributions of source code must retain the above copyright *
10  * notice, this list of conditions and the following disclaimer. *
11  * 2. Redistributions in binary form must reproduce the above copyright *
12  * notice, this list of conditions and the following disclaimer in *
13  * the documentation and/or other materials provided with the *
14  * distribution. *
15  * 3. Neither the name of the copyright holder nor the names of its *
16  * contributors may be used to endorse or promote products derived *
17  * from this software without specific prior written permission. *
18  * *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY *
29  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30  * POSSIBILITY OF SUCH DAMAGE. *
31  ***************************************************************************/
32 
34 #include <tuw_control/utils.h>
35 
36 #include <algorithm>
37 
38 #include <iostream>
39 
40 using namespace std;
41 using namespace tuw;
42 
43 TrajectoryOptimizer::TrajectoryOptimizer(StateSimPtr& _stateSim,
44  unique_ptr<TrajectorySimulator::CostsEvaluatorClass> _costsEvaluator,
45  OptimizationStateSPtr _optState)
46  : TrajectorySimGrade(_stateSim, std::move(_costsEvaluator)), optState_(_optState)
47 {
48 }
49 
50 void TrajectoryOptimizer::optimize()
51 {
52  throw "not implemented";
53 }
54 
56 {
57  return stepSize_;
58 }
60 {
62 
63  auto& costsEvaluator = trajSim()->costsEvaluator_;
64 
65  costsEvaluator->gradF.resize(optState_->valueSize());
66  costsEvaluator->gradG.resize(costsEvaluator->g.size(), optState_->valueSize());
67  costsEvaluator->gradH.resize(costsEvaluator->h.size(), optState_->valueSize());
68 
69  fCache = costsEvaluator->f;
70  gCache = costsEvaluator->g;
71  hCache = costsEvaluator->h;
72 
73  for (size_t i = 0; i < optState_->valueSize(); ++i)
74  {
76  }
77  optState_->toTrajState(*trajSim());
78 
79  costsEvaluator->f = fCache;
80  costsEvaluator->g = gCache;
81  costsEvaluator->h = hCache;
82 }
83 
85 {
86  const double optStateIFix = optState_->value(_idx);
87  optState_->value(_idx) += stepSize_;
88  optState_->toTrajState(*trajSim());
89 
91 
92  auto& costsEvaluator = trajSim()->costsEvaluator_;
93  costsEvaluator->gradF[_idx] = (costsEvaluator->f - fCache) / stepSize_;
94  for (int j = 0; j < costsEvaluator->gradG.rows(); ++j)
95  {
96  costsEvaluator->gradG(j, _idx) = (costsEvaluator->g[j] - gCache[j]) / stepSize_;
97  }
98  for (int j = 0; j < costsEvaluator->gradH.rows(); ++j)
99  {
100  costsEvaluator->gradH(j, _idx) = (costsEvaluator->h[j] - hCache[j]) / stepSize_;
101  }
102 
103  optState_->value(_idx) = optStateIFix;
104 }
105 
106 void TrajectoryOptimizer::initState0ParamFuncsHValid(const std::size_t& _optFailCount)
107 {
108  return;
109 }
void evaluateTrajectory(const double &_arcBegin=0)
std::shared_ptr< OptimizationState > OptimizationStateSPtr
Helper function needed to upgrade c++ 2011.
Definition: utils.h:193
TrajectorySimulatorSPtr & trajSim()
std::vector< double > hCache
virtual void initState0ParamFuncsHValid(const size_t &_optFailCount)
std::vector< double > gCache
void computeJacobian1Entry(size_t _idx)
std::shared_ptr< StateSim > StateSimPtr
OptimizationStateSPtr optState_


tuw_control
Author(s): George Todoran
autogenerated on Mon Jun 10 2019 15:27:22