Files
IPIN2016/code/DijkstraMapper.h
2016-04-14 13:03:16 +02:00

58 lines
1.6 KiB
C++

#ifndef DIJKSTRAMAPPER_H
#define DIJKSTRAMAPPER_H
#include "MyGridNode.h"
/**
* allows BETTER dijkstra calculation on top of our data-structure
*/
class DijkstraMapper {
Grid<MyGridNode>& grid;
public:
DijkstraMapper(Grid<MyGridNode>& grid) : grid(grid) {;}
int getNumNeighbors(const MyGridNode& node) const {return node.getNumNeighbors();}
const MyGridNode* getNeighbor(const MyGridNode& node, const int idx) const {return &grid.getNeighbor(node, idx);}
float getWeightBetween(const MyGridNode& n1, const MyGridNode& n2) const {
float d = ((Point3)n1 - (Point3)n2).length(2) ;
//if (d > 20) {d*= 1.30;}
//d /= std::pow(n2.imp, 3);
d /= n2.imp;
return d;
}
const std::vector<MyGridNode>& getAllNodes() const {return grid.getNodes();}
decltype(grid.neighbors(MyGridNode())) getNeighbors(const MyGridNode& node) const {return grid.neighbors(node);}
float getHeuristic(const MyGridNode& n1, const MyGridNode& n2) const {return ((Point3)n1 - (Point3)n2).length(2) ;}
//std::abs(n1.x_cm - n2.x_cm) + std::abs(n1.y_cm - n2.y_cm)
};
/**
* allows NORMAL dijkstra calculation on top of our data-structure
*/
class DijkstraMapperNormal {
Grid<MyGridNode>& grid;
public:
DijkstraMapperNormal(Grid<MyGridNode>& grid) : grid(grid) {;}
int getNumNeighbors(const MyGridNode& node) const {return node.getNumNeighbors();}
const MyGridNode* getNeighbor(const MyGridNode& node, const int idx) const {return &grid.getNeighbor(node, idx);}
float getWeightBetween(const MyGridNode& n1, const MyGridNode& n2) const {
return ((Point3)n1 - (Point3)n2).length();
}
};
#endif // DIJKSTRAMAPPER_H