8 RRTExt13::DijkstraNode::DijkstraNode(RRTNode* n) : node(n)
13 RRTExt13::DijkstraNode::vi()
23 RRTExt13::DijkstraNodeComparator::operator() (DijkstraNode const& n1,
24 DijkstraNode const& n2)
26 return n1.node->cc() > n2.node->cc();
30 RRTExt13::pick_interesting()
33 this->dn_.reserve(this->path_.size());
34 //for (auto n: this->opath_) {
35 // this->dn_.push_back(DijkstraNode(n));
36 // this->dn_.back().i = this->dn_.size() - 1;
39 for (unsigned int i = 0; i < this->opath_.size() - 1; i++) {
40 //unsigned int i = 0; {
41 RRTNode& ni = *this->opath_[i];
42 this->bc_.set_pose(ni);
43 for (unsigned int j = i + 1; j < this->opath_.size(); j++) {
44 RRTNode& nj = *this->opath_[j];
45 RRTNode& njl = *this->opath_[j - 1];
46 if (njl.sp() == 0.0 || sgn(njl.sp()) != sgn(nj.sp())
47 || njl.edist(nj) < this->eta_) {
48 this->dn_.push_back(DijkstraNode(&njl));
49 this->dn_.back().i = this->dn_.size() - 1;
51 if (!this->bc_.drivable(nj)) {
52 this->dn_.push_back(DijkstraNode(&njl));
53 this->dn_.back().i = this->dn_.size() - 1;
59 this->dn_.push_back(DijkstraNode(this->opath_.back()));
60 this->dn_.back().i = this->dn_.size() - 1;
64 RRTExt13::dijkstra_forward()
66 std::priority_queue<DijkstraNode, std::vector<DijkstraNode>,
67 DijkstraNodeComparator> pq;
68 this->dn_.front().vi();
69 pq.push(this->dn_.front());
71 DijkstraNode fd = pq.top();
72 RRTNode& f = *fd.node;
74 for (unsigned int i = fd.i + 1; i < this->dn_.size(); i++) {
75 RRTNode& t = *this->dn_[i].node;
76 double cost = f.cc() + this->cost_build(f, t);
78 if (this->steered_.size() == 0) {
81 if (this->collide_steered()) {
84 this->bc_.set_pose(this->steered_.back());
85 bool td = this->bc_.drivable(t);
86 bool tn = this->bc_.edist(t) < this->eta_;
87 if (cost < t.cc() && td && tn) {
88 this->join_steered(&f);
89 t.p(this->nodes_.back());
90 t.c(this->cost_build(this->nodes_.back(), t));
91 if (!this->dn_[i].vi()) {
92 pq.push(this->dn_[i]);
100 RRTExt13::dijkstra_backward()
102 std::priority_queue<DijkstraNode, std::vector<DijkstraNode>,
103 DijkstraNodeComparator> pq;
104 this->dn_.back().vi();
105 pq.push(this->dn_.back());
106 while (!pq.empty()) {
107 DijkstraNode td = pq.top();
108 RRTNode& t = *td.node;
110 for (unsigned int i = td.i - 1; i > 0; i--) {
111 RRTNode& f = *this->dn_[i].node;
112 double cost = f.cc() + this->cost_build(f, t);
114 if (this->steered_.size() == 0) {
117 if (this->collide_steered()) {
120 this->bc_.set_pose(this->steered_.back());
121 bool td = this->bc_.drivable(t);
122 bool tn = this->bc_.edist(t) < this->eta_;
123 if (cost < t.cc() && td && tn) {
124 this->join_steered(&f);
125 t.p(this->nodes_.back());
126 t.c(this->cost_build(this->nodes_.back(), t));
127 if (!this->dn_[i].vi()) {
128 pq.push(this->dn_[i]);
136 RRTExt13::compute_path()
138 RRTS::compute_path();
139 bool measure_time = false;
140 if (this->opath_.size() == 0) {
141 this->opath_ = this->path_;
142 this->ogoal_cc_ = this->goal_.cc();
146 this->otime_ = -this->ter_.scnt();
148 this->pick_interesting();
149 this->dijkstra_forward();
150 this->pick_interesting();
151 this->dijkstra_backward();
152 RRTS::compute_path();
154 this->otime_ += this->ter_.scnt();
160 this->opath_.reserve(10000);
161 this->dn_.reserve(10000);
165 RRTExt13::json() const
167 auto jvo = RRTS::json();
169 for (auto n: this->opath_) {
170 jvo["opath"][i][0] = n->x();
171 jvo["opath"][i][1] = n->y();
172 jvo["opath"][i][2] = n->h();
175 jvo["ogoal_cc"] = this->ogoal_cc_;
176 jvo["otime"] = this->otime_;
181 RRTExt13::json(Json::Value jvi)
190 this->opath_.clear();
191 this->ogoal_cc_ = 0.0;