Loading...
Searching...
No Matches
OptimizationObjective.h
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2012, Willow Garage, Inc.
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/* Author: Luis G. Torres, Ioan Sucan, Jonathan Gammell */
36
37#ifndef OMPL_BASE_OPTIMIZATION_OBJECTIVE_
38#define OMPL_BASE_OPTIMIZATION_OBJECTIVE_
39
40#include "ompl/base/Cost.h"
41#include "ompl/base/SpaceInformation.h"
42#include "ompl/util/ClassForward.h"
43#include "ompl/base/ProblemDefinition.h"
44#include "ompl/base/samplers/InformedStateSampler.h"
45#include "ompl/control/Control.h"
46
47#include <functional>
48#include <iostream>
49
50namespace ompl
51{
52 namespace base
53 {
54 class Goal;
55
58 using CostToGoHeuristic = std::function<Cost(const State *, const Goal *)>;
59
61
62 OMPL_CLASS_FORWARD(OptimizationObjective);
64
67
71 class OptimizationObjective
72 {
73 public:
74 // non-copyable
75 OptimizationObjective(const OptimizationObjective &) = delete;
76 OptimizationObjective &operator=(const OptimizationObjective &) = delete;
77
80 OptimizationObjective(SpaceInformationPtr si);
81
82 virtual ~OptimizationObjective() = default;
83
85 const std::string &getDescription() const;
86
89 virtual bool isSatisfied(Cost c) const;
90
92 Cost getCostThreshold() const;
93
96 void setCostThreshold(Cost c);
97
100 virtual bool isCostBetterThan(Cost c1, Cost c2) const;
101
105 virtual bool isCostEquivalentTo(Cost c1, Cost c2) const;
106
108 virtual bool isFinite(Cost cost) const;
109
111 virtual Cost betterCost(Cost c1, Cost c2) const;
112
114 virtual Cost stateCost(const State *s) const = 0;
115
117 virtual Cost motionCost(const State *s1, const State *s2) const = 0;
118
121 virtual Cost controlCost(const control::Control *c, unsigned int steps) const;
122
125 virtual Cost combineCosts(Cost c1, Cost c2) const;
126
128 virtual Cost subtractCosts(Cost c1, Cost c2) const;
129
135 virtual Cost identityCost() const;
136
139 virtual Cost infiniteCost() const;
140
143 virtual Cost initialCost(const State *s) const;
144
147 virtual Cost terminalCost(const State *s) const;
148
151 virtual bool isSymmetric() const;
152
154 virtual Cost averageStateCost(unsigned int numStates) const;
155
160
162 bool hasCostToGoHeuristic() const;
163
168 Cost costToGo(const State *state, const Goal *goal) const;
169
174 virtual Cost motionCostHeuristic(const State *s1, const State *s2) const;
175
180 virtual Cost motionCostBestEstimate(const State *s1, const State *s2) const;
181
184
187 virtual InformedSamplerPtr allocInformedStateSampler(const ProblemDefinitionPtr &probDefn,
188 unsigned int maxNumberCalls) const;
189
191 virtual void print(std::ostream &out) const;
192
193 protected:
196
198 std::string description_;
199
202
206 };
207
216 Cost goalRegionCostToGo(const State *state, const Goal *goal);
217
221 class MultiOptimizationObjective : public OptimizationObjective
222 {
223 public:
224 MultiOptimizationObjective(const SpaceInformationPtr &si);
225
228 void addObjective(const OptimizationObjectivePtr &objective, double weight);
229
231 std::size_t getObjectiveCount() const;
232
235 const OptimizationObjectivePtr &getObjective(unsigned int idx) const;
236
238 double getObjectiveWeight(unsigned int idx) const;
239
241 void setObjectiveWeight(unsigned int idx, double weight);
242
244 void lock();
245
247 bool isLocked() const;
248
253 Cost stateCost(const State *s) const override;
254
259 Cost motionCost(const State *s1, const State *s2) const override;
260
261 protected:
263 struct Component
264 {
265 Component(OptimizationObjectivePtr obj, double weight);
266 OptimizationObjectivePtr objective;
267 double weight;
268 };
269
271 std::vector<Component> components_;
272
275
276 // Friend functions for operator overloads for easy multiobjective creation
278 const OptimizationObjectivePtr &b);
279
281
283 };
284
288
292
296 } // namespace base
297} // namespace ompl
298
299#endif
Definition of a cost value. Can represent the cost of a motion or the cost of a state.
Definition Cost.h:48
Abstract definition of goals.
Definition Goal.h:63
const OptimizationObjectivePtr & getObjective(unsigned int idx) const
Returns a specific objective from this multiobjective, where the individual objectives are in order o...
void setObjectiveWeight(unsigned int idx, double weight)
Sets the weighing factor of a specific objective.
std::size_t getObjectiveCount() const
Returns the number of objectives that make up this multiobjective.
Cost stateCost(const State *s) const override
double getObjectiveWeight(unsigned int idx) const
Returns the weighing factor of a specific objective.
bool locked_
Whether this multiobjective is locked from further additions.
friend OptimizationObjectivePtr operator*(const OptimizationObjectivePtr &a, double weight)
Given a weighing factor and an optimization objective, returns a MultiOptimizationObjective containin...
friend OptimizationObjectivePtr operator*(double weight, const OptimizationObjectivePtr &a)
Given a weighing factor and an optimization objective, returns a MultiOptimizationObjective containin...
bool isLocked() const
Returns whether this multiobjective has been locked from adding further objectives.
std::vector< Component > components_
List of objective/weight pairs.
void addObjective(const OptimizationObjectivePtr &objective, double weight)
Adds a new objective for this multiobjective. A weight must also be specified for specifying importan...
Cost motionCost(const State *s1, const State *s2) const override
friend OptimizationObjectivePtr operator+(const OptimizationObjectivePtr &a, const OptimizationObjectivePtr &b)
Given two optimization objectives, returns a MultiOptimizationObjective that combines the two objecti...
void lock()
This method "freezes" this multiobjective so that no more objectives can be added to it.
A shared pointer wrapper for ompl::base::OptimizationObjective.
Abstract definition of optimization objectives.
Cost costToGo(const State *state, const Goal *goal) const
Uses a cost-to-go heuristic to calculate an admissible estimate of the optimal cost from a given stat...
std::string description_
The description of this optimization objective.
virtual Cost subtractCosts(Cost c1, Cost c2) const
Get the cost that corresponds to subtracting the cost c2 from c1.
void setCostThreshold(Cost c)
Set the cost threshold for objective satisfaction. When a path is found with a cost better than the c...
virtual Cost averageStateCost(unsigned int numStates) const
Compute the average state cost of this objective by taking a sample of numStates states.
bool hasCostToGoHeuristic() const
Check if this objective has a cost-to-go heuristic function.
virtual bool isCostEquivalentTo(Cost c1, Cost c2) const
Compare whether cost c1 and cost c2 are equivalent. By default defined as !isCostBetterThan(c1,...
virtual bool isFinite(Cost cost) const
Returns whether the cost is finite or not.
void setCostToGoHeuristic(const CostToGoHeuristic &costToGo)
Set the cost-to-go heuristic function for this objective. The cost-to-go heuristic is a function whic...
virtual Cost stateCost(const State *s) const =0
Evaluate a cost map defined on the state space at a state s.
const SpaceInformationPtr & getSpaceInformation() const
Returns this objective's SpaceInformation. Needed for operators in MultiOptimizationObjective.
Cost threshold_
The cost threshold used for checking whether this objective has been satisfied during planning.
virtual Cost motionCostHeuristic(const State *s1, const State *s2) const
Defines an admissible estimate on the optimal cost on the motion between states s1 and s2....
virtual Cost identityCost() const
Get the identity cost value. The identity cost value is the cost c_i such that, for all costs c,...
virtual Cost combineCosts(Cost c1, Cost c2) const
Get the cost that corresponds to combining the costs c1 and c2. Default implementation defines this c...
virtual Cost terminalCost(const State *s) const
Returns a cost value corresponding to a path ending at a state s. No optimal planners currently suppo...
virtual Cost controlCost(const control::Control *c, unsigned int steps) const
Get the cost that corresponds to the motion created by a control c applied for duration steps....
virtual bool isCostBetterThan(Cost c1, Cost c2) const
Check whether the the cost c1 is considered better than the cost c2. By default, this returns true if...
CostToGoHeuristic costToGoFn_
The function used for returning admissible estimates on the optimal cost of the path between a given ...
Cost getCostThreshold() const
Returns the cost threshold currently being checked for objective satisfaction.
virtual bool isSatisfied(Cost c) const
Check if the the given cost c satisfies the specified cost objective, defined as better than the spec...
virtual Cost motionCost(const State *s1, const State *s2) const =0
Get the cost that corresponds to the motion segment between s1 and s2.
virtual Cost motionCostBestEstimate(const State *s1, const State *s2) const
Defines a possibly inadmissible estimate on the optimal cost on the motion between states s1 and s2....
virtual Cost betterCost(Cost c1, Cost c2) const
Return the minimum cost given c1 and c2. Uses isCostBetterThan.
virtual bool isSymmetric() const
Check if this objective has a symmetric cost metric, i.e. motionCost(s1, s2) = motionCost(s2,...
virtual Cost infiniteCost() const
Get a cost which is greater than all other costs in this OptimizationObjective; required for use in D...
const std::string & getDescription() const
Get the description of this optimization objective.
virtual Cost initialCost(const State *s) const
Returns a cost value corresponding to starting at a state s. No optimal planners currently support th...
virtual void print(std::ostream &out) const
Print information about this optimization objective.
virtual InformedSamplerPtr allocInformedStateSampler(const ProblemDefinitionPtr &probDefn, unsigned int maxNumberCalls) const
Allocate a heuristic-sampling state generator for this cost function, defaults to a basic rejection s...
SpaceInformationPtr si_
The space information for this objective.
A shared pointer wrapper for ompl::base::ProblemDefinition.
A shared pointer wrapper for ompl::base::SpaceInformation.
Definition of an abstract state.
Definition State.h:50
Definition of an abstract control.
Definition Control.h:48
This namespace contains sampling based planning routines shared by both planning under geometric cons...
Cost goalRegionCostToGo(const State *state, const Goal *goal)
For use when the cost-to-go of a state under the optimization objective is equivalent to the goal reg...
std::function< Cost(const State *, const Goal *)> CostToGoHeuristic
The definition of a function which returns an admissible estimate of the optimal path cost from a giv...
OptimizationObjectivePtr operator+(const OptimizationObjectivePtr &a, const OptimizationObjectivePtr &b)
Given two optimization objectives, returns a MultiOptimizationObjective that combines the two objecti...
OptimizationObjectivePtr operator*(double weight, const OptimizationObjectivePtr &a)
Given a weighing factor and an optimization objective, returns a MultiOptimizationObjective containin...
Main namespace. Contains everything in this library.