Thunder.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, JSK, The University of Tokyo.
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 JSK, The University of Tokyo 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: Dave Coleman
36 */
37 
38 #ifndef OMPL_TOOLS_THUNDER_THUNDER_
39 #define OMPL_TOOLS_THUNDER_THUNDER_
40 
41 #include <ompl/tools/experience/ExperienceSetup.h> // the parent class
42 
43 #include <ompl/tools/thunder/ThunderDB.h>
44 #include <ompl/geometric/planners/experience/ThunderRetrieveRepair.h>
45 
46 #include <ompl/base/Planner.h>
47 #include <ompl/base/PlannerData.h>
48 #include <ompl/base/ProblemDefinition.h>
49 #include <ompl/base/SpaceInformation.h>
50 #include <ompl/base/ProblemDefinition.h>
51 #include <ompl/base/StateSpace.h> // for storing to file
52 
53 #include <ompl/geometric/PathGeometric.h>
54 #include <ompl/geometric/PathSimplifier.h>
55 
56 #include <ompl/tools/multiplan/ParallelPlan.h>
57 
58 #include <ompl/util/Console.h>
59 #include <ompl/util/Exception.h>
60 
61 namespace ompl
62 {
63 
64  namespace tools
65  {
77  OMPL_CLASS_FORWARD(Thunder);
80 
86  {
87  public:
88 
90  explicit
92 
96  explicit
97  Thunder(const base::StateSpacePtr &space);
98 
99  private:
100 
102  void initialize();
103 
104  public:
105 
107  void printResultsInfo(std::ostream &out = std::cout) const;
108 
110  void printLogs(std::ostream &out = std::cout) const;
111 
114  {
115  return planner_;
116  }
117 
120  {
121  return static_cast<ompl::geometric::ThunderRetrieveRepair&>(*rrPlanner_);
122  }
123 
127  void setRepairPlanner(const base::PlannerPtr &planner)
128  {
129  static_cast<ompl::geometric::ThunderRetrieveRepair&>(*rrPlanner_).setRepairPlanner(planner);
130  }
131 
136 
138  virtual base::PlannerStatus solve(double time = 1.0);
139 
142 
144  bool save();
145 
147  bool saveIfChanged();
148 
152  virtual void clear(void);
153 
155  virtual void print(std::ostream &out = std::cout) const;
156 
159  virtual void setup(void);
160 
162  void getAllPlannerDatas(std::vector<ompl::base::PlannerDataPtr> &plannerDatas) const;
163 
165  std::size_t getExperiencesCount() const;
166 
169 
177 
179  ompl::tools::ThunderDBPtr getExperienceDB();
180 
182  bool doPostProcessing();
183 
184  protected:
185 
188 
191 
194 
196  ompl::tools::ParallelPlanPtr pp_;
197 
199  ompl::tools::ThunderDBPtr experienceDB_;
200 
202  std::vector<ompl::geometric::PathGeometric> queuedSolutionPaths_;
203 
204  }; // end of class Thunder
205 
206  } // end of namespace
207 
208 } // end of namespace
209 #endif
210 
base::PlannerPtr rrPlanner_
Definition: Thunder.h:187
std::vector< ompl::geometric::PathGeometric > queuedSolutionPaths_
Accumulated experiences to be later added to experience database.
Definition: Thunder.h:202
std::size_t getExperiencesCount() const
Get the total number of paths stored in the database.
Definition: Thunder.cpp:480
ompl::tools::ThunderDBPtr getExperienceDB()
Hook for getting access to debug data.
Definition: Thunder.cpp:519
ompl::geometric::ThunderRetrieveRepair & getRetrieveRepairPlanner() const
Get a pointer to the retrieve repair planner.
Definition: Thunder.h:119
A shared pointer wrapper for ompl::base::StateSpace.
bool saveIfChanged()
Save the experience database to file if there has been a change.
Definition: Thunder.cpp:410
ompl::tools::ParallelPlanPtr pp_
Instance of parallel planning to use for computing solutions in parallel.
Definition: Thunder.h:196
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
base::PlannerPtr planner2_
Definition: Thunder.h:190
virtual base::PlannerStatus solve(double time=1.0)
Run the planner for up to a specified amount of time (default is 1 second)
Definition: Thunder.cpp:398
Built off of SimpleSetup but provides support for planning from experience.
Definition: Thunder.h:85
bool reversePathIfNecessary(ompl::geometric::PathGeometric &path1, ompl::geometric::PathGeometric &path2)
If path1 and path2 have a better start/goal match when reverse, then reverse path2.
Definition: Thunder.cpp:497
virtual void print(std::ostream &out=std::cout) const
Print information about the current setup.
Definition: Thunder.cpp:427
bool doPostProcessing()
Allow accumlated experiences to be processed.
Definition: Thunder.cpp:524
The Thunder Framework's Retrieve-Repair component.
Thunder(const base::SpaceInformationPtr &si)
Constructor needs the state space used for planning.
Definition: Thunder.cpp:46
std::function< PlannerPtr(const SpaceInformationPtr &)> PlannerAllocator
Definition of a function that can allocate a planner.
Definition: Planner.h:423
A shared pointer wrapper for ompl::base::Planner.
void printLogs(std::ostream &out=std::cout) const
Display debug data about overall results from Thunder since being loaded.
Definition: Thunder.cpp:453
base::PlannerPtr planner_
The maintained planner instance.
Definition: SimpleSetup.h:283
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
A shared pointer wrapper for ompl::base::SpaceInformation.
void setPlannerAllocator(const base::PlannerAllocator &pa)
Set the planner allocator to use. This is only used if no planner has been set. This is optional – a ...
Definition: Thunder.cpp:191
void setRepairPlanner(const base::PlannerPtr &planner)
Set the planner that will be used for repairing invalid paths recalled from experience.
bool save()
Save the experience database to file.
Definition: Thunder.cpp:404
virtual void clear(void)
Clear all planning data. This only includes data generated by motion plan computation. Planner settings, start & goal states are not affected.
Definition: Thunder.cpp:175
void convertPlannerData(const ompl::base::PlannerDataPtr plannerData, ompl::geometric::PathGeometric &path)
Convert PlannerData to PathGeometric. Assume ordering of verticies is order of path.
Definition: Thunder.cpp:490
ompl::base::PlannerPtr & getPlanner()
Get the current planner.
Definition: Thunder.h:113
Definition of a geometric path.
Definition: PathGeometric.h:60
void printResultsInfo(std::ostream &out=std::cout) const
Display debug data about potential available solutions.
Definition: Thunder.cpp:416
virtual void setup(void)
This method will create the necessary classes for planning. The solve() method will call this functio...
Definition: Thunder.cpp:78
void setRepairPlanner(const base::PlannerPtr &planner)
Set the planner to use for repairing experience paths inside the ThunderRetrieveRepair planner...
Definition: Thunder.h:127
bool dualThreadScratchEnabled_
Definition: Thunder.h:193
A shared pointer wrapper for ompl::base::PlannerData.
Create the set of classes typically needed to solve a geometric problem.
void getAllPlannerDatas(std::vector< ompl::base::PlannerDataPtr > &plannerDatas) const
Get a vector of all the planning data in the database.
Definition: Thunder.cpp:485
ompl::tools::ThunderDBPtr experienceDB_
A shared object between all the planners for saving and loading previous experience.
Definition: Thunder.h:199