#include "rrtplanner.h"
#include "cost.h"
+#define KUWATA2008_CCOST co3
+#define KUWATA2008_DCOST co1
+
LaValle1998::LaValle1998(RRTNode *init, RRTNode *goal):
RRTBase(init, goal),
nn(nn1),
return this->goal_found();
}
+Kuwata2008::Kuwata2008(RRTNode *init, RRTNode *goal):
+ RRTBase(init, goal),
+ nn(nn1),
+ sample(sa1),
+ steer(st1),
+ cost(KUWATA2008_DCOST)
+{
+ srand(static_cast<unsigned>(time(0)));
+}
+
+bool Kuwata2008::next()
+{
+ RRTNode *rs;
+ if (this->samples().size() == 0) {
+ rs = this->goal();
+ } else {
+ rs = this->sample();
+ }
+ this->samples().push_back(rs);
+ float heur = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
+ if (this->goal_found()) {
+ if (heur < 0.7)
+ this->cost = &KUWATA2008_CCOST;
+ else
+ this->cost = &KUWATA2008_DCOST;
+ } else {
+ if (heur < 0.3)
+ this->cost = &KUWATA2008_CCOST;
+ else
+ this->cost = &KUWATA2008_DCOST;
+ }
+ RRTNode *nn = this->nn(this->root(), rs, this->cost);
+ RRTNode *pn = nn;
+ std::vector<RRTNode *> newly_added;
+ for (auto ns: this->steer(nn, rs)) {
+ this->nodes().push_back(ns);
+ pn->add_child(ns, KUWATA2008_DCOST(pn, ns));
+ if (this->collide(pn, ns)) {
+ pn->children().pop_back();
+ break;
+ }
+ pn = ns;
+ newly_added.push_back(pn);
+ if (this->goal_found(pn, &KUWATA2008_DCOST)) {
+ this->tlog(this->findt());
+ break;
+ }
+ }
+ if (this->samples().size() > 1) {
+ for (auto na: newly_added) {
+ pn = na;
+ for (auto ns: this->steer(na, this->goal())) {
+ this->nodes().push_back(ns);
+ pn->add_child(ns, KUWATA2008_DCOST(pn, ns));
+ if (this->collide(pn, ns)) {
+ pn->children().pop_back();
+ break;
+ }
+ pn = ns;
+ if (this->goal_found(pn, &KUWATA2008_DCOST)) {
+ this->tlog(this->findt());
+ break;
+ }
+ }
+ }
+ }
+ return this->goal_found();
+}
+
Karaman2011::Karaman2011(RRTNode *init, RRTNode *goal):
RRTBase(init, goal),
nn(nn1),
bool next();
};
+class Kuwata2008: public RRTBase {
+ public:
+ Kuwata2008(RRTNode *init, RRTNode *goal);
+
+ // RRT framework
+ RRTNode *(*nn)(
+ RRTNode *root,
+ RRTNode *node,
+ float (*cost)(RRTNode *, RRTNode *));
+ RRTNode *(*sample)();
+ std::vector<RRTNode *> (*steer)(
+ RRTNode *init,
+ RRTNode *goal);
+ float (*cost)(RRTNode *init, RRTNode *goal);
+ bool next();
+};
+
class Karaman2011: public RRTBase {
public:
Karaman2011(RRTNode *init, RRTNode *goal);