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 namespace tools
00046 {
00048 class Benchmark
00049 {
00050 public:
00051
00056 struct Status
00057 {
00058 Status(void)
00059 {
00060 running = false;
00061 activeRun = 0;
00062 progressPercentage = 0.0;
00063 }
00064
00066 bool running;
00067
00069 std::string activePlanner;
00070
00072 unsigned int activeRun;
00073
00075 double progressPercentage;
00076 };
00077
00080 typedef std::map<std::string, std::string> RunProperties;
00081
00083 typedef boost::function<void(const base::PlannerPtr&)> PreSetupEvent;
00084
00086 typedef boost::function<void(const base::PlannerPtr&, RunProperties&)> PostSetupEvent;
00087
00089 struct PlannerExperiment
00090 {
00092 std::string name;
00093
00095 std::vector<RunProperties> runs;
00096
00098 RunProperties common;
00099
00100 bool operator==(const PlannerExperiment& p) const
00101 {
00102 return name==p.name && runs==p.runs && common==p.common;
00103 }
00104 };
00105
00107 struct CompleteExperiment
00108 {
00110 std::string name;
00111
00113 std::vector<PlannerExperiment> planners;
00114
00116 double maxTime;
00117
00119 double maxMem;
00120
00122 unsigned int runCount;
00123
00125 time::point startTime;
00126
00128 double totalDuration;
00129
00131 std::string setupInfo;
00132
00134 boost::uint32_t seed;
00135
00137 std::string host;
00138 };
00139
00141 struct Request
00142 {
00144 Request(double maxTime = 5.0, double maxMem = 4096.0,
00145 unsigned int runCount = 100, bool displayProgress = true,
00146 bool saveConsoleOutput = true, bool useThreads = true)
00147 : maxTime(maxTime), maxMem(maxMem), runCount(runCount),
00148 displayProgress(displayProgress), saveConsoleOutput(saveConsoleOutput),
00149 useThreads(useThreads)
00150 {
00151 }
00152
00154 double maxTime;
00155
00157 double maxMem;
00158
00160 unsigned int runCount;
00161
00163 bool displayProgress;
00164
00166 bool saveConsoleOutput;
00167
00169 bool useThreads;
00170 };
00171
00173 Benchmark(geometric::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(&setup), csetup_(NULL), msg_("Benchmark")
00174 {
00175 exp_.name = name;
00176 }
00177
00179 Benchmark(control::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(NULL), csetup_(&setup), msg_("Benchmark")
00180 {
00181 exp_.name = name;
00182 }
00183
00184 virtual ~Benchmark(void)
00185 {
00186 }
00187
00189 void setExperimentName(const std::string &name)
00190 {
00191 exp_.name = name;
00192 }
00193
00195 const std::string& getExperimentName(void) const
00196 {
00197 return exp_.name;
00198 }
00199
00201 void addPlanner(const base::PlannerPtr &planner)
00202 {
00203 if (planner && planner->getSpaceInformation().get() !=
00204 (gsetup_ ? gsetup_->getSpaceInformation().get() : csetup_->getSpaceInformation().get()))
00205 throw Exception("Planner instance does not match space information");
00206 planners_.push_back(planner);
00207 }
00208
00210 void addPlannerAllocator(const base::PlannerAllocator &pa)
00211 {
00212 planners_.push_back(pa(gsetup_ ? gsetup_->getSpaceInformation() : csetup_->getSpaceInformation()));
00213 }
00214
00216 void clearPlanners(void)
00217 {
00218 planners_.clear();
00219 }
00220
00222 void setPlannerSwitchEvent(const PreSetupEvent &event)
00223 {
00224 plannerSwitch_ = event;
00225 }
00226
00228 void setPreRunEvent(const PreSetupEvent &event)
00229 {
00230 preRun_ = event;
00231 }
00232
00234 void setPostRunEvent(const PostSetupEvent &event)
00235 {
00236 postRun_ = event;
00237 }
00238
00250 virtual void benchmark(const Request &req);
00251
00253 const Status& getStatus(void) const
00254 {
00255 return status_;
00256 }
00257
00262 const CompleteExperiment& getRecordedExperimentData(void) const
00263 {
00264 return exp_;
00265 }
00266
00268 virtual bool saveResultsToStream(std::ostream &out = std::cout) const;
00269
00271 bool saveResultsToFile(const char *filename) const;
00272
00274 bool saveResultsToFile(void) const;
00275
00276 protected:
00277
00279 geometric::SimpleSetup *gsetup_;
00280
00282 control::SimpleSetup *csetup_;
00283
00285 std::vector<base::PlannerPtr> planners_;
00286
00288 CompleteExperiment exp_;
00289
00291 Status status_;
00292
00294 PreSetupEvent plannerSwitch_;
00295
00297 PreSetupEvent preRun_;
00298
00300 PostSetupEvent postRun_;
00301
00303 msg::Interface msg_;
00304
00305 };
00306 }
00307 }
00308 #endif