VFUpstreamCriterionOptimizationObjective.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, Caleb Voss and Wilson Beebe
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Authors: Caleb Voss, Wilson Beebe */
36 
37 #ifndef OMPL_BASE_OBJECTIVES_VF_UPSTREAM_CRITERION_OPTIMIZATION_OBJECTIVE_
38 #define OMPL_BASE_OBJECTIVES_VF_UPSTREAM_CRITERION_OPTIMIZATION_OBJECTIVE_
39 
40 #include <utility>
41 
42 #include "ompl/base/OptimizationObjective.h"
43 #include "ompl/geometric/planners/rrt/VFRRT.h"
44 
45 namespace ompl
46 {
47  namespace base
48  {
52  class VFUpstreamCriterionOptimizationObjective : public ompl::base::OptimizationObjective
53  {
54  public:
57  geometric::VFRRT::VectorField vf)
58  : ompl::base::OptimizationObjective(si), vf_(std::move(vf))
59  {
60  description_ = "Upstream Criterion";
61  }
62 
64  bool isSatisfied(ompl::base::Cost) const override
65  {
66  return false;
67  }
68 
70  Cost stateCost(const State *) const override
71  {
72  return Cost(0.);
73  }
74 
76  ompl::base::Cost motionCost(const State *s1, const State *s2) const override
77  {
78  const base::StateSpacePtr &space = si_->getStateSpace();
79  // Per equation 1 in the paper, Riemann approximation on the left
80  unsigned int vfdim = space->getValueLocations().size();
81  Eigen::VectorXd qprime(vfdim);
82  unsigned int numSegments = space->validSegmentCount(s1, s2);
83  std::vector<ompl::base::State *> interp;
84 
85  for (unsigned int i = 0; i < vfdim; i++)
86  qprime[i] = *space->getValueAddressAtIndex(s2, i) - *space->getValueAddressAtIndex(s1, i);
87  qprime.normalize();
88  si_->getMotionStates(s1, s2, interp, numSegments - 1, true, true);
89  double cost = 0;
90  for (unsigned int i = 0; i < interp.size() - 1; i++)
91  {
92  Eigen::VectorXd f = vf_(interp[i]);
93  cost += si_->distance(interp[i], interp[i + 1]) * (f.norm() - f.dot(qprime));
94  si_->freeState(interp[i]);
95  }
96  si_->freeState(interp[interp.size() - 1]);
97  return ompl::base::Cost(cost);
98  }
99 
100  bool isSymmetric() const override
101  {
102  return false;
103  }
104 
105  protected:
107  geometric::VFRRT::VectorField vf_;
108  };
109  }
110 }
111 
112 #endif
SpaceInformationPtr si_
The space information for this objective.
A shared pointer wrapper for ompl::base::SpaceInformation.
ompl::base::Cost motionCost(const State *s1, const State *s2) const override
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:111
Abstract definition of optimization objectives.
Cost stateCost(const State *) const override
Returns a cost with a value of 0.
std::string description_
The description of this optimization objective.
VFUpstreamCriterionOptimizationObjective(const ompl::base::SpaceInformationPtr &si, geometric::VFRRT::VectorField vf)
bool isSymmetric() const override
Check if this objective has a symmetric cost metric, i.e. motionCost(s1, s2) = motionCost(s2,...
Main namespace. Contains everything in this library.