}
return this->goal_found();
}
+
+T1::T1(RRTNode *init, RRTNode *goal):
+ RRTBase(init, goal),
+ nn(nn1),
+ nv(nv1),
+ sample(sa1),
+ steer(st1),
+ cost(co1)
+{
+ srand(static_cast<unsigned>(time(0)));
+}
+
+bool T1::next()
+{
+ RRTNode *rs;
+ if (this->samples().size() == 0)
+ rs = this->goal();
+ else
+ rs = this->sample();
+ this->samples().push_back(rs);
+ RRTNode *nn = this->nn(this->root(), rs, this->cost);
+ RRTNode *pn = nn;
+ std::vector<RRTNode *> nvs;
+ bool connected;
+ RRTNode *op; // old parent
+ float od; // old direct cost
+ float oc; // old cumulative cost
+ std::vector<RRTNode *> steered = this->steer(nn, rs);
+ // RRT* for first node
+ RRTNode *ns = steered[0];
+ {
+ nvs = this->nv(this->root(), ns, this->cost, MIN(
+ GAMMA_RRTSTAR(this->nodes().size()),
+ 0.2)); // TODO const
+ this->nodes().push_back(ns);
+ connected = false;
+ pn->add_child(ns, this->cost(pn, ns));
+ if (this->collide(pn, ns)) {
+ pn->children().pop_back();
+ } else {
+ connected = true;
+ }
+ // connect
+ for (auto nv: nvs) {
+ if (!connected || (nv->ccost() + this->cost(nv, ns) <
+ ns->ccost())) {
+ op = ns->parent();
+ od = ns->dcost();
+ oc = ns->ccost();
+ nv->add_child(ns, this->cost(nv, ns));
+ if (this->collide(nv, ns)) {
+ nv->children().pop_back();
+ ns->parent(op);
+ ns->dcost(od);
+ ns->ccost(oc);
+ } else if (connected) {
+ op->children().pop_back();
+ } else {
+ connected = true;
+ }
+ }
+ }
+ if (!connected)
+ return false;
+ // rewire
+ for (auto nv: nvs) {
+ if (ns->ccost() + this->cost(ns, nv) < nv->ccost()) {
+ op = nv->parent();
+ od = nv->dcost();
+ oc = nv->ccost();
+ ns->add_child(nv, this->cost(ns, nv));
+ if (this->collide(ns, nv)) {
+ ns->children().pop_back();
+ nv->parent(op);
+ nv->dcost(od);
+ nv->ccost(oc);
+ } else {
+ op->rem_child(nv);
+ }
+ }
+ }
+ pn = ns;
+ if (this->goal_found(pn, this->cost)) {
+ this->tlog(this->findt());
+ }
+ }
+ unsigned int i = 0;
+ for (i = 1; i < steered.size(); i++) {
+ ns = steered[i];
+ this->nodes().push_back(ns);
+ pn->add_child(ns, this->cost(pn, ns));
+ if (this->collide(pn, ns)) {
+ pn->children().pop_back();
+ break;
+ }
+ pn = ns;
+ if (this->goal_found(pn, this->cost)) {
+ this->tlog(this->findt());
+ break;
+ }
+ }
+ return this->goal_found();
+}
bool next();
};
+class T1: public RRTBase {
+ public:
+ T1(RRTNode *init, RRTNode *goal);
+
+ // RRT framework
+ RRTNode *(*nn)(
+ RRTNode *root,
+ RRTNode *node,
+ float (*cost)(RRTNode *, RRTNode *));
+ std::vector<RRTNode *> (*nv)(
+ RRTNode *root,
+ RRTNode *node,
+ float (*cost)(RRTNode *, RRTNode *),
+ float dist);
+ RRTNode *(*sample)();
+ std::vector<RRTNode *> (*steer)(
+ RRTNode *init,
+ RRTNode *goal);
+ float (*cost)(RRTNode *init, RRTNode *goal);
+ bool next();
+};
+
#endif