Benchmark.cpp
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, Luis G. Torres */
36 
37 #include "ompl/tools/benchmark/Benchmark.h"
38 #include "ompl/tools/benchmark/MachineSpecs.h"
39 #include "ompl/util/Time.h"
40 #include "ompl/config.h"
41 #include <boost/scoped_ptr.hpp>
42 #include <boost/progress.hpp>
43 #include <thread>
44 #include <mutex>
45 #include <condition_variable>
46 #include <fstream>
47 #include <sstream>
48 
50 namespace ompl
51 {
52  namespace tools
53  {
56  static std::string getResultsFilename(const Benchmark::CompleteExperiment &exp)
57  {
58  return "ompl_" + exp.host + "_" + time::as_string(exp.startTime) + ".log";
59  }
60 
63  static std::string getConsoleFilename(const Benchmark::CompleteExperiment &exp)
64  {
65  return "ompl_" + exp.host + "_" + time::as_string(exp.startTime) + ".console";
66  }
67 
68  static bool terminationCondition(const machine::MemUsage_t maxMem, const time::point &endTime)
69  {
70  if (time::now() < endTime && machine::getProcessMemoryUsage() < maxMem)
71  return false;
72  return true;
73  }
74 
75  class RunPlanner
76  {
77  public:
78  RunPlanner(const Benchmark *benchmark, bool useThreads)
79  : benchmark_(benchmark), timeUsed_(0.0), memUsed_(0), useThreads_(useThreads)
80  {
81  }
82 
83  void run(const base::PlannerPtr &planner, const machine::MemUsage_t memStart,
84  const machine::MemUsage_t maxMem, const double maxTime, const double timeBetweenUpdates)
85  {
86  // if (!useThreads_)
87  // {
88  runThread(planner, memStart + maxMem, time::seconds(maxTime), time::seconds(timeBetweenUpdates));
89  // return;
90  // }
91 
92  // std::thread t([planner, memStart, maxMem, maxTime, timeBetweenUpdates]
93  // {
94  // runThread(planner, memStart + maxMem, time::seconds(maxTime),
95  // time::seconds(timeBetweenUpdates)); });
96  // }
97 
98  // allow 25% more time than originally specified, in order to detect planner termination
99  // if (!t.try_join_for(time::seconds(maxTime * 1.25)))
100  // {
101  // status_ = base::PlannerStatus::CRASH;
102  //
103  // std::stringstream es;
104  // es << "Planner " << benchmark_->getStatus().activePlanner << " did not complete run " <<
105  // benchmark_->getStatus().activeRun
106  // << " within the specified amount of time (possible crash). Attempting to force termination of
107  // planning thread ..." << std::endl;
108  // std::cerr << es.str();
109  // OMPL_ERROR(es.str().c_str());
110  //
111  // t.interrupt();
112  // t.join();
113  //
114  // std::string m = "Planning thread cancelled";
115  // std::cerr << m << std::endl;
116  // OMPL_ERROR(m.c_str());
117  // }
118 
119  // if (memStart < memUsed_)
120  // memUsed_ -= memStart;
121  // else
122  // memUsed_ = 0;
123  }
124 
125  double getTimeUsed() const
126  {
127  return timeUsed_;
128  }
129 
130  machine::MemUsage_t getMemUsed() const
131  {
132  return memUsed_;
133  }
134 
135  base::PlannerStatus getStatus() const
136  {
137  return status_;
138  }
139 
140  const Benchmark::RunProgressData &getRunProgressData() const
141  {
142  return runProgressData_;
143  }
144 
145  private:
146  void runThread(const base::PlannerPtr &planner, const machine::MemUsage_t maxMem,
147  const time::duration &maxDuration, const time::duration &timeBetweenUpdates)
148  {
149  time::point timeStart = time::now();
150 
151  try
152  {
153  const time::point endtime = time::now() + maxDuration;
154  base::PlannerTerminationConditionFn ptc([maxMem, endtime]
155  {
156  return terminationCondition(maxMem, endtime);
157  });
158  solved_ = false;
159  // Only launch the planner progress property
160  // collector if there is any data for it to report
161  //
162  // \todo issue here is that at least one sample
163  // always gets taken before planner even starts;
164  // might be worth adding a short wait time before
165  // collector begins sampling
166  boost::scoped_ptr<std::thread> t;
167  if (planner->getPlannerProgressProperties().size() > 0)
168  t.reset(new std::thread([this, &planner, timeBetweenUpdates]
169  {
170  collectProgressProperties(planner->getPlannerProgressProperties(),
171  timeBetweenUpdates);
172  }));
173  status_ = planner->solve(ptc, 0.1);
174  solvedFlag_.lock();
175  solved_ = true;
176  solvedCondition_.notify_all();
177  solvedFlag_.unlock();
178  if (t)
179  t->join(); // maybe look into interrupting even if planner throws an exception
180  }
181  catch (std::runtime_error &e)
182  {
183  std::stringstream es;
184  es << "There was an error executing planner " << benchmark_->getStatus().activePlanner
185  << ", run = " << benchmark_->getStatus().activeRun << std::endl;
186  es << "*** " << e.what() << std::endl;
187  std::cerr << es.str();
188  OMPL_ERROR(es.str().c_str());
189  }
190 
191  timeUsed_ = time::seconds(time::now() - timeStart);
192  memUsed_ = machine::getProcessMemoryUsage();
193  }
194 
195  void collectProgressProperties(const base::Planner::PlannerProgressProperties &properties,
196  const time::duration &timePerUpdate)
197  {
198  time::point timeStart = time::now();
199 
200  std::unique_lock<std::mutex> ulock(solvedFlag_);
201  while (!solved_)
202  {
203  if (solvedCondition_.wait_for(ulock, timePerUpdate) == std::cv_status::no_timeout)
204  return;
205  else
206  {
207  double timeInSeconds = time::seconds(time::now() - timeStart);
208  std::string timeStamp = std::to_string(timeInSeconds);
209  std::map<std::string, std::string> data;
210  data["time REAL"] = timeStamp;
211  for (const auto &property : properties)
212  {
213  data[property.first] = property.second();
214  }
215  runProgressData_.push_back(data);
216  }
217  }
218  }
219 
220  const Benchmark *benchmark_;
221  double timeUsed_;
222  machine::MemUsage_t memUsed_;
223  base::PlannerStatus status_;
224  bool useThreads_;
225  Benchmark::RunProgressData runProgressData_;
226 
227  // variables needed for progress property collection
228  bool solved_;
229  std::mutex solvedFlag_;
230  std::condition_variable solvedCondition_;
231  };
232  }
233 }
235 
236 bool ompl::tools::Benchmark::saveResultsToFile(const char *filename) const
237 {
238  bool result = false;
239 
240  std::ofstream fout(filename);
241  if (fout.good())
242  {
243  result = saveResultsToStream(fout);
244  OMPL_INFORM("Results saved to '%s'", filename);
245  }
246  else
247  {
248  // try to save to a different file, if we can
249  if (getResultsFilename(exp_) != std::string(filename))
250  result = saveResultsToFile();
251 
252  OMPL_ERROR("Unable to write results to '%s'", filename);
253  }
254  return result;
255 }
256 
258 {
259  std::string filename = getResultsFilename(exp_);
260  return saveResultsToFile(filename.c_str());
261 }
262 
263 bool ompl::tools::Benchmark::saveResultsToStream(std::ostream &out) const
264 {
265  if (exp_.planners.empty())
266  {
267  OMPL_WARN("There is no experimental data to save");
268  return false;
269  }
270 
271  if (!out.good())
272  {
273  OMPL_ERROR("Unable to write to stream");
274  return false;
275  }
276 
277  out << "OMPL version " << OMPL_VERSION << std::endl;
278  out << "Experiment " << (exp_.name.empty() ? "NO_NAME" : exp_.name) << std::endl;
279 
280  out << exp_.parameters.size() << " experiment properties" << std::endl;
281  for (const auto &parameter : exp_.parameters)
282  out << parameter.first << " = " << parameter.second << std::endl;
283 
284  out << "Running on " << (exp_.host.empty() ? "UNKNOWN" : exp_.host) << std::endl;
285  out << "Starting at " << time::as_string(exp_.startTime) << std::endl;
286  out << "<<<|" << std::endl << exp_.setupInfo << "|>>>" << std::endl;
287  out << "<<<|" << std::endl << exp_.cpuInfo << "|>>>" << std::endl;
288 
289  out << exp_.seed << " is the random seed" << std::endl;
290  out << exp_.maxTime << " seconds per run" << std::endl;
291  out << exp_.maxMem << " MB per run" << std::endl;
292  out << exp_.runCount << " runs per planner" << std::endl;
293  out << exp_.totalDuration << " seconds spent to collect the data" << std::endl;
294 
295  // change this if more enum types are added
296  out << "1 enum type" << std::endl;
297  out << "status";
298  for (unsigned int i = 0; i < base::PlannerStatus::TYPE_COUNT; ++i)
299  out << '|' << base::PlannerStatus(static_cast<base::PlannerStatus::StatusType>(i)).asString();
300  out << std::endl;
301 
302  out << exp_.planners.size() << " planners" << std::endl;
303 
304  for (const auto &planner : exp_.planners)
305  {
306  out << planner.name << std::endl;
307 
308  // get names of common properties
309  std::vector<std::string> properties;
310  for (auto &property : planner.common)
311  properties.push_back(property.first);
312  std::sort(properties.begin(), properties.end());
313 
314  // print names & values of common properties
315  out << properties.size() << " common properties" << std::endl;
316  for (auto &property : properties)
317  {
318  auto it = planner.common.find(property);
319  out << it->first << " = " << it->second << std::endl;
320  }
321 
322  // construct the list of all possible properties for all runs
323  std::map<std::string, bool> propSeen;
324  for (auto &run : planner.runs)
325  for (auto &property : run)
326  propSeen[property.first] = true;
327 
328  properties.clear();
329 
330  for (auto &it : propSeen)
331  properties.push_back(it.first);
332  std::sort(properties.begin(), properties.end());
333 
334  // print the property names
335  out << properties.size() << " properties for each run" << std::endl;
336  for (auto &property : properties)
337  out << property << std::endl;
338 
339  // print the data for each run
340  out << planner.runs.size() << " runs" << std::endl;
341  for (auto &run : planner.runs)
342  {
343  for (auto &property : properties)
344  {
345  auto it = run.find(property);
346  if (it != run.end())
347  out << it->second;
348  out << "; ";
349  }
350  out << std::endl;
351  }
352 
353  // print the run progress data if it was reported
354  if (planner.runsProgressData.size() > 0)
355  {
356  // Print number of progress properties
357  out << planner.progressPropertyNames.size() << " progress properties for each run" << std::endl;
358  // Print progress property names
359  for (const auto &progPropName : planner.progressPropertyNames)
360  {
361  out << progPropName << std::endl;
362  }
363  // Print progress properties for each run
364  out << planner.runsProgressData.size() << " runs" << std::endl;
365  for (const auto &r : planner.runsProgressData)
366  {
367  // For each time point
368  for (const auto &t : r)
369  {
370  // Print each of the properties at that time point
371  for (const auto &iter : t)
372  {
373  out << iter.second << ",";
374  }
375 
376  // Separate time points by semicolons
377  out << ";";
378  }
379 
380  // Separate runs by newlines
381  out << std::endl;
382  }
383  }
384 
385  out << '.' << std::endl;
386  }
387  return true;
388 }
389 
391 {
392  // sanity checks
393  if (gsetup_)
394  {
395  if (!gsetup_->getSpaceInformation()->isSetup())
396  gsetup_->getSpaceInformation()->setup();
397  }
398  else
399  {
400  if (!csetup_->getSpaceInformation()->isSetup())
401  csetup_->getSpaceInformation()->setup();
402  }
403 
404  if (!(gsetup_ ? gsetup_->getGoal() : csetup_->getGoal()))
405  {
406  OMPL_ERROR("No goal defined");
407  return;
408  }
409 
410  if (planners_.empty())
411  {
412  OMPL_ERROR("There are no planners to benchmark");
413  return;
414  }
415 
416  status_.running = true;
417  exp_.totalDuration = 0.0;
418  exp_.maxTime = req.maxTime;
419  exp_.maxMem = req.maxMem;
420  exp_.runCount = req.runCount;
421  exp_.host = machine::getHostname();
422  exp_.cpuInfo = machine::getCPUInfo();
423  exp_.seed = RNG::getSeed();
424 
425  exp_.startTime = time::now();
426 
427  OMPL_INFORM("Configuring planners ...");
428 
429  // clear previous experimental data
430  exp_.planners.clear();
431  exp_.planners.resize(planners_.size());
432 
433  const base::ProblemDefinitionPtr &pdef =
434  gsetup_ ? gsetup_->getProblemDefinition() : csetup_->getProblemDefinition();
435  // set up all the planners
436  for (unsigned int i = 0; i < planners_.size(); ++i)
437  {
438  // configure the planner
439  planners_[i]->setProblemDefinition(pdef);
440  if (!planners_[i]->isSetup())
441  planners_[i]->setup();
442  exp_.planners[i].name = (gsetup_ ? "geometric_" : "control_") + planners_[i]->getName();
443  OMPL_INFORM("Configured %s", exp_.planners[i].name.c_str());
444  }
445 
446  OMPL_INFORM("Done configuring planners.");
447  OMPL_INFORM("Saving planner setup information ...");
448 
449  std::stringstream setupInfo;
450  if (gsetup_)
451  gsetup_->print(setupInfo);
452  else
453  csetup_->print(setupInfo);
454  setupInfo << std::endl << "Properties of benchmarked planners:" << std::endl;
455  for (auto &planner : planners_)
456  planner->printProperties(setupInfo);
457 
458  exp_.setupInfo = setupInfo.str();
459 
460  OMPL_INFORM("Done saving information");
461 
462  OMPL_INFORM("Beginning benchmark");
464  boost::scoped_ptr<msg::OutputHandlerFile> ohf;
465  if (req.saveConsoleOutput)
466  {
467  ohf.reset(new msg::OutputHandlerFile(getConsoleFilename(exp_).c_str()));
468  msg::useOutputHandler(ohf.get());
469  }
470  else
472  OMPL_INFORM("Beginning benchmark");
473 
474  boost::scoped_ptr<boost::progress_display> progress;
475  if (req.displayProgress)
476  {
477  std::cout << "Running experiment " << exp_.name << "." << std::endl;
478  std::cout << "Each planner will be executed " << req.runCount << " times for at most " << req.maxTime
479  << " seconds. Memory is limited at " << req.maxMem << "MB." << std::endl;
480  progress.reset(new boost::progress_display(100, std::cout));
481  }
482 
484  auto maxMemBytes = (machine::MemUsage_t)(req.maxMem * 1024 * 1024);
485 
486  for (unsigned int i = 0; i < planners_.size(); ++i)
487  {
488  status_.activePlanner = exp_.planners[i].name;
489  // execute planner switch event, if set
490  try
491  {
492  if (plannerSwitch_)
493  {
494  OMPL_INFORM("Executing planner-switch event for planner %s ...", status_.activePlanner.c_str());
495  plannerSwitch_(planners_[i]);
496  OMPL_INFORM("Completed execution of planner-switch event");
497  }
498  }
499  catch (std::runtime_error &e)
500  {
501  std::stringstream es;
502  es << "There was an error executing the planner-switch event for planner " << status_.activePlanner
503  << std::endl;
504  es << "*** " << e.what() << std::endl;
505  std::cerr << es.str();
506  OMPL_ERROR(es.str().c_str());
507  }
508  if (gsetup_)
509  gsetup_->setup();
510  else
511  csetup_->setup();
512  planners_[i]->params().getParams(exp_.planners[i].common);
513  planners_[i]->getSpaceInformation()->params().getParams(exp_.planners[i].common);
514 
515  // Add planner progress property names to struct
516  exp_.planners[i].progressPropertyNames.emplace_back("time REAL");
517  base::Planner::PlannerProgressProperties::const_iterator iter;
518  for (iter = planners_[i]->getPlannerProgressProperties().begin();
519  iter != planners_[i]->getPlannerProgressProperties().end(); ++iter)
520  {
521  exp_.planners[i].progressPropertyNames.push_back(iter->first);
522  }
523  std::sort(exp_.planners[i].progressPropertyNames.begin(), exp_.planners[i].progressPropertyNames.end());
524 
525  // run the planner
526  for (unsigned int j = 0; j < req.runCount; ++j)
527  {
528  status_.activeRun = j;
529  status_.progressPercentage =
530  (double)(100 * (req.runCount * i + j)) / (double)(planners_.size() * req.runCount);
531 
532  if (req.displayProgress)
533  while (status_.progressPercentage > progress->count())
534  ++(*progress);
535 
536  OMPL_INFORM("Preparing for run %d of %s", status_.activeRun, status_.activePlanner.c_str());
537 
538  // make sure all planning data structures are cleared
539  try
540  {
541  planners_[i]->clear();
542  if (gsetup_)
543  {
544  gsetup_->getProblemDefinition()->clearSolutionPaths();
545  gsetup_->getSpaceInformation()->getMotionValidator()->resetMotionCounter();
546  }
547  else
548  {
549  csetup_->getProblemDefinition()->clearSolutionPaths();
550  csetup_->getSpaceInformation()->getMotionValidator()->resetMotionCounter();
551  }
552  }
553  catch (std::runtime_error &e)
554  {
555  std::stringstream es;
556  es << "There was an error while preparing for run " << status_.activeRun << " of planner "
557  << status_.activePlanner << std::endl;
558  es << "*** " << e.what() << std::endl;
559  std::cerr << es.str();
560  OMPL_ERROR(es.str().c_str());
561  }
562 
563  // execute pre-run event, if set
564  try
565  {
566  if (preRun_)
567  {
568  OMPL_INFORM("Executing pre-run event for run %d of planner %s ...", status_.activeRun,
569  status_.activePlanner.c_str());
570  preRun_(planners_[i]);
571  OMPL_INFORM("Completed execution of pre-run event");
572  }
573  }
574  catch (std::runtime_error &e)
575  {
576  std::stringstream es;
577  es << "There was an error executing the pre-run event for run " << status_.activeRun << " of planner "
578  << status_.activePlanner << std::endl;
579  es << "*** " << e.what() << std::endl;
580  std::cerr << es.str();
581  OMPL_ERROR(es.str().c_str());
582  }
583 
584  RunPlanner rp(this, req.useThreads);
585  rp.run(planners_[i], memStart, maxMemBytes, req.maxTime, req.timeBetweenUpdates);
586  bool solved = gsetup_ ? gsetup_->haveSolutionPath() : csetup_->haveSolutionPath();
587 
588  // store results
589  try
590  {
591  RunProperties run;
592 
593  run["time REAL"] = std::to_string(rp.getTimeUsed());
594  run["memory REAL"] = std::to_string((double)rp.getMemUsed() / (1024.0 * 1024.0));
595  run["status ENUM"] = std::to_string((int)static_cast<base::PlannerStatus::StatusType>(rp.getStatus()));
596  if (gsetup_)
597  {
598  run["solved BOOLEAN"] = std::to_string(gsetup_->haveExactSolutionPath());
599  run["valid segment fraction REAL"] =
600  std::to_string(gsetup_->getSpaceInformation()->getMotionValidator()->getValidMotionFraction());
601  }
602  else
603  {
604  run["solved BOOLEAN"] = std::to_string(csetup_->haveExactSolutionPath());
605  run["valid segment fraction REAL"] =
606  std::to_string(csetup_->getSpaceInformation()->getMotionValidator()->getValidMotionFraction());
607  }
608 
609  if (solved)
610  {
611  if (gsetup_)
612  {
613  run["approximate solution BOOLEAN"] =
614  std::to_string(gsetup_->getProblemDefinition()->hasApproximateSolution());
615  run["solution difference REAL"] =
616  std::to_string(gsetup_->getProblemDefinition()->getSolutionDifference());
617  run["solution length REAL"] = std::to_string(gsetup_->getSolutionPath().length());
618  run["solution smoothness REAL"] = std::to_string(gsetup_->getSolutionPath().smoothness());
619  run["solution clearance REAL"] = std::to_string(gsetup_->getSolutionPath().clearance());
620  run["solution segments INTEGER"] =
621  std::to_string(gsetup_->getSolutionPath().getStateCount() - 1);
622  run["correct solution BOOLEAN"] = std::to_string(gsetup_->getSolutionPath().check());
623 
624  unsigned int factor = gsetup_->getStateSpace()->getValidSegmentCountFactor();
625  gsetup_->getStateSpace()->setValidSegmentCountFactor(factor * 4);
626  run["correct solution strict BOOLEAN"] = std::to_string(gsetup_->getSolutionPath().check());
627  gsetup_->getStateSpace()->setValidSegmentCountFactor(factor);
628 
629  if (req.simplify)
630  {
631  // simplify solution
632  time::point timeStart = time::now();
633  gsetup_->simplifySolution();
634  double timeUsed = time::seconds(time::now() - timeStart);
635  run["simplification time REAL"] = std::to_string(timeUsed);
636  run["simplified solution length REAL"] =
637  std::to_string(gsetup_->getSolutionPath().length());
638  run["simplified solution smoothness REAL"] =
639  std::to_string(gsetup_->getSolutionPath().smoothness());
640  run["simplified solution clearance REAL"] =
641  std::to_string(gsetup_->getSolutionPath().clearance());
642  run["simplified solution segments INTEGER"] =
643  std::to_string(gsetup_->getSolutionPath().getStateCount() - 1);
644  run["simplified correct solution BOOLEAN"] =
645  std::to_string(gsetup_->getSolutionPath().check());
646  gsetup_->getStateSpace()->setValidSegmentCountFactor(factor * 4);
647  run["simplified correct solution strict BOOLEAN"] =
648  std::to_string(gsetup_->getSolutionPath().check());
649  gsetup_->getStateSpace()->setValidSegmentCountFactor(factor);
650  }
651  }
652  else
653  {
654  run["approximate solution BOOLEAN"] =
655  std::to_string(csetup_->getProblemDefinition()->hasApproximateSolution());
656  run["solution difference REAL"] =
657  std::to_string(csetup_->getProblemDefinition()->getSolutionDifference());
658  run["solution length REAL"] = std::to_string(csetup_->getSolutionPath().length());
659  run["solution clearance REAL"] =
660  std::to_string(csetup_->getSolutionPath().asGeometric().clearance());
661  run["solution segments INTEGER"] = std::to_string(csetup_->getSolutionPath().getControlCount());
662  run["correct solution BOOLEAN"] = std::to_string(csetup_->getSolutionPath().check());
663  }
664  }
665 
666  base::PlannerData pd(gsetup_ ? gsetup_->getSpaceInformation() : csetup_->getSpaceInformation());
667  planners_[i]->getPlannerData(pd);
668  run["graph states INTEGER"] = std::to_string(pd.numVertices());
669  run["graph motions INTEGER"] = std::to_string(pd.numEdges());
670 
671  for (const auto &prop : pd.properties)
672  run[prop.first] = prop.second;
673 
674  // execute post-run event, if set
675  try
676  {
677  if (postRun_)
678  {
679  OMPL_INFORM("Executing post-run event for run %d of planner %s ...", status_.activeRun,
680  status_.activePlanner.c_str());
681  postRun_(planners_[i], run);
682  OMPL_INFORM("Completed execution of post-run event");
683  }
684  }
685  catch (std::runtime_error &e)
686  {
687  std::stringstream es;
688  es << "There was an error in the execution of the post-run event for run " << status_.activeRun
689  << " of planner " << status_.activePlanner << std::endl;
690  es << "*** " << e.what() << std::endl;
691  std::cerr << es.str();
692  OMPL_ERROR(es.str().c_str());
693  }
694 
695  exp_.planners[i].runs.push_back(run);
696 
697  // Add planner progress data from the planner progress
698  // collector if there was anything to report
699  if (planners_[i]->getPlannerProgressProperties().size() > 0)
700  {
701  exp_.planners[i].runsProgressData.push_back(rp.getRunProgressData());
702  }
703  }
704  catch (std::runtime_error &e)
705  {
706  std::stringstream es;
707  es << "There was an error in the extraction of planner results: planner = " << status_.activePlanner
708  << ", run = " << status_.activePlanner << std::endl;
709  es << "*** " << e.what() << std::endl;
710  std::cerr << es.str();
711  OMPL_ERROR(es.str().c_str());
712  }
713  }
714  }
715 
716  status_.running = false;
717  status_.progressPercentage = 100.0;
718  if (req.displayProgress)
719  {
720  while (status_.progressPercentage > progress->count())
721  ++(*progress);
722  std::cout << std::endl;
723  }
724 
725  exp_.totalDuration = time::seconds(time::now() - exp_.startTime);
726 
727  OMPL_INFORM("Benchmark complete");
729  OMPL_INFORM("Benchmark complete");
730 }
Object containing planner generated vertex and edge data. It is assumed that all vertices are unique...
Definition: PlannerData.h:174
std::string getCPUInfo()
Get information about the CPU of the machine in use.
A shared pointer wrapper for ompl::base::ProblemDefinition.
virtual bool saveResultsToStream(std::ostream &out=std::cout) const
Save the results of the benchmark to a stream.
Definition: Benchmark.cpp:263
double maxMem
the maximum amount of memory a planner is allowed to use (MB); 4096.0 by default
Definition: Benchmark.h:177
double timeBetweenUpdates
When collecting time-varying data from a planner during its execution, the planner&#39;s progress will be...
Definition: Benchmark.h:184
std::map< std::string, std::string > RunProperties
The data collected from a run of a planner is stored as key-value pairs.
Definition: Benchmark.h:79
std::function< bool()> PlannerTerminationConditionFn
Signature for functions that decide whether termination conditions have been met for a planner...
void noOutputHandler()
This function instructs ompl that no messages should be outputted. Equivalent to useOutputHandler(nul...
Definition: Console.cpp:95
std::string as_string(const point &p)
Return string representation of point in time.
Definition: Time.h:90
bool displayProgress
flag indicating whether progress is to be displayed or not; true by default
Definition: Benchmark.h:187
unsigned int runCount
the number of times to run each planner; 100 by default
Definition: Benchmark.h:180
bool saveConsoleOutput
flag indicating whether console output is saved (in an automatically generated filename); true by def...
Definition: Benchmark.h:191
duration seconds(double sec)
Return the time duration representing a given number of seconds.
Definition: Time.h:76
bool useThreads
flag indicating whether planner runs should be run in a separate thread. It is advisable to set this ...
Definition: Benchmark.h:196
Main namespace. Contains everything in this library.
Definition: AppBase.h:21
The number of possible status values.
Definition: PlannerStatus.h:72
#define OMPL_ERROR(fmt,...)
Log a formatted error string.
Definition: Console.h:64
double maxTime
the maximum amount of time a planner is allowed to run (seconds); 5.0 by default
Definition: Benchmark.h:174
std::chrono::system_clock::duration duration
Representation of a time duration.
Definition: Time.h:67
A class to store the exit status of Planner::solve()
Definition: PlannerStatus.h:48
Generic class to handle output from a piece of code.
Definition: Console.h:102
static std::uint_fast32_t getSeed()
Get the seed used to generate the seeds of each RNG instance. Passing the returned value to setSeed()...
#define OMPL_WARN(fmt,...)
Log a formatted warning string.
Definition: Console.h:66
MemUsage_t getProcessMemoryUsage()
Get the amount of memory the current process is using. This should work on major platforms (Windows...
Representation of a benchmark request.
Definition: Benchmark.h:156
bool simplify
flag indicating whether simplification should be applied to path; true by default ...
Definition: Benchmark.h:199
point now()
Get the current time point.
Definition: Time.h:70
bool saveResultsToFile() const
Save the results of the benchmark to a file. The name of the file is the current date and time...
Definition: Benchmark.cpp:257
OutputHandler * getOutputHandler()
Get the instance of the OutputHandler currently used. This is nullptr in case there is no output hand...
Definition: Console.cpp:115
Implementation of OutputHandler that saves messages in a file.
Definition: Console.h:125
unsigned long long MemUsage_t
Amount of memory used, in bytes.
Definition: MachineSpecs.h:48
std::string getHostname()
Get the hostname of the machine in use.
std::chrono::system_clock::time_point point
Representation of a point in time.
Definition: Time.h:64
std::string asString() const
Return a string representation.
void useOutputHandler(OutputHandler *oh)
Specify the instance of the OutputHandler to use. By default, this is OutputHandlerSTD.
Definition: Console.cpp:108
std::map< std::string, PlannerProgressProperty > PlannerProgressProperties
A dictionary which maps the name of a progress property to the function to be used for querying that ...
Definition: Planner.h:349
CompleteExperiment exp_
The collected experimental data (for all planners)
Definition: Benchmark.h:343
virtual void benchmark(const Request &req)
Benchmark the added planners on the defined problem. Repeated calls clear previously gathered data...
Definition: Benchmark.cpp:390
#define OMPL_INFORM(fmt,...)
Log a formatted information string.
Definition: Console.h:68