#include <queue>
#include "rrtext.h"
-
+#include <iostream>
std::vector<RRTNode *> RRTExt13::first_path_optimization()
{
if (this->orig_path().size() == 0) {
}
};
std::vector<DijkstraNode> dn;
- dn.reserve(this->orig_path().size());
+ unsigned int ops = this->orig_path().size();
+ auto op = this->orig_path();
+ dn.reserve(ops);
unsigned int dncnt = 0;
- for (auto n: this->orig_path()) {
- if (
- n->t(RRTNodeType::cusp)
- || n->t(RRTNodeType::connected)
- ) {
- dn.push_back(DijkstraNode(*n));
- dn.back().cc = cc(*n);
- dn.back().s = &dn.back();
- dn.back().n = n;
- dn.back().i = dncnt++;
+ dn.push_back(DijkstraNode(*this->orig_path().front()));
+ dn.back().cc = cc(*this->orig_path().front());
+ dn.back().s = &dn.back();
+ dn.back().n = this->orig_path().front();
+ dn.back().i = dncnt++;
+ for (unsigned int i = 0; i < ops - 1; i++) {
+ auto ibc = BicycleCar();
+ ibc.x(op[i]->x());
+ ibc.y(op[i]->y());
+ ibc.h(op[i]->h());
+ for (unsigned int j = i + 1; j < ops; j++) {
+ auto jbc = BicycleCar();
+ jbc.x(op[j]->x());
+ jbc.y(op[j]->y());
+ jbc.h(op[j]->h());
+ if (!jbc.drivable(ibc)) {
+ //std::cerr<<*op[i];
+ //std::cerr<<" to ";
+ //std::cerr<<*op[j];
+ //std::cerr<<std::endl;
+ dn.push_back(DijkstraNode(*op[j-1]));
+ dn.back().cc = cc(*op[j-1]);
+ dn.back().s = &dn.back();
+ dn.back().n = op[j-1];
+ dn.back().i = dncnt++;
+ i = j;
+ break;
+ }
}
}
dn.push_back(DijkstraNode(*this->orig_path().back()));
}
};
std::vector<DijkstraNode> dn;
- dn.reserve(this->orig_path().size());
+ unsigned int ops = this->orig_path().size();
+ auto op = this->orig_path();
+ dn.reserve(ops);
unsigned int dncnt = 0;
- for (auto n: this->orig_path()) {
- if (
- n->t(RRTNodeType::cusp)
- || n->t(RRTNodeType::connected)
- ) {
- dn.push_back(DijkstraNode(*n));
- dn.back().cc = cc(*n);
- dn.back().s = &dn.back();
- dn.back().n = n;
- dn.back().i = dncnt++;
+ dn.push_back(DijkstraNode(*this->orig_path().front()));
+ dn.back().cc = cc(*this->orig_path().front());
+ dn.back().s = &dn.back();
+ dn.back().n = this->orig_path().front();
+ dn.back().i = dncnt++;
+ for (unsigned int i = ops - 1; i > 1; i--) {
+ auto ibc = BicycleCar();
+ ibc.x(op[i]->x());
+ ibc.y(op[i]->y());
+ ibc.h(op[i]->h());
+ for (unsigned int j = i - 1; j > 0; j--) {
+ auto jbc = BicycleCar();
+ jbc.x(op[j]->x());
+ jbc.y(op[j]->y());
+ jbc.h(op[j]->h());
+ if (!jbc.drivable(ibc)) {
+ //std::cerr<<*op[i];
+ //std::cerr<<" to ";
+ //std::cerr<<*op[j];
+ //std::cerr<<std::endl;
+ dn.push_back(DijkstraNode(*op[j-1]));
+ dn.back().cc = cc(*op[j-1]);
+ dn.back().s = &dn.back();
+ dn.back().n = op[j-1];
+ dn.back().i = dncnt++;
+ i = j;
+ break;
+ }
}
}
dn.push_back(DijkstraNode(*this->orig_path().back()));