ExperienceSetup.h
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, University of Colorado, Boulder
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 Univ of CO, Boulder 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_EXPERIENCE__EXPERIENCE_SETUP_
39 #define OMPL_TOOLS_EXPERIENCE__EXPERIENCE_SETUP_
40 
41 #include "ompl/geometric/SimpleSetup.h"
42 
43 namespace ompl
44 {
45  namespace tools
46  {
48  OMPL_CLASS_FORWARD(ExperienceSetup);
50 
57  {
58  public:
63  {
65  : numSolutionsFromRecall_(0)
66  , numSolutionsFromRecallSaved_(0)
67  , numSolutionsFromScratch_(0)
68  , numSolutionsFailed_(0)
69  , numSolutionsTimedout_(0)
70  , numSolutionsApproximate_(0)
71  , numSolutionsTooShort_(0)
72  , numProblems_(0)
73  , totalPlanningTime_(0.0)
74  , totalInsertionTime_(0.0)
75  {
76  }
77 
78  double getAveragePlanningTime() const
79  {
80  if (!numProblems_)
81  return 0.0;
82 
83  return totalPlanningTime_ / numProblems_;
84  }
85 
86  double getAverageInsertionTime() const
87  {
88  if (!numProblems_)
89  return 0.0;
90 
91  // Clean up output
92  double time = totalInsertionTime_ / numProblems_;
93  if (time < 1e-8)
94  return 0.0;
95  else
96  return totalInsertionTime_ / numProblems_;
97  }
98 
99  double numSolutionsFromRecall_;
100  double numSolutionsFromRecallSaved_;
101  double numSolutionsFromScratch_;
102  double numSolutionsFailed_;
103  double numSolutionsTimedout_;
104  double numSolutionsApproximate_;
105  double numSolutionsTooShort_; // less than 3 states
106  double numProblems_; // input requests
107  double totalPlanningTime_; // of all input requests, used for averaging
108  double totalInsertionTime_; // of all input requests, used for averaging
109  };
110 
115  {
116  ExperienceLog()
117  // Defaults
118  : planning_time(0.0),
119  insertion_time(0.0),
120  planner("NA"),
121  result("NA"),
122  is_saved("NA"),
123  approximate(0.0),
124  too_short(0.0),
125  insertion_failed(0.0),
126  score(0.0),
127  num_vertices(0.0),
128  num_edges(0.0),
129  num_connected_components(0.0)
130  {
131  }
132  // Times
133  double planning_time;
134  double insertion_time;
135  // Solution properties
136  std::string planner;
137  std::string result;
138  std::string is_saved;
139  // Failure booleans
140  bool approximate;
141  bool too_short;
142  bool insertion_failed;
143  // Lightning properties
144  double score;
145  // Thunder (SPARS) properties
146  std::size_t num_vertices;
147  std::size_t num_edges;
148  std::size_t num_connected_components;
149  };
150 
152  explicit ExperienceSetup(const base::SpaceInformationPtr &si);
153 
155  explicit ExperienceSetup(const base::StateSpacePtr &space);
156 
158  void logInitialize();
159 
161  void convertLogToString(const ExperienceLog &log);
162 
164  virtual void printResultsInfo(std::ostream &out = std::cout) const = 0;
165 
167  virtual void printLogs(std::ostream &out = std::cout) const = 0;
168 
170  virtual void saveDataLog(std::ostream &out = std::cout);
171 
175  virtual void setRepairPlanner(const base::PlannerPtr &planner) = 0;
176 
178  virtual bool save() = 0;
179 
181  virtual bool saveIfChanged() = 0;
182 
184  void enablePlanningFromRecall(bool enable);
185 
189  void enablePlanningFromScratch(bool enable);
190 
192  virtual void getAllPlannerDatas(std::vector<ompl::base::PlannerDataPtr> &plannerDatas) const = 0;
193 
195  virtual std::size_t getExperiencesCount() const = 0;
196 
199  virtual const std::string &getFilePath() const;
200 
204  virtual bool setFilePath(const std::string &filePath);
205 
209  const ExperienceStats &getStats() const
210  {
211  return stats_;
212  }
213 
217  virtual bool doPostProcessing()
218  {
219  return true;
220  }
221 
222  protected:
225 
228 
230  std::string filePath_;
231 
232  // output data to file to analyze performance externally
233  std::stringstream csvDataLogStream_;
234 
237  };
238  }
239 }
240 #endif
virtual void setRepairPlanner(const base::PlannerPtr &planner)=0
Set the planner to use for repairing experience paths inside the RetrieveRepair planner. If the planner is not set, a default planner is set.
Single entry for the csv data logging file.
void log(const char *file, int line, LogLevel level, const char *m,...)
Root level logging function. This should not be invoked directly, but rather used via a logging macro...
Definition: Console.cpp:120
A shared pointer wrapper for ompl::base::StateSpace.
void logInitialize()
Load the header (first row) of the csv file.
Simple logging functionality encapsled in a struct.
virtual bool setFilePath(const std::string &filePath)
Set the database file to load. Actual loading occurs when setup() is called.
void enablePlanningFromScratch(bool enable)
Optionally disable the ability to plan from scratch Note: Lightning can still save modified experienc...
virtual bool doPostProcessing()
Allow accumlated experiences to be processed.
virtual void printLogs(std::ostream &out=std::cout) const =0
Display debug data about overall results since being loaded.
virtual void saveDataLog(std::ostream &out=std::cout)
Save debug data about overall results since being loaded.
ExperienceStats stats_
States data for display to console.
virtual void printResultsInfo(std::ostream &out=std::cout) const =0
Display debug data about potential available solutions.
virtual std::size_t getExperiencesCount() const =0
Get the total number of paths stored in the database.
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
Create the set of classes typically needed to solve a geometric problem.
Definition: SimpleSetup.h:63
A shared pointer wrapper for ompl::base::Planner.
std::string filePath_
File location of database.
virtual void getAllPlannerDatas(std::vector< ompl::base::PlannerDataPtr > &plannerDatas) const =0
Get a vector of all the planning data in the database.
A shared pointer wrapper for ompl::base::SpaceInformation.
ExperienceSetup(const base::SpaceInformationPtr &si)
Constructor needs the state space used for planning.
const ExperienceStats & getStats() const
Getter for logging data.
bool scratchEnabled_
Flag indicating whether planning from scratch should be used to find solutions. Enabled by default...
virtual const std::string & getFilePath() const
After setFile() is called, access the generated file path for loading and saving the experience datab...
virtual bool save()=0
Save the experience database to file.
bool recallEnabled_
Flag indicating whether recalled plans should be used to find solutions. Enabled by default...
void convertLogToString(const ExperienceLog &log)
Move data to string format and put in buffer.
virtual bool saveIfChanged()=0
Save the experience database to file if there has been a change.
void enablePlanningFromRecall(bool enable)
Optionally disable the ability to use previous plans in solutions (but will still save them) ...
Create the set of classes typically needed to solve a geometric problem.