7 RRTExt13::DijkstraNode::DijkstraNode(RRTNode* n) : node(n)
12 RRTExt13::DijkstraNode::vi()
22 RRTExt13::DijkstraNodeComparator::operator() (DijkstraNode const& n1,
23 DijkstraNode const& n2)
25 return n1.node->cc() > n2.node->cc();
29 RRTExt13::DijkstraNodeBackwardComparator::operator() (DijkstraNode const& n1,
30 DijkstraNode const& n2)
36 RRTExt13::interesting_forward()
39 this->dn_.reserve(this->path_.size());
40 #if 0 // all path poses are interesting
41 for (auto n: this->opath_) {
42 this->dn_.push_back(DijkstraNode(n));
43 this->dn_.back().i = this->dn_.size() - 1;
47 #if 1 // cusp and 1st non-drivable path poses are interesting
48 this->dn_.push_back(DijkstraNode(this->opath_.front()));
49 this->dn_.back().i = this->dn_.size() - 1;
50 for (unsigned int i = 0; i < this->opath_.size() - 1; i++) {
51 RRTNode& ni = *this->opath_[i];
52 this->bc_.set_pose(ni);
53 for (unsigned int j = i + 1; j < this->opath_.size(); j++) {
54 RRTNode& nj = *this->opath_[j];
55 RRTNode& njl = *this->opath_[j - 1];
56 if (!this->bc_.drivable(nj)) {
57 this->dn_.push_back(DijkstraNode(&njl));
58 this->dn_.back().i = this->dn_.size() - 1;
62 if (njl.sp() == 0.0 || sgn(njl.sp()) != sgn(nj.sp())) {
63 this->dn_.push_back(DijkstraNode(&njl));
64 this->dn_.back().i = this->dn_.size() - 1;
68 this->dn_.push_back(DijkstraNode(this->opath_.back()));
69 this->dn_.back().i = this->dn_.size() - 1;
74 RRTExt13::interesting_backward()
77 this->dn_.reserve(this->path_.size());
78 #if 0 // all path poses are interesting
79 for (auto n: this->opath_) {
80 this->dn_.push_back(DijkstraNode(n));
81 this->dn_.back().i = this->dn_.size() - 1;
83 std::reverse(this->dn_.begin(), this->dn_.end());
86 #if 1 // cusp and 1st non-drivable path poses are interesting
87 double goal_cc = this->goal_.cc();
88 this->dn_.push_back(DijkstraNode(this->opath_.back()));
89 this->dn_.back().i = this->dn_.size() - 1;
90 this->dn_.back().d = goal_cc - this->opath_.back()->cc();
91 for (unsigned int i = this->opath_.size() - 1; i > 1; i--) {
92 RRTNode& ni = *this->opath_[i];
93 this->bc_.set_pose(ni);
94 for (unsigned int j = i - 1; j > 0; j--) {
95 RRTNode& nj = *this->opath_[j];
96 RRTNode& njl = *this->opath_[j + 1];
97 if (!this->bc_.drivable(nj)) {
98 this->dn_.push_back(DijkstraNode(&njl));
99 this->dn_.back().i = this->dn_.size() - 1;
100 this->dn_.back().d = goal_cc - njl.cc();
104 if (njl.sp() == 0.0 || sgn(njl.sp()) != sgn(nj.sp())) {
105 this->dn_.push_back(DijkstraNode(&njl));
106 this->dn_.back().i = this->dn_.size() - 1;
107 this->dn_.back().d = goal_cc - njl.cc();
111 this->dn_.push_back(DijkstraNode(this->opath_.front()));
112 this->dn_.back().i = this->dn_.size() - 1;
113 this->dn_.back().d = goal_cc - this->opath_.front()->cc();
118 RRTExt13::dijkstra_forward()
120 std::priority_queue<DijkstraNode, std::vector<DijkstraNode>,
121 DijkstraNodeComparator> pq;
122 this->dn_.front().vi();
123 pq.push(this->dn_.front());
124 while (!pq.empty()) {
125 DijkstraNode fd = pq.top();
126 RRTNode& f = *fd.node;
128 this->bc_.set_pose(f);
129 for (unsigned int i = fd.i + 1; i < this->dn_.size(); i++) {
130 RRTNode& t = *this->dn_[i].node;
131 if (!this->bc_.drivable(t)) {
134 double cost = f.cc() + this->cost_build(f, t);
136 if (this->steered_.size() == 0) {
139 unsigned int ss = this->steered_.size();
140 if (this->collide_steered()
141 || ss != this->steered_.size()) {
144 this->bc_.set_pose(this->steered_.back());
145 bool td = this->bc_.drivable(t);
146 bool tn = this->bc_.edist(t) < 2.0 * this->eta_;
147 if (cost < t.cc() && td && tn) {
148 this->join_steered(&f);
149 t.p(this->nodes_.back());
150 t.c(this->cost_build(this->nodes_.back(), t));
151 if (!this->dn_[i].vi()) {
152 pq.push(this->dn_[i]);
160 RRTExt13::dijkstra_backward()
162 std::priority_queue<DijkstraNode, std::vector<DijkstraNode>,
163 DijkstraNodeComparator> pq;
164 this->dn_.front().vi();
165 pq.push(this->dn_.front());
166 while (!pq.empty()) {
167 DijkstraNode td = pq.top();
168 RRTNode& t = *td.node;
170 this->bc_.set_pose(t);
171 for (unsigned int i = td.i; i > 0; i--) {
172 DijkstraNode& fd = this->dn_[i];
173 RRTNode& f = *this->dn_[i].node;
174 if (!this->bc_.drivable(f)) {
177 double cost = td.d + this->cost_build(f, t);
179 if (this->steered_.size() == 0) {
182 unsigned int ss = this->steered_.size();
183 if (this->collide_steered()
184 || ss != this->steered_.size()) {
187 this->bc_.set_pose(this->steered_.back());
188 bool td = this->bc_.drivable(t);
189 bool tn = this->bc_.edist(t) < 2.0 * this->eta_;
190 if (cost < fd.d && td && tn) {
192 this->join_steered(&f);
193 t.p(this->nodes_.back());
194 t.c(this->cost_build(this->nodes_.back(), t));
195 this->recompute_path_cc();
196 if (!this->dn_[i].vi()) {
197 pq.push(this->dn_[i]);
205 RRTExt13::compute_path()
207 RRTS::compute_path();
208 if (this->goal_.cc() == 0.0 || this->path_.size() == 0) {
211 #if 0 // TODO 0.59 should work for sc4-1-0 only.
212 if (this->goal_.cc() * 0.59 > this->last_goal_cc_
213 && this->last_goal_cc_ != 0.0) {
217 bool measure_time = false;
218 if (this->opath_.size() == 0) {
219 this->opath_ = this->path_;
220 this->ogoal_cc_ = this->goal_.cc();
224 this->otime_ = -this->ter_.scnt();
226 double curr_cc = this->goal_.cc();
227 double last_cc = curr_cc + 1.0;
228 while (curr_cc < last_cc) {
230 RRTS::compute_path();
231 this->interesting_forward();
232 this->dijkstra_forward();
233 RRTS::compute_path();
234 this->interesting_backward();
235 this->dijkstra_backward();
236 RRTS::compute_path();
237 curr_cc = this->goal_.cc();
240 this->otime_ += this->ter_.scnt();
246 this->opath_.reserve(10000);
247 this->dn_.reserve(10000);
251 RRTExt13::json() const
253 auto jvo = RRTS::json();
255 for (auto n: this->opath_) {
256 jvo["opath"][i][0] = n->x();
257 jvo["opath"][i][1] = n->y();
258 jvo["opath"][i][2] = n->h();
261 jvo["ogoal_cc"] = this->ogoal_cc_;
262 jvo["otime"] = this->otime_;
267 RRTExt13::json(Json::Value jvi)
276 this->opath_.clear();