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),
93 number_of_collisions_(0) {}
95 Parameters(
unsigned int number_of_iterations,
96 unsigned int actual_tree_size = 100,
97 unsigned int tree_size = 100,
98 unsigned int number_of_collisions = 10000)
99 : number_of_iterations_(number_of_iterations),
100 actual_tree_size_(actual_tree_size),
101 tree_size_(tree_size),
102 number_of_collisions_(number_of_collisions) {}
104 unsigned int number_of_iterations_;
105 unsigned int actual_tree_size_;
106 unsigned int tree_size_;
107 unsigned int number_of_collisions_;
110 friend std::ostream& operator<<(std::ostream& s,
const Parameters& p);
114 RRT(
kernel::Model* m, DOFsSampler* sampler, LocalPlanner* planner,
115 const DOFs& cspace_dofs,
unsigned int iteration_number = 1000,
116 unsigned int tree_size = 100,
117 unsigned int number_of_sampled_dofs = 0);
123 const_cast<RRT*
>(
this)->run();
129 std::vector<DOFValues> get_DOFValues();
134 void set_number_of_iterations(
unsigned int num) {
135 default_parameters_.number_of_iterations_ = num;
139 void set_tree_size(
unsigned int num) { default_parameters_.tree_size_ = num; }
142 void set_actual_tree_size(
unsigned int num) {
143 default_parameters_.actual_tree_size_ = num;
147 void set_number_of_collisions(
unsigned int num) {
148 default_parameters_.number_of_collisions_ = num;
152 RRTNode* get_q_near(
const DOFValues& q_rand)
const;
154 void add_nodes(RRTNode* q_near,
const std::vector<DOFValues>& new_nodes);
157 bool is_stop_condition(
const Parameters& parameters,
158 const Parameters& counters) {
159 return (counters.number_of_iterations_ > parameters.number_of_iterations_ ||
160 counters.actual_tree_size_ > parameters.actual_tree_size_ ||
161 counters.tree_size_ > parameters.tree_size_ ||
162 counters.number_of_collisions_ > parameters.number_of_collisions_);
166 DOFsSampler* dofs_sampler_;
167 LocalPlanner* local_planner_;
168 typedef std::vector<RRTNode*> RRTTree;
171 Parameters default_parameters_;
174 unsigned int number_of_sampled_dofs_;
175 std::vector<bool> active_dofs_;
178 IMPKINEMATICS_END_NAMESPACE
A class to store a set of configurations of a model.
a simple class for storage of DOF values.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
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.
Base class for all samplers.
Import IMP/kernel/ConfigurationSet.h in the namespace.
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs