CostHelper.cpp
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2014, University of Toronto
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 University of Toronto 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: Jonathan Gammell */
36 
37 // My definition:
38 #include "ompl/geometric/planners/bitstar/datastructures/CostHelper.h"
39 
40 // BIT*:
41 // The implicit graph:
42 #include "ompl/geometric/planners/bitstar/datastructures/ImplicitGraph.h"
43 
44 namespace ompl
45 {
46  namespace geometric
47  {
49  {
50  opt_ = opt;
51  graphPtr_ = graph;
52  }
53 
56  {
57  opt_.reset();
58  graphPtr_.reset();
59  }
60 
62  {
63  // Variable
64  // The current best cost to a goal from the state, initialize to infinity
65  ompl::base::Cost curBest = this->infiniteCost();
66 
67  // Iterate over the vector of goals, finding the minimum estimated cost-to-go from the state
68  for (auto goalIter = graphPtr_->goalVerticesBeginConst(); goalIter != graphPtr_->goalVerticesEndConst();
69  ++goalIter)
70  {
71  // Update the cost-to-go as the better of the best so far and the new one
72  curBest = this->betterCost(curBest,
73  this->motionCostHeuristic(vertex->stateConst(), (*goalIter)->stateConst()));
74  }
75 
76  // Return
77  return curBest;
78  }
79 
81  {
82  // Variable
83  // The current best cost to the state, initialize to infinity
84  ompl::base::Cost curBest = this->infiniteCost();
85 
86  // Iterate over the vector of starts, finding the minimum estimated cost-to-come to the state
87  for (auto startIter = graphPtr_->startVerticesBeginConst(); startIter != graphPtr_->startVerticesEndConst();
88  ++startIter)
89  {
90  // Update the cost-to-come as the better of the best so far and the new one
91  curBest = this->betterCost(curBest,
92  this->motionCostHeuristic((*startIter)->stateConst(), vertex->stateConst()));
93  }
94 
95  // Return
96  return curBest;
97  }
98  } // geometric
99 } // ompl
ompl::base::Cost costToComeHeuristic(const VertexConstPtr &vertex) const
Calculate a heuristic estimate of the cost-to-come for a Vertex.
Definition: CostHelper.cpp:80
std::shared_ptr< ImplicitGraph > ImplicitGraphPtr
An implicit graph shared pointer.
Definition: BITstar.h:148
std::shared_ptr< const Vertex > VertexConstPtr
A constant vertex shared pointer.
Definition: BITstar.h:126
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
A shared pointer wrapper for ompl::base::OptimizationObjective.
void setup(const ompl::base::OptimizationObjectivePtr &opt, const ImplicitGraphPtr &graph)
Setup the CostHelper, must be called before use.
Definition: CostHelper.cpp:48
ompl::base::Cost costToGoHeuristic(const VertexConstPtr &vertex) const
Calculate a heuristic estimate of the cost-to-go for a Vertex.
Definition: CostHelper.cpp:61
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition: Cost.h:47
void clear()
Clear the CostHelper, returns to state at construction.
Definition: CostHelper.cpp:55