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 
46  namespace tools
47  {
48 
50  OMPL_CLASS_FORWARD(ExperienceSetup);
52 
59  {
60  public:
65  {
67  : numSolutionsFromRecall_(0)
68  , numSolutionsFromRecallSaved_(0)
69  , numSolutionsFromScratch_(0)
70  , numSolutionsFailed_(0)
71  , numSolutionsTimedout_(0)
72  , numSolutionsApproximate_(0)
73  , numSolutionsTooShort_(0)
74  , numProblems_(0)
75  , totalPlanningTime_(0.0)
76  , totalInsertionTime_(0.0)
77  {
78  }
79 
80  double getAveragePlanningTime() const
81  {
82  if (!numProblems_)
83  return 0.0;
84 
85  return totalPlanningTime_ / numProblems_;
86  }
87 
88  double getAverageInsertionTime() const
89  {
90  if (!numProblems_)
91  return 0.0;
92 
93  // Clean up output
94  double time = totalInsertionTime_ / numProblems_;
95  if (time < 1e-8)
96  return 0.0;
97  else
98  return totalInsertionTime_ / numProblems_;
99  }
100 
101  double numSolutionsFromRecall_;
102  double numSolutionsFromRecallSaved_;
103  double numSolutionsFromScratch_;
104  double numSolutionsFailed_;
105  double numSolutionsTimedout_;
106  double numSolutionsApproximate_;
107  double numSolutionsTooShort_; // less than 3 states
108  double numProblems_; // input requests
109  double totalPlanningTime_; // of all input requests, used for averaging
110  double totalInsertionTime_; // of all input requests, used for averaging
111  };
112 
117  {
118  ExperienceLog()
119  // Defaults
120  : planning_time(0.0),
121  insertion_time(0.0),
122  planner("NA"),
123  result("NA"),
124  is_saved("NA"),
125  approximate(0.0),
126  too_short(0.0),
127  insertion_failed(0.0),
128  score(0.0),
129  num_vertices(0.0),
130  num_edges(0.0),
131  num_connected_components(0.0)
132  {}
133  // Times
134  double planning_time;
135  double insertion_time;
136  // Solution properties
137  std::string planner;
138  std::string result;
139  std::string is_saved;
140  // Failure booleans
141  bool approximate;
142  bool too_short;
143  bool insertion_failed;
144  // Lightning properties
145  double score;
146  // Thunder (SPARS) properties
147  std::size_t num_vertices;
148  std::size_t num_edges;
149  std::size_t num_connected_components;
150  };
151 
153  explicit
155 
157  explicit
158  ExperienceSetup(const base::StateSpacePtr &space);
159 
161  void logInitialize();
162 
164  void convertLogToString(const ExperienceLog &log);
165 
167  virtual void printResultsInfo(std::ostream &out = std::cout) const = 0;
168 
170  virtual void printLogs(std::ostream &out = std::cout) const = 0;
171 
173  virtual void saveDataLog(std::ostream &out = std::cout);
174 
178  virtual void setRepairPlanner(const base::PlannerPtr &planner) = 0;
179 
181  virtual bool save() = 0;
182 
184  virtual bool saveIfChanged() = 0;
185 
187  void enablePlanningFromRecall(bool enable);
188 
192  void enablePlanningFromScratch(bool enable);
193 
195  virtual void getAllPlannerDatas(std::vector<ompl::base::PlannerDataPtr> &plannerDatas) const = 0;
196 
198  virtual std::size_t getExperiencesCount() const = 0;
199 
201  virtual const std::string& getFilePath() const;
202 
206  virtual bool setFilePath(const std::string &filePath);
207 
211  const ExperienceStats& getStats() const
212  {
213  return stats_;
214  }
215 
219  virtual bool doPostProcessing()
220  {
221  return true;
222  }
223 
224  protected:
225 
228 
231 
233  std::string filePath_;
234 
235  // output data to file to analyze performance externally
236  std::stringstream csvDataLogStream_;
237 
240  };
241  }
242 
243 }
244 #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.
const ExperienceStats & getStats() const
Getter for logging data.
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: Cost.h:42
Create the set of classes typically needed to solve a geometric problem.
Definition: SimpleSetup.h:65
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.
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.