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 "ompl/base/OptimizationObjective.h"
41 #include "ompl/geometric/planners/rrt/VFRRT.h"
42 
43 namespace ompl
44 {
45  namespace base
46  {
47 
52  {
53 
54  public:
55 
58  const geometric::VFRRT::VectorField &vf)
59  : ompl::base::OptimizationObjective(si), vf_(vf)
60  {
61  description_ = "Upstream Criterion";
62  }
63 
66  {
67  return false;
68  }
69 
71  virtual Cost stateCost(const State *s) const
72  {
73  return Cost(0.);
74  }
75 
77  ompl::base::Cost motionCost(const State *s1, const State *s2) const
78  {
79  const base::StateSpacePtr &space = si_->getStateSpace();
80  // Per equation 1 in the paper, Riemann approximation on the left
81  unsigned int vfdim = space->getValueLocations().size();
82  Eigen::VectorXd qprime(vfdim);
83  unsigned int numSegments = space->validSegmentCount(s1, s2);
84  std::vector<ompl::base::State*> interp;
85 
86  for (unsigned int i = 0; i < vfdim; i++)
87  qprime[i] = *space->getValueAddressAtIndex(s2, i)
88  - *space->getValueAddressAtIndex(s1, i);
89  qprime.normalize();
90  si_->getMotionStates(s1, s2, interp, numSegments - 1, true, true);
91  double cost = 0;
92  for (unsigned int i = 0; i < interp.size() - 1; i++)
93  {
94  Eigen::VectorXd f = vf_(interp[i]);
95  cost += si_->distance(interp[i], interp[i + 1]) * (f.norm() - f.dot(qprime));
96  si_->freeState(interp[i]);
97  }
98  si_->freeState(interp[interp.size()-1]);
99  return ompl::base::Cost(cost);
100  }
101 
102  bool isSymmetric(void) const
103  {
104  return false;
105  }
106 
107  protected:
109  geometric::VFRRT::VectorField vf_;
110  };
111 
112  }
113 }
114 
115 #endif
std::string description_
The description of this optimization objective.
A shared pointer wrapper for ompl::base::StateSpace.
bool isSymmetric(void) const
Check if this objective has a symmetric cost metric, i.e. motionCost(s1, s2) = motionCost(s2, s1). Default implementation returns whether the underlying state space has symmetric interpolation.
virtual Cost stateCost(const State *s) const
Returns a cost with a value of 0.
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition: State.h:50
Abstract definition of optimization objectives.
ompl::base::Cost motionCost(const State *s1, const State *s2) const
SpaceInformationPtr si_
The space information for this objective.
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
VFUpstreamCriterionOptimizationObjective(const ompl::base::SpaceInformationPtr &si, const geometric::VFRRT::VectorField &vf)