11 #ifndef IMPKINEMATICS_RR_T_H
12 #define IMPKINEMATICS_RR_T_H
14 #include <IMP/kinematics/kinematics_config.h>
22 IMPKINEMATICS_BEGIN_NAMESPACE
37 RRTNode(
const DOFValues& vec) : vec_(vec) {
44 const DOFValues& get_DOFValues()
const {
return vec_; }
46 const std::vector<std::pair<const RRTNode*, float> >&
get_edges()
const {
50 int get_id()
const {
return id_; }
52 float get_score()
const {
return score_; }
54 bool is_edge(
const RRTNode* node)
const {
55 for(
unsigned int i=0; i<edges_.size(); i++)
56 if(node == edges_[i].first)
return true;
61 void add_edge(
const RRTNode* node,
float distance) {
62 if(id_ > node->id_) std::cerr <<
"wrong direction edge" << std::endl;
63 edges_.push_back(std::make_pair(node, distance));
66 void set_score(
float score) { score_ = score; }
69 bool operator()(
const RRTNode* n1,
const RRTNode* n2) {
70 return n1->get_score() < n2->get_score();
74 friend std::ostream& operator<<(std::ostream& s,
const RRTNode& n);
79 std::vector<std::pair<const RRTNode*, float> > edges_;
82 static int node_counter_;
90 number_of_iterations_(0), actual_tree_size_(0),
91 tree_size_(0), number_of_collisions_(0) {}
93 Parameters(
unsigned int number_of_iterations,
94 unsigned int actual_tree_size = 100,
95 unsigned int tree_size = 100,
96 unsigned int number_of_collisions = 10000) :
97 number_of_iterations_(number_of_iterations),
98 actual_tree_size_(actual_tree_size),
99 tree_size_(tree_size), number_of_collisions_(number_of_collisions) {}
101 unsigned int number_of_iterations_;
102 unsigned int actual_tree_size_;
103 unsigned int tree_size_;
104 unsigned int number_of_collisions_;
107 friend std::ostream& operator<<(std::ostream& s,
const Parameters& p);
112 RRT(
kernel::Model *m, DOFsSampler* sampler, LocalPlanner* planner,
113 const DOFs& cspace_dofs,
unsigned int iteration_number = 1000,
114 unsigned int tree_size = 100);
120 const_cast<RRT*
>(
this)->run();
126 std::vector<DOFValues> get_DOFValues();
131 void set_number_of_iterations(
unsigned int num) {
132 default_parameters_.number_of_iterations_ = num;
136 void set_tree_size(
unsigned int num) {
137 default_parameters_.tree_size_ = num;
141 void set_actual_tree_size(
unsigned int num) {
142 default_parameters_.actual_tree_size_ = num;
146 void set_number_of_collisions(
unsigned int num) {
147 default_parameters_.number_of_collisions_ = num;
151 RRTNode* get_q_near(
const DOFValues& q_rand)
const;
153 void add_nodes(RRTNode* q_near,
const std::vector<DOFValues>& new_nodes);
156 bool is_stop_condition(
const Parameters& parameters,
157 const Parameters& counters) {
158 return (counters.number_of_iterations_ > parameters.number_of_iterations_ ||
159 counters.actual_tree_size_ > parameters.actual_tree_size_ ||
160 counters.tree_size_ > parameters.tree_size_ ||
161 counters.number_of_collisions_ > parameters.number_of_collisions_);
165 DOFsSampler* dofs_sampler_;
166 LocalPlanner* local_planner_;
167 typedef std::vector<RRTNode*> RRTTree;
170 Parameters default_parameters_;
173 IMPKINEMATICS_END_NAMESPACE
A class to store a set of configurations of a model.
a simple class for storage of DOF values.
IntPairs get_edges(const BoundingBoxD< 3 > &)
Return the edges of the box as indices into the vertices list.
Import IMP/kernel/Sampler.h in the namespace.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Base class for all samplers.
Import IMP/kernel/ConfigurationSet.h in the namespace.
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs