libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
policy_improvement_loop.hpp
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
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 Willow Garage 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 
37 #ifndef POLICY_IMPROVEMENT_LOOP_H_
38 #define POLICY_IMPROVEMENT_LOOP_H_
39 
40 //#include <ros/ros.h>
41 //#include <rosbag/bag.h>
42 #include <boost/shared_ptr.hpp>
43 
44 #include "policy.hpp"
45 
46 #include "task.hpp"
47 #include "policy_improvement.hpp"
48 #include "API/ConfigSpace/configuration.hpp"
49 //#include <policy_improvement_loop/PolicyImprovementStatistics.h>
50 
51 namespace stomp_motion_planner
52 {
53 
55 {
56 public:
58  virtual ~PolicyImprovementLoop();
59 
60 // bool initializeAndRunTaskByName(/*ros::NodeHandle& node_handle,*/ std::string& task_name);
61 
62  bool initialize(boost::shared_ptr<Task> task, bool singleRollout);
63  bool runSingleIteration(int iteration_number);
64 
68  void testSampler();
69  bool generateSingleNoisyTrajectory();
70  void getRollouts(std::vector<std::vector<confPtr_t> >& traj);
71 
72  // Reset all extra rollouts
73  void resetReusedRollouts();
74 
75 private:
76 
77  bool initialized_;
78 // ros::NodeHandle node_handle_;
79 
80  int num_rollouts_;
81  int num_reused_rollouts_;
82  int num_time_steps_;
83  int num_dimensions_;
84 
85  bool write_to_file_;
86  bool use_cumulative_costs_;
87  bool set_parameters_in_policy_;
88 
89  bool use_annealing_;
90  int limits_violations_;
91  double K_;
92 
93  boost::shared_ptr<Task> task_;
94  boost::shared_ptr<Policy> policy_;
95 
96  PolicyImprovement policy_improvement_;
97 
98  std::vector<std::vector<Eigen::VectorXd> > rollouts_;
99  std::vector<std::vector<Eigen::VectorXd> > reused_rollouts_;
100 
101  std::vector<Eigen::MatrixXd> parameter_updates_;
102  std::vector<Eigen::VectorXd> parameters_;
103  Eigen::MatrixXd rollout_costs_;
104  std::vector<double> noise_stddev_;
105  std::vector<double> noise_decay_;
106  double control_cost_weight_;
107 
108  // temporary variables
109  Eigen::VectorXd tmp_rollout_cost_;
110 
111  bool readParameters();
112 
113  // added by jim
114  bool readParametersSingleRollout();
115  void resampleParameters();
116 
117  int policy_iteration_counter_;
118  bool readPolicy(const int iteration_number);
119  bool writePolicy(const int iteration_number, bool is_rollout = false, int rollout_id = 0);
120  //bool writePolicyImprovementStatistics(const policy_improvement_loop::PolicyImprovementStatistics& stats_msg);
121 
122  void addStraightLineRollout(std::vector<std::vector<Eigen::VectorXd> >& extra_rollout,
123  std::vector<Eigen::VectorXd>& extra_rollout_cost);
124  void parametersToVector(std::vector<Eigen::VectorXd>& rollout);
125  void getSingleRollout(const std::vector<Eigen::VectorXd>& rollout, std::vector<confPtr_t>& traj);
126  void addSingleRolloutsToDraw(const std::vector<Eigen::VectorXd>& rollout, int color);
127  void addRolloutsToDraw(bool add_reused);
128 
129 };
130 
131 }
132 
133 #endif /* POLICY_IMPROVEMENT_LOOP_H_ */
void testSampler()
Functions added by jim.
Definition: policy_improvement_loop.cpp:520
Definition: policy_improvement_loop.hpp:54
Definition: policy_improvement.hpp:79