SelfConfig.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Rice University.
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 Rice University 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: Ioan Sucan */
36 
37 #ifndef OMPL_TOOLS_SELF_CONFIG_
38 #define OMPL_TOOLS_SELF_CONFIG_
39 
40 #include "ompl/config.h"
41 #include "ompl/base/Goal.h"
42 #include "ompl/base/Planner.h"
43 #include "ompl/base/SpaceInformation.h"
44 #include "ompl/datastructures/NearestNeighborsSqrtApprox.h"
45 #include "ompl/datastructures/NearestNeighborsGNAT.h"
46 #include "ompl/datastructures/NearestNeighborsGNATNoThreadSafety.h"
47 #include <mutex>
48 #include <iostream>
49 #include <string>
50 
51 namespace ompl
52 {
54  namespace tools
55  {
59  class SelfConfig
60  {
61  public:
65  SelfConfig(const base::SpaceInformationPtr &si, const std::string &context = std::string());
66 
67  ~SelfConfig();
68 
72 
76 
82  void configureValidStateSamplingAttempts(unsigned int &attempts);
83 
85  void configurePlannerRange(double &range);
86 
91 
93  void print(std::ostream &out = std::cout) const;
94 
96  template <typename _T>
98  {
99  const base::StateSpacePtr &space = planner->getSpaceInformation()->getStateSpace();
100  const base::PlannerSpecs &specs = planner->getSpecs();
101  if (space->isMetricSpace())
102  {
103  if (specs.multithreaded)
104  return new NearestNeighborsGNAT<_T>();
106  }
107  return new NearestNeighborsSqrtApprox<_T>();
108  }
109 
112 
113  private:
115  class SelfConfigImpl;
116 
117  SelfConfigImpl *impl_;
118  std::string context_;
119  static std::mutex staticConstructorLock_;
121  };
122  }
123 }
124 
125 #endif
const SpaceInformationPtr & getSpaceInformation() const
Get the space information this planner is using.
Definition: Planner.cpp:66
Properties that planners may have.
Definition: Planner.h:192
A shared pointer wrapper for ompl::base::StateSpace.
void print(std::ostream &out=std::cout) const
Print the computed configuration parameters.
Definition: SelfConfig.cpp:237
Geometric Near-neighbor Access Tree (GNAT), a data structure for nearest neighbor search...
bool multithreaded
Flag indicating whether multiple threads are used in the computation of the planner.
Definition: Planner.h:200
const PlannerSpecs & getSpecs() const
Return the specifications (capabilities of this planner)
Definition: Planner.cpp:51
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
A nearest neighbors datastructure that uses linear search. The linear search is done over sqrt(n) ele...
A shared pointer wrapper for ompl::base::Planner.
Geometric Near-neighbor Access Tree (GNAT), a data structure for nearest neighbor search...
static NearestNeighbors< _T > * getDefaultNearestNeighbors(const base::Planner *planner)
Select a default nearest neighbor datastructure for the given space.
Definition: SelfConfig.h:97
Base class for a planner.
Definition: Planner.h:223
double getAverageValidMotionLength()
Get the probability of a sampled state being valid (calls base::SpaceInformation::averageValidMotionL...
Definition: SelfConfig.cpp:213
A shared pointer wrapper for ompl::base::ProjectionEvaluator.
A shared pointer wrapper for ompl::base::SpaceInformation.
SelfConfig(const base::SpaceInformationPtr &si, const std::string &context=std::string())
Construct an instance that can configure the space encapsulated by si. Any information printed to the...
Definition: SelfConfig.cpp:173
Abstract representation of a container that can perform nearest neighbors queries.
static base::PlannerPtr getDefaultPlanner(const base::GoalPtr &goal)
Given a goal specification, decide on a planner for that goal.
Definition: SelfConfig.cpp:243
void configureProjectionEvaluator(base::ProjectionEvaluatorPtr &proj)
If proj is undefined, it is set to the default projection reported by base::StateSpace::getDefaultPro...
Definition: SelfConfig.cpp:231
double getProbabilityOfValidState()
Get the probability of a sampled state being valid (calls base::SpaceInformation::probabilityOfValidS...
Definition: SelfConfig.cpp:207
void configurePlannerRange(double &range)
Compute what a good length for motion segments is.
Definition: SelfConfig.cpp:225
This class contains methods that automatically configure various parameters for motion planning...
Definition: SelfConfig.h:59
A shared pointer wrapper for ompl::base::Goal.
void configureValidStateSamplingAttempts(unsigned int &attempts)
Instances of base::ValidStateSampler need a number of attempts to be specified – the maximum number ...
Definition: SelfConfig.cpp:219