BenchmarkExecutor.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2015, 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: Ryan Luna */
36 
37 #ifndef MOVEIT_ROS_BENCHMARKS_BENCHMARK_EXECUTOR_
38 #define MOVEIT_ROS_BENCHMARKS_BENCHMARK_EXECUTOR_
39 
41 
43 
52 
53 #include <map>
54 #include <vector>
55 #include <string>
56 #include <boost/function.hpp>
57 #include <memory>
58 
60 {
64 {
65 public:
67  typedef std::map<std::string, std::string> PlannerRunData;
69  typedef std::vector<PlannerRunData> PlannerBenchmarkData;
70 
72  typedef boost::function<void(const moveit_msgs::MotionPlanRequest& request, planning_scene::PlanningScenePtr)>
74 
76  typedef boost::function<void(const moveit_msgs::MotionPlanRequest& request, planning_scene::PlanningScenePtr)>
78 
81  typedef boost::function<void(const moveit_msgs::MotionPlanRequest& request, PlannerBenchmarkData& benchmark_data)>
83 
86  typedef boost::function<void(const moveit_msgs::MotionPlanRequest& request, PlannerBenchmarkData& benchmark_data)>
88 
90  typedef boost::function<void(moveit_msgs::MotionPlanRequest& request)> PreRunEventFunction;
91 
93  typedef boost::function<void(const moveit_msgs::MotionPlanRequest& request,
95  PlannerRunData& run_data)>
97 
98  BenchmarkExecutor(const std::string& robot_description_param = "robot_description");
99  virtual ~BenchmarkExecutor();
100 
101  // Initialize the benchmark executor by loading planning pipelines from the
102  // given set of classes
103  void initialize(const std::vector<std::string>& plugin_classes);
104 
105  void addPreRunEvent(PreRunEventFunction func);
111 
112  virtual void clear();
113 
114  virtual bool runBenchmarks(const BenchmarkOptions& opts);
115 
116 protected:
118  {
119  std::string name;
120  moveit_msgs::MotionPlanRequest request;
121  };
122 
123  struct StartState
124  {
125  moveit_msgs::RobotState state;
126  std::string name;
127  };
128 
130  {
131  std::vector<moveit_msgs::Constraints> constraints;
132  std::string name;
133  };
134 
136  {
137  moveit_msgs::TrajectoryConstraints constraints;
138  std::string name;
139  };
140 
141  virtual bool initializeBenchmarks(const BenchmarkOptions& opts, moveit_msgs::PlanningScene& scene_msg,
142  std::vector<BenchmarkRequest>& queries);
143 
144  virtual void collectMetrics(PlannerRunData& metrics, const planning_interface::MotionPlanDetailedResponse& mp_res,
145  bool solved, double total_time);
146 
147  virtual void writeOutput(const BenchmarkRequest& brequest, const std::string& start_time, double benchmark_duration);
148 
149  void shiftConstraintsByOffset(moveit_msgs::Constraints& constraints, const std::vector<double> offset);
150 
152  bool plannerConfigurationsExist(const std::map<std::string, std::vector<std::string>>& planners,
153  const std::string& group_name);
154 
156  bool queriesAndPlannersCompatible(const std::vector<BenchmarkRequest>& requests,
157  const std::map<std::string, std::vector<std::string>>& planners);
158 
160  bool loadPlanningScene(const std::string& scene_name, moveit_msgs::PlanningScene& scene_msg);
161 
163  bool loadStates(const std::string& regex, std::vector<StartState>& start_states);
164 
166  bool loadPathConstraints(const std::string& regex, std::vector<PathConstraints>& constraints);
167 
169  bool loadTrajectoryConstraints(const std::string& regex, std::vector<TrajectoryConstraints>& constraints);
170 
172  bool loadQueries(const std::string& regex, const std::string& scene_name, std::vector<BenchmarkRequest>& queries);
173 
175  void createRequestCombinations(const BenchmarkRequest& brequest, const std::vector<StartState>& start_states,
176  const std::vector<PathConstraints>& path_constraints,
177  std::vector<BenchmarkRequest>& combos);
178 
180  void runBenchmark(moveit_msgs::MotionPlanRequest request,
181  const std::map<std::string, std::vector<std::string>>& planners, int runs);
182 
189 
191  planning_scene::PlanningScenePtr planning_scene_;
192 
194 
195  std::shared_ptr<pluginlib::ClassLoader<planning_interface::PlannerManager>> planner_plugin_loader_;
196  std::map<std::string, planning_interface::PlannerManagerPtr> planner_interfaces_;
197 
198  std::vector<PlannerBenchmarkData> benchmark_data_;
199 
200  std::vector<PreRunEventFunction> pre_event_fns_;
201  std::vector<PostRunEventFunction> post_event_fns_;
202  std::vector<PlannerStartEventFunction> planner_start_fns_;
203  std::vector<PlannerCompletionEventFunction> planner_completion_fns_;
204  std::vector<QueryStartEventFunction> query_start_fns_;
205  std::vector<QueryCompletionEventFunction> query_end_fns_;
206 };
207 }
208 
209 #endif
BenchmarkExecutor(const std::string &robot_description_param="robot_description")
void addPostRunEvent(PostRunEventFunction func)
void createRequestCombinations(const BenchmarkRequest &brequest, const std::vector< StartState > &start_states, const std::vector< PathConstraints > &path_constraints, std::vector< BenchmarkRequest > &combos)
Duplicate the given benchmark request for all combinations of start states and path constraints...
bool loadQueries(const std::string &regex, const std::string &scene_name, std::vector< BenchmarkRequest > &queries)
Load all motion plan requests matching the given regular expression from the warehouse.
moveit_warehouse::PlanningSceneStorage * pss_
bool loadStates(const std::string &regex, std::vector< StartState > &start_states)
Load all states matching the given regular expression from the warehouse.
planning_scene::PlanningScenePtr planning_scene_
warehouse_ros::DatabaseLoader dbloader
virtual void writeOutput(const BenchmarkRequest &brequest, const std::string &start_time, double benchmark_duration)
moveit_warehouse::TrajectoryConstraintsStorage * tcs_
void addPreRunEvent(PreRunEventFunction func)
std::vector< PreRunEventFunction > pre_event_fns_
virtual void collectMetrics(PlannerRunData &metrics, const planning_interface::MotionPlanDetailedResponse &mp_res, bool solved, double total_time)
boost::function< void(const moveit_msgs::MotionPlanRequest &request, PlannerBenchmarkData &benchmark_data)> PlannerCompletionEventFunction
std::vector< PlannerStartEventFunction > planner_start_fns_
void addQueryCompletionEvent(QueryCompletionEventFunction func)
virtual bool runBenchmarks(const BenchmarkOptions &opts)
std::shared_ptr< pluginlib::ClassLoader< planning_interface::PlannerManager > > planner_plugin_loader_
moveit_warehouse::ConstraintsStorage * cs_
void runBenchmark(moveit_msgs::MotionPlanRequest request, const std::map< std::string, std::vector< std::string >> &planners, int runs)
Execute the given motion plan request on the set of planners for the set number of runs...
boost::function< void(const moveit_msgs::MotionPlanRequest &request, planning_scene::PlanningScenePtr)> QueryCompletionEventFunction
Definition of a query-end benchmark event function. Invoked after a query has finished benchmarking...
std::vector< PlannerCompletionEventFunction > planner_completion_fns_
bool loadPathConstraints(const std::string &regex, std::vector< PathConstraints > &constraints)
Load all constraints matching the given regular expression from the warehouse.
std::map< std::string, std::string > PlannerRunData
Structure to hold information for a single run of a planner.
bool plannerConfigurationsExist(const std::map< std::string, std::vector< std::string >> &planners, const std::string &group_name)
Check that the desired planner plugins and algorithms exist for the given group.
planning_scene_monitor::PlanningSceneMonitor * psm_
std::vector< QueryCompletionEventFunction > query_end_fns_
void addPlannerCompletionEvent(PlannerCompletionEventFunction func)
bool loadTrajectoryConstraints(const std::string &regex, std::vector< TrajectoryConstraints > &constraints)
Load all trajectory constraints from the warehouse that match the given regular expression.
boost::function< void(moveit_msgs::MotionPlanRequest &request)> PreRunEventFunction
Definition of a pre-run benchmark event function. Invoked immediately before each planner calls solve...
bool loadPlanningScene(const std::string &scene_name, moveit_msgs::PlanningScene &scene_msg)
Load the planning scene with the given name from the warehouse.
std::vector< QueryStartEventFunction > query_start_fns_
std::vector< moveit_msgs::Constraints > constraints
std::map< std::string, planning_interface::PlannerManagerPtr > planner_interfaces_
moveit_warehouse::PlanningSceneWorldStorage * psws_
void initialize(const std::vector< std::string > &plugin_classes)
moveit_warehouse::RobotStateStorage * rs_
void addPlannerStartEvent(PlannerStartEventFunction func)
boost::function< void(const moveit_msgs::MotionPlanRequest &request, const planning_interface::MotionPlanDetailedResponse &response, PlannerRunData &run_data)> PostRunEventFunction
Definition of a post-run benchmark event function. Invoked immediately after each planner calls solve...
std::vector< PlannerRunData > PlannerBenchmarkData
Structure to hold information for a single planner&#39;s benchmark data.
std::vector< PlannerBenchmarkData > benchmark_data_
boost::function< void(const moveit_msgs::MotionPlanRequest &request, PlannerBenchmarkData &benchmark_data)> PlannerStartEventFunction
virtual bool initializeBenchmarks(const BenchmarkOptions &opts, moveit_msgs::PlanningScene &scene_msg, std::vector< BenchmarkRequest > &queries)
void addQueryStartEvent(QueryStartEventFunction func)
void shiftConstraintsByOffset(moveit_msgs::Constraints &constraints, const std::vector< double > offset)
boost::function< void(const moveit_msgs::MotionPlanRequest &request, planning_scene::PlanningScenePtr)> QueryStartEventFunction
Definition of a query-start benchmark event function. Invoked before a new query is benchmarked...
std::vector< PostRunEventFunction > post_event_fns_
bool queriesAndPlannersCompatible(const std::vector< BenchmarkRequest > &requests, const std::map< std::string, std::vector< std::string >> &planners)
Check that the given requests can be run on the set of planner plugins and algorithms.


benchmarks
Author(s): Ryan Luna
autogenerated on Wed Jul 10 2019 04:04:08