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_BENCHMARK_BENCHMARK_
00038 #define OMPL_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                 activePlanner = "";
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         struct PlannerExperiment
00084         {
00086             std::string                name;
00087 
00089             std::vector<RunProperties> runs;
00090 
00092             RunProperties              common;
00093         };
00094 
00096         struct CompleteExperiment
00097         {
00099             std::string                    name;
00100 
00102             std::vector<PlannerExperiment> planners;
00103 
00105             double                         maxTime;
00106 
00108             double                         maxMem;
00109 
00111             time::point                    startTime;
00112 
00114             double                         totalDuration;
00115 
00117             std::string                    setupInfo;
00118 
00120             boost::uint32_t                seed;
00121 
00123             std::string                    host;
00124         };
00125 
00127         Benchmark(geometric::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(&setup), csetup_(NULL), msg_("Benchmark")
00128         {
00129             exp_.name = name;
00130         }
00131 
00133         Benchmark(control::SimpleSetup &setup, const std::string &name = std::string()) : gsetup_(NULL), csetup_(&setup), msg_("Benchmark")
00134         {
00135             exp_.name = name;
00136         }
00137 
00138         virtual ~Benchmark(void)
00139         {
00140         }
00141 
00143         void setExperimentName(const std::string &name)
00144         {
00145             exp_.name = name;
00146         }
00147 
00149         const std::string& getExperimentName(void) const
00150         {
00151             return exp_.name;
00152         }
00153 
00158         void addPlanner(const base::PlannerPtr &planner)
00159         {
00160             if (planner && planner->getSpaceInformation().get() !=
00161                 (gsetup_ ? gsetup_->getSpaceInformation().get() : csetup_->getSpaceInformation().get()))
00162                 throw Exception("Planner instance does not match space information");
00163             planners_.push_back(planner);
00164         }
00165 
00169         void addPlannerAllocator(const base::PlannerAllocator &pa)
00170         {
00171             planners_.push_back(pa(gsetup_ ? gsetup_->getSpaceInformation() : csetup_->getSpaceInformation()));
00172         }
00173 
00175         void clearPlanners(void)
00176         {
00177             planners_.clear();
00178         }
00179 
00195         virtual void benchmark(double maxTime, double maxMem, unsigned int runCount, bool displayProgress = false);
00196 
00198         const Status& getStatus(void) const
00199         {
00200             return status_;
00201         }
00202 
00207         const CompleteExperiment& getRecordedExperimentData(void) const
00208         {
00209             return exp_;
00210         }
00211 
00213         virtual bool saveResultsToStream(std::ostream &out = std::cout) const;
00214 
00216         bool saveResultsToFile(const char *filename) const;
00217 
00219         bool saveResultsToFile(void) const;
00220 
00221     protected:
00222 
00224         std::string getResultsFilename(void) const;
00225 
00227         geometric::SimpleSetup       *gsetup_;
00228 
00230         control::SimpleSetup         *csetup_;
00231 
00233         std::vector<base::PlannerPtr> planners_;
00234 
00236         CompleteExperiment            exp_;
00237 
00239         Status                        status_;
00240 
00242         msg::Interface                msg_;
00243 
00244     };
00245 
00246 }
00247 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator