All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Benchmark.h
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, Rice University
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Rice University nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* Author: Ioan Sucan */
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         geometric::SimpleSetup       *gsetup_;
00242 
00244         control::SimpleSetup         *csetup_;
00245 
00247         std::vector<base::PlannerPtr> planners_;
00248 
00250         CompleteExperiment            exp_;
00251 
00253         Status                        status_;
00254 
00256         PreSetupEvent                 preRun_;
00257 
00259         PostSetupEvent                postRun_;
00260 
00262         msg::Interface                msg_;
00263 
00264     };
00265 
00266 }
00267 #endif