6 RRTExt13::DijkstraNode::DijkstraNode(RRTNode* n) : node(n)
11 RRTExt13::DijkstraNode::vi()
21 RRTExt13::DijkstraNodeComparator::operator() (DijkstraNode const& n1,
22 DijkstraNode const& n2)
24 return n1.node->cc() > n2.node->cc();
28 RRTExt13::pick_interesting()
31 this->dn_.reserve(this->path_.size());
32 #if 0 // all path poses are interesting
33 for (auto n: this->opath_) {
34 this->dn_.push_back(DijkstraNode(n));
35 this->dn_.back().i = this->dn_.size() - 1;
39 #if 1 // cusp and 1st non-drivable path poses are interesting
40 this->dn_.push_back(DijkstraNode(this->opath_.front()));
41 this->dn_.back().i = this->dn_.size() - 1;
42 for (unsigned int i = 0; i < this->opath_.size() - 1; i++) {
43 RRTNode& ni = *this->opath_[i];
44 this->bc_.set_pose(ni);
45 for (unsigned int j = i + 1; j < this->opath_.size(); j++) {
46 RRTNode& nj = *this->opath_[j];
47 RRTNode& njl = *this->opath_[j - 1];
48 if (!this->bc_.drivable(nj)) {
49 this->dn_.push_back(DijkstraNode(&njl));
50 this->dn_.back().i = this->dn_.size() - 1;
54 if (njl.sp() == 0.0 || sgn(njl.sp()) != sgn(nj.sp())) {
55 this->dn_.push_back(DijkstraNode(&njl));
56 this->dn_.back().i = this->dn_.size() - 1;
60 this->dn_.push_back(DijkstraNode(this->opath_.back()));
61 this->dn_.back().i = this->dn_.size() - 1;
66 RRTExt13::dijkstra_forward()
68 std::priority_queue<DijkstraNode, std::vector<DijkstraNode>,
69 DijkstraNodeComparator> pq;
70 this->dn_.front().vi();
71 pq.push(this->dn_.front());
73 DijkstraNode fd = pq.top();
74 RRTNode& f = *fd.node;
76 for (unsigned int i = fd.i + 1; i < this->dn_.size(); i++) {
77 RRTNode& t = *this->dn_[i].node;
78 double cost = f.cc() + this->cost_build(f, t);
80 if (this->steered_.size() == 0) {
83 if (this->collide_steered()) {
86 this->bc_.set_pose(this->steered_.back());
87 bool td = this->bc_.drivable(t);
88 bool tn = this->bc_.edist(t) < this->eta_;
89 if (cost < t.cc() && td && tn) {
90 this->join_steered(&f);
91 t.p(this->nodes_.back());
92 t.c(this->cost_build(this->nodes_.back(), t));
93 if (!this->dn_[i].vi()) {
94 pq.push(this->dn_[i]);
102 RRTExt13::dijkstra_backward()
104 std::priority_queue<DijkstraNode, std::vector<DijkstraNode>,
105 DijkstraNodeComparator> pq;
106 this->dn_.back().vi();
107 pq.push(this->dn_.back());
108 while (!pq.empty()) {
109 DijkstraNode td = pq.top();
110 RRTNode& t = *td.node;
112 for (unsigned int i = td.i - 1; i > 0; i--) {
113 RRTNode& f = *this->dn_[i].node;
114 double cost = f.cc() + this->cost_build(f, t);
116 if (this->steered_.size() == 0) {
119 if (this->collide_steered()) {
122 this->bc_.set_pose(this->steered_.back());
123 bool td = this->bc_.drivable(t);
124 bool tn = this->bc_.edist(t) < this->eta_;
125 if (cost < t.cc() && td && tn) {
126 this->join_steered(&f);
127 t.p(this->nodes_.back());
128 t.c(this->cost_build(this->nodes_.back(), t));
129 if (!this->dn_[i].vi()) {
130 pq.push(this->dn_[i]);
138 RRTExt13::compute_path()
140 RRTS::compute_path();
141 if (this->goal_.cc() == 0.0 || this->path_.size() == 0) {
144 #if 0 // TODO 0.59 should work for sc4-1-0 only.
145 if (this->goal_.cc() * 0.59 > this->last_goal_cc_
146 && this->last_goal_cc_ != 0.0) {
150 bool measure_time = false;
151 if (this->opath_.size() == 0) {
152 this->opath_ = this->path_;
153 this->ogoal_cc_ = this->goal_.cc();
157 this->otime_ = -this->ter_.scnt();
159 this->pick_interesting();
160 this->dijkstra_forward();
161 #if 0 // TODO Fix as the code does not always finish.
162 RRTS::compute_path();
163 this->pick_interesting();
164 this->dijkstra_backward();
166 RRTS::compute_path();
168 this->otime_ += this->ter_.scnt();
174 this->opath_.reserve(10000);
175 this->dn_.reserve(10000);
179 RRTExt13::json() const
181 auto jvo = RRTS::json();
183 for (auto n: this->opath_) {
184 jvo["opath"][i][0] = n->x();
185 jvo["opath"][i][1] = n->y();
186 jvo["opath"][i][2] = n->h();
189 jvo["ogoal_cc"] = this->ogoal_cc_;
190 jvo["otime"] = this->otime_;
195 RRTExt13::json(Json::Value jvi)
204 this->opath_.clear();