All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Benchmark.h
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Rice University
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 Rice University 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: Ioan Sucan */
36 
37 #ifndef OMPL_TOOLS_BENCHMARK_BENCHMARK_
38 #define OMPL_TOOLS_BENCHMARK_BENCHMARK_
39 
40 #include "ompl/geometric/SimpleSetup.h"
41 #include "ompl/control/SimpleSetup.h"
42 
43 namespace ompl
44 {
45  namespace tools
46  {
48  class Benchmark
49  {
50  public:
51 
56  struct Status
57  {
58  Status(void)
59  {
60  running = false;
61  activeRun = 0;
62  progressPercentage = 0.0;
63  }
64 
66  bool running;
67 
69  std::string activePlanner;
70 
72  unsigned int activeRun;
73 
76  };
77 
80  typedef std::map<std::string, std::string> RunProperties;
81 
83  typedef boost::function<void(const base::PlannerPtr&)> PreSetupEvent;
84 
86  typedef boost::function<void(const base::PlannerPtr&, RunProperties&)> PostSetupEvent;
87 
90  {
92  std::string name;
93 
95  std::vector<RunProperties> runs;
96 
99 
100  bool operator==(const PlannerExperiment& p) const
101  {
102  return name==p.name && runs==p.runs && common==p.common;
103  }
104  };
105 
108  {
110  std::string name;
111 
113  std::vector<PlannerExperiment> planners;
114 
116  double maxTime;
117 
119  double maxMem;
120 
122  unsigned int runCount;
123 
126 
129 
131  std::string setupInfo;
132 
134  boost::uint32_t seed;
135 
137  std::string host;
138  };
139 
141  struct Request
142  {
144  Request(double maxTime = 5.0, double maxMem = 4096.0,
145  unsigned int runCount = 100, bool displayProgress = true,
146  bool saveConsoleOutput = true, bool useThreads = true)
150  {
151  }
152 
154  double maxTime;
155 
157  double maxMem;
158 
160  unsigned int runCount;
161 
164 
167 
170  };
171 
173  Benchmark(geometric::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(&setup), csetup_(NULL)
174  {
175  exp_.name = name;
176  }
177 
179  Benchmark(control::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(NULL), csetup_(&setup)
180  {
181  exp_.name = name;
182  }
183 
184  virtual ~Benchmark(void)
185  {
186  }
187 
189  void setExperimentName(const std::string &name)
190  {
191  exp_.name = name;
192  }
193 
195  const std::string& getExperimentName(void) const
196  {
197  return exp_.name;
198  }
199 
201  void addPlanner(const base::PlannerPtr &planner)
202  {
203  if (planner && planner->getSpaceInformation().get() !=
205  throw Exception("Planner instance does not match space information");
206  planners_.push_back(planner);
207  }
208 
211  {
213  }
214 
216  void clearPlanners(void)
217  {
218  planners_.clear();
219  }
220 
223  {
224  plannerSwitch_ = event;
225  }
226 
228  void setPreRunEvent(const PreSetupEvent &event)
229  {
230  preRun_ = event;
231  }
232 
234  void setPostRunEvent(const PostSetupEvent &event)
235  {
236  postRun_ = event;
237  }
238 
250  virtual void benchmark(const Request &req);
251 
253  const Status& getStatus(void) const
254  {
255  return status_;
256  }
257 
263  {
264  return exp_;
265  }
266 
268  virtual bool saveResultsToStream(std::ostream &out = std::cout) const;
269 
271  bool saveResultsToFile(const char *filename) const;
272 
274  bool saveResultsToFile(void) const;
275 
276  protected:
277 
280 
283 
285  std::vector<base::PlannerPtr> planners_;
286 
289 
292 
295 
298 
301 
302  };
303  }
304 }
305 #endif