00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef OMPL_TOOLS_BENCHMARK_BENCHMARK_
00038 #define OMPL_TOOLS_BENCHMARK_BENCHMARK_
00039
00040 #include "ompl/geometric/SimpleSetup.h"
00041 #include "ompl/control/SimpleSetup.h"
00042
00043 namespace ompl
00044 {
00045
00047 class Benchmark
00048 {
00049 public:
00050
00055 struct Status
00056 {
00057 Status(void)
00058 {
00059 running = false;
00060 activeRun = 0;
00061 progressPercentage = 0.0;
00062 }
00063
00065 bool running;
00066
00068 std::string activePlanner;
00069
00071 unsigned int activeRun;
00072
00074 double progressPercentage;
00075 };
00076
00079 typedef std::map<std::string, std::string> RunProperties;
00080
00082 typedef boost::function1<void, const base::PlannerPtr&> PreSetupEvent;
00083
00085 typedef boost::function2<void, const base::PlannerPtr&, RunProperties&> PostSetupEvent;
00086
00088 struct PlannerExperiment
00089 {
00091 std::string name;
00092
00094 std::vector<RunProperties> runs;
00095
00097 RunProperties common;
00098 };
00099
00101 struct CompleteExperiment
00102 {
00104 std::string name;
00105
00107 std::vector<PlannerExperiment> planners;
00108
00110 double maxTime;
00111
00113 double maxMem;
00114
00116 time::point startTime;
00117
00119 double totalDuration;
00120
00122 std::string setupInfo;
00123
00125 boost::uint32_t seed;
00126
00128 std::string host;
00129 };
00130
00132 Benchmark(geometric::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(&setup), csetup_(NULL), msg_("Benchmark")
00133 {
00134 exp_.name = name;
00135 }
00136
00138 Benchmark(control::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(NULL), csetup_(&setup), msg_("Benchmark")
00139 {
00140 exp_.name = name;
00141 }
00142
00143 virtual ~Benchmark(void)
00144 {
00145 }
00146
00148 void setExperimentName(const std::string &name)
00149 {
00150 exp_.name = name;
00151 }
00152
00154 const std::string& getExperimentName(void) const
00155 {
00156 return exp_.name;
00157 }
00158
00163 void addPlanner(const base::PlannerPtr &planner)
00164 {
00165 if (planner && planner->getSpaceInformation().get() !=
00166 (gsetup_ ? gsetup_->getSpaceInformation().get() : csetup_->getSpaceInformation().get()))
00167 throw Exception("Planner instance does not match space information");
00168 planners_.push_back(planner);
00169 }
00170
00174 void addPlannerAllocator(const base::PlannerAllocator &pa)
00175 {
00176 planners_.push_back(pa(gsetup_ ? gsetup_->getSpaceInformation() : csetup_->getSpaceInformation()));
00177 }
00178
00180 void clearPlanners(void)
00181 {
00182 planners_.clear();
00183 }
00184
00186 void setPreRunEvent(const PreSetupEvent &event)
00187 {
00188 preRun_ = event;
00189 }
00190
00192 void setPostRunEvent(const PostSetupEvent &event)
00193 {
00194 postRun_ = event;
00195 }
00196
00212 virtual void benchmark(double maxTime, double maxMem, unsigned int runCount, bool displayProgress = false);
00213
00215 const Status& getStatus(void) const
00216 {
00217 return status_;
00218 }
00219
00224 const CompleteExperiment& getRecordedExperimentData(void) const
00225 {
00226 return exp_;
00227 }
00228
00230 virtual bool saveResultsToStream(std::ostream &out = std::cout) const;
00231
00233 bool saveResultsToFile(const char *filename) const;
00234
00236 bool saveResultsToFile(void) const;
00237
00238 protected:
00239
00241 std::string getResultsFilename(void) const;
00242
00244 geometric::SimpleSetup *gsetup_;
00245
00247 control::SimpleSetup *csetup_;
00248
00250 std::vector<base::PlannerPtr> planners_;
00251
00253 CompleteExperiment exp_;
00254
00256 Status status_;
00257
00259 PreSetupEvent preRun_;
00260
00262 PostSetupEvent postRun_;
00263
00265 msg::Interface msg_;
00266
00267 };
00268
00269 }
00270 #endif