ExperienceSetup.cpp
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  Desc: Common functions for experience-based planning. Used by lighting and thunder
37 */
38 
39 #include "ompl/tools/experience/ExperienceSetup.h"
40 #include "ompl/tools/multiplan/ParallelPlan.h"
41 
43  : ompl::geometric::SimpleSetup(si)
44  , recallEnabled_(true)
45  , scratchEnabled_(true)
46 {
47  logInitialize();
48 };
49 
51  : ompl::geometric::SimpleSetup(space)
52 {
53  logInitialize();
54 };
55 
57 {
58  // Header of CSV file
59  csvDataLogStream_
60  // Times
61  << "planning_time,insertion_time,"
62  // Solution properties
63  << "planner,result,is_saved,"
64  // Failure booleans
65  << "approximate,too_short,insertion_failed,"
66  // Lightning properties
67  << "score,"
68  // Thunder (SPARS) properties
69  << "num_vertices,num_edges,num_connected_components,"
70  // Hack for using python cause im lazy right now
71  << "total_experiences,total_scratch,total_recall,total_failed,total_approximate,"
72  << "total_too_short,total_insertion_failed,"
73  << "avg_planning_time,avg_insertion_time"
74  << std::endl;
75 }
76 
78 {
79  csvDataLogStream_
80  << log.planning_time << ","
81  << log.insertion_time << ","
82  << log.planner << ","
83  << log.result << ","
84  << log.is_saved << ","
85  << log.approximate << ","
86  << log.too_short << ","
87  << log.insertion_failed << ","
88  << log.score << ","
89  << log.num_vertices << ","
90  << log.num_edges << ","
91  << log.num_connected_components
92  << std::endl;
93 }
94 
96 {
97  // Export to file and clear the stream
98  out << csvDataLogStream_.str();
99  csvDataLogStream_.str("");
100 }
101 
103 {
104  return filePath_;
105 }
106 
107 bool ompl::tools::ExperienceSetup::setFilePath(const std::string &filePath)
108 {
109  filePath_ = filePath;
110  return true;
111 }
112 
114 {
115  // Remember state
116  recallEnabled_ = enable;
117 
118  // Flag the planners as possibly misconfigured
119  configured_ = false;
120 }
121 
123 {
124  // Remember state
125  scratchEnabled_ = enable;
126 
127  // Flag the planners as possibly misconfigured
128  configured_ = false;
129 }
130 
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.
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 void saveDataLog(std::ostream &out=std::cout)
Save debug data about overall results since being loaded.
A shared pointer wrapper for ompl::base::SpaceInformation.
ExperienceSetup(const base::SpaceInformationPtr &si)
Constructor needs the state space used for planning.
virtual const std::string & getFilePath() const
After setFile() is called, access the generated file path for loading and saving the experience datab...
void convertLogToString(const ExperienceLog &log)
Move data to string format and put in buffer.
void enablePlanningFromRecall(bool enable)
Optionally disable the ability to use previous plans in solutions (but will still save them) ...