ompl/geometric/planners/rrt/LazyRRT.h
00001 
00002 /*********************************************************************
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2008, Willow Garage, Inc.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of the Willow Garage nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *********************************************************************/
00035 
00036 /* Author: Ioan Sucan */
00037 
00038 #ifndef OMPL_GEOMETRIC_PLANNERS_RRT_LAZY_RRT_
00039 #define OMPL_GEOMETRIC_PLANNERS_RRT_LAZY_RRT_
00040 
00041 #include "ompl/geometric/planners/PlannerIncludes.h"
00042 #include "ompl/datastructures/NearestNeighbors.h"
00043 #include <vector>
00044 
00045 namespace ompl
00046 {
00047 
00048     namespace geometric
00049     {
00050 
00078         class LazyRRT : public base::Planner
00079         {
00080         public:
00081 
00083             LazyRRT(const base::SpaceInformationPtr &si);
00084 
00085             virtual ~LazyRRT();
00086 
00087             virtual void getPlannerData(base::PlannerData &data) const;
00088 
00089             virtual base::PlannerStatus solve(const base::PlannerTerminationCondition &ptc);
00090 
00091             virtual void clear();
00092 
00102             void setGoalBias(double goalBias)
00103             {
00104                 goalBias_ = goalBias;
00105             }
00106 
00108             double getGoalBias() const
00109             {
00110                 return goalBias_;
00111             }
00112 
00118             void setRange(double distance)
00119             {
00120                 maxDistance_ = distance;
00121             }
00122 
00124             double getRange() const
00125             {
00126                 return maxDistance_;
00127             }
00128 
00130             template<template<typename T> class NN>
00131             void setNearestNeighbors()
00132             {
00133                 nn_.reset(new NN<Motion*>());
00134             }
00135 
00136             virtual void setup();
00137 
00138         protected:
00139 
00141             class Motion
00142             {
00143             public:
00144 
00145                 Motion() : state(NULL), parent(NULL), valid(false)
00146                 {
00147                 }
00148 
00150                 Motion(const base::SpaceInformationPtr &si) : state(si->allocState()), parent(NULL), valid(false)
00151                 {
00152                 }
00153 
00154                 ~Motion()
00155                 {
00156                 }
00157 
00159                 base::State          *state;
00160 
00162                 Motion               *parent;
00163 
00165                 bool                  valid;
00166 
00168                 std::vector<Motion*>  children;
00169             };
00170 
00172             void freeMemory();
00173 
00175             void removeMotion(Motion *motion);
00176 
00178             double distanceFunction(const Motion *a, const Motion *b) const
00179             {
00180                 return si_->distance(a->state, b->state);
00181             }
00182 
00184             base::StateSamplerPtr                          sampler_;
00185 
00187             boost::shared_ptr< NearestNeighbors<Motion*> > nn_;
00188 
00190             double                                         goalBias_;
00191 
00193             double                                         maxDistance_;
00194 
00196             RNG                                            rng_;
00197 
00199             Motion                                         *lastGoalMotion_;
00200 
00201         };
00202 
00203     }
00204 }
00205 
00206 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines