ThunderDB.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_THUNDERDB_
39 #define OMPL_TOOLS_THUNDER_THUNDERDB_
40 
41 #include <ompl/base/StateSpace.h>
42 #include <ompl/geometric/PathGeometric.h>
43 #include <ompl/base/PlannerData.h>
44 #include <ompl/base/PlannerDataStorage.h>
45 #include <ompl/base/State.h>
46 #include <ompl/base/SpaceInformation.h>
47 #include <ompl/datastructures/NearestNeighbors.h>
48 #include <ompl/tools/thunder/SPARSdb.h>
49 
50 namespace ompl
51 {
52 
53  namespace tools
54  {
61  OMPL_CLASS_FORWARD(ThunderDB);
64 
65  typedef std::shared_ptr<ompl::geometric::SPARSdb> SPARSdbPtr;
66 
71  class ThunderDB
72  {
73  public:
74 
78  ThunderDB(const base::StateSpacePtr &space);
79 
81  virtual ~ThunderDB(void);
82 
88  bool load(const std::string& fileName);
89 
97  bool addPath(ompl::geometric::PathGeometric& solutionPath, double& insertionTime);
98 
104  bool saveIfChanged(const std::string& fileName);
105 
111  bool save(const std::string& fileName);
112 
116  void getAllPlannerDatas(std::vector<ompl::base::PlannerDataPtr> &plannerDatas) const;
117 
120 
123 
125  bool findNearestStartGoal(int nearestK, const base::State* start, const base::State* goal,
128 
130  void debugVertex(const ompl::base::PlannerDataVertex& vertex);
131  void debugState(const ompl::base::State* state);
132 
135  {
136  return numPathsInserted_;
137  }
138 
141  {
142  return saving_enabled_;
143  }
144 
146  void setSavingEnabled(bool saving_enabled)
147  {
148  saving_enabled_ = saving_enabled;
149  }
150 
155  bool isEmpty()
156  {
157  return !spars_->getNumVertices();
158  }
159 
160  protected:
161 
163  base::SpaceInformationPtr si_; // TODO: is this even necessary?
164 
167 
168  // Track unsaved paths to determine if a save is required
169  int numPathsInserted_;
170 
171  // Use SPARSdb's graph datastructure to store experience
173 
174  // Allow the database to save to file (new experiences)
175  bool saving_enabled_;
176 
177  }; // end of class ThunderDB
178 
179  } // end of namespace
180 
181 } // end of namespace
182 #endif
ompl::tools::SPARSdbPtr & getSPARSdb()
Hook for debugging.
Definition: ThunderDB.cpp:259
base::SpaceInformationPtr si_
The created space information.
Definition: ThunderDB.h:163
Object that handles loading/storing a PlannerData object to/from a binary stream. Serialization of ve...
bool getSavingEnabled()
Getter for enabling experience database saving.
Definition: ThunderDB.h:140
bool save(const std::string &fileName)
Save loaded database to file.
Definition: ThunderDB.cpp:175
A shared pointer wrapper for ompl::base::StateSpace.
Encapsulate a termination condition for a motion planner. Planners will call operator() to decide whe...
int getNumPathsInserted() const
Get number of unsaved paths.
Definition: ThunderDB.h:134
Struct for passing around partially solved solutions.
Definition: SPARSdb.h:240
bool findNearestStartGoal(int nearestK, const base::State *start, const base::State *goal, ompl::geometric::SPARSdb::CandidateSolution &candidateSolution, const base::PlannerTerminationCondition &ptc)
Find the k nearest paths to our queries one.
Definition: ThunderDB.cpp:279
virtual ~ThunderDB(void)
Deconstructor.
Definition: ThunderDB.cpp:56
Base class for a vertex in the PlannerData structure. All derived classes must implement the clone an...
Definition: PlannerData.h:59
Main namespace. Contains everything in this library.
Definition: Cost.h:42
bool addPath(ompl::geometric::PathGeometric &solutionPath, double &insertionTime)
Add a new solution path to our database. Des not actually save to file so experience will be lost if ...
Definition: ThunderDB.cpp:130
void getAllPlannerDatas(std::vector< ompl::base::PlannerDataPtr > &plannerDatas) const
Get a vector of all the planner datas in the database.
Definition: ThunderDB.cpp:264
ompl::base::PlannerDataStorage plannerDataStorage_
Helper class for storing each plannerData instance.
Definition: ThunderDB.h:166
A shared pointer wrapper for ompl::base::SpaceInformation.
bool load(const std::string &fileName)
Load database from file.
Definition: ThunderDB.cpp:62
Definition of an abstract state.
Definition: State.h:50
Save and load entire paths from file.
Definition: ThunderDB.h:71
bool isEmpty()
Check if anything has been loaded into DB.
Definition: ThunderDB.h:155
ThunderDB(const base::StateSpacePtr &space)
Constructor needs the state space used for planning.
Definition: ThunderDB.cpp:48
void setSPARSdb(ompl::tools::SPARSdbPtr &prm)
Create the database structure for saving experiences.
Definition: ThunderDB.cpp:251
void debugVertex(const ompl::base::PlannerDataVertex &vertex)
Print info to screen.
Definition: ThunderDB.cpp:297
Definition of a geometric path.
Definition: PathGeometric.h:60
bool saveIfChanged(const std::string &fileName)
Save loaded database to file, except skips saving if no paths have been added.
Definition: ThunderDB.cpp:166
std::shared_ptr< ompl::geometric::SPARSdb > SPARSdbPtr
Definition: ThunderDB.h:65
void setSavingEnabled(bool saving_enabled)
Setter for enabling experience database saving.
Definition: ThunderDB.h:146