+++ /dev/null
-/*
-This file is part of I am car.
-
-I am car is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-I am car is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with I am car. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include <omp.h>
-#include <vector>
-#include "nn.h"
-#include "rrtbase.h"
-
-RRTNode *nn1(
- std::vector<RRTNode *> &nodes,
- RRTNode *node,
- float (*cost)(RRTNode *, RRTNode *))
-{
- RRTNode *root = nodes[0];
- std::vector<RRTNode *> s; // DFS stack
- std::vector<RRTNode *> r; // reset visited_
- RRTNode *tmp;
- RRTNode *nn = root;
- float mcost = (*cost)(root, node);
-
- s.push_back(root);
- while (s.size() > 0) {
- tmp = s.back();
- s.pop_back();
- if (!tmp->visit()) {
- r.push_back(tmp);
- if ((*cost)(tmp, node) < mcost) {
- nn = tmp;
- mcost = (*cost)(tmp, node);
- }
- for (auto ch: tmp->children()) {
- s.push_back(ch);
- }
- }
- }
- for (auto n: r) {
- n->visit(false);
- }
- return nn;
-}
-
-RRTNode *nn2(
- std::vector<RRTNode *> &nodes,
- RRTNode *node,
- float (*cost)(RRTNode *, RRTNode *))
-{
- RRTNode *nn = nodes[0];
- float mcost = (*cost)(nn, node);
- unsigned int i;
- // TODO fix see, user-defined reductions
- #pragma omp parallel for
- for (i = 0; i < nodes.size(); i++) {
- if ((*cost)(nodes[i], node) < mcost) {
- nn = nodes[i];
- mcost = (*cost)(nodes[i], node);
- }
- }
- return nn;
-}
-
-RRTNode *nn3(
- std::vector<RRTNode *> (&nodes)[IYSIZE],
- RRTNode *node,
- float (*cost)(RRTNode *, RRTNode *))
-{
- int iy = IYI(node->y());
- struct mcnn nn;
- nn.nn = nullptr;
- nn.mc = 9999;
- unsigned int i = 0; // vector step
- unsigned int j = 0; // array step
- int iyj = 0;
- while (nn.mc > j * IYSTEP) {
- iyj = (int) (iy + j);
- if (iyj >= IYSIZE)
- iyj = IYSIZE - 1;
- #pragma omp parallel for reduction(minn: nn)
- for (i = 0; i < nodes[iyj].size(); i++) {
- if ((*cost)(nodes[iyj][i], node) < nn.mc) {
- nn.mc = (*cost)(nodes[iyj][i], node);
- nn.nn = nodes[iyj][i];
- }
- }
- if (j > 0) {
- iyj = (int) (iy - j);
- if (iyj < 0)
- iyj = 0;
- #pragma omp parallel for reduction(minn: nn)
- for (i = 0; i < nodes[iyj].size(); i++) {
- if ((*cost)(nodes[iyj][i], node) < nn.mc) {
- nn.mc = (*cost)(nodes[iyj][i], node);
- nn.nn = nodes[iyj][i];
- }
- }
- }
- j++;
- }
- return nn.nn;
-}
-
-RRTNode *nn4(
- std::vector<RRTNode *> (&nodes)[IYSIZE],
- RRTNode *node,
- float (*cost)(RRTNode *, RRTNode *))
-{
- int iy = IYI(node->y());
- struct mcnn nn;
- nn.nn = nullptr;
- nn.mc = 9999;
- unsigned int i = 0; // vector step
- unsigned int j = 0; // array step
- int iyj = 0;
- while (nn.mc > j * IYSTEP) {
- iyj = (int) (iy + j);
- if (iyj >= IYSIZE)
- iyj = IYSIZE - 1;
- #pragma omp parallel for reduction(minn: nn)
- for (i = 0; i < nodes[iyj].size(); i++) {
- if (EDIST(nodes[iyj][i], node) < nn.mc) {
- nn.mc = EDIST(nodes[iyj][i], node);
- nn.nn = nodes[iyj][i];
- }
- }
- if (j > 0) {
- iyj = (int) (iy - j);
- if (iyj < 0)
- iyj = 0;
- #pragma omp parallel for reduction(minn: nn)
- for (i = 0; i < nodes[iyj].size(); i++) {
- if (EDIST(nodes[iyj][i], node) < nn.mc) {
- nn.mc = EDIST(nodes[iyj][i], node);
- nn.nn = nodes[iyj][i];
- }
- }
- }
- j++;
- }
- return nn.nn;
-}
-
-RRTNode *nn5(
- std::vector<RRTNode *> (&nodes)[IYSIZE],
- RRTNode *node,
- float (*cost)(RRTNode *, RRTNode *),
- char tree)
-{
- int iy = IYI(node->y());
- struct mcnn nn;
- nn.nn = nullptr;
- nn.mc = 9999;
- unsigned int i = 0; // vector step
- unsigned int j = 0; // array step
- int iyj = 0;
- while (nn.mc > j * IYSTEP) {
- iyj = (int) (iy + j);
- if (iyj >= IYSIZE)
- iyj = IYSIZE - 1;
- #pragma omp parallel for reduction(minn: nn)
- for (i = 0; i < nodes[iyj].size(); i++) {
- if (EDIST(nodes[iyj][i], node) < nn.mc &&
- tree != '0' &&
- nodes[iyj][i]->tree() == tree) {
- nn.mc = EDIST(nodes[iyj][i], node);
- nn.nn = nodes[iyj][i];
- }
- }
- if (j > 0) {
- iyj = (int) (iy - j);
- if (iyj < 0)
- iyj = 0;
- #pragma omp parallel for reduction(minn: nn)
- for (i = 0; i < nodes[iyj].size(); i++) {
- if (EDIST(nodes[iyj][i], node) < nn.mc &&
- tree != '0' &&
- nodes[iyj][i]->tree() == tree) {
- nn.mc = EDIST(nodes[iyj][i], node);
- nn.nn = nodes[iyj][i];
- }
- }
- }
- j++;
- }
- return nn.nn;
-}