Faster routed startup (roughly 20%)

This commit is contained in:
Dennis Luxen 2010-07-14 14:22:29 +00:00
parent 4351e8850a
commit 61c19405fd
3 changed files with 28 additions and 48 deletions

View File

@ -21,13 +21,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef _NODE_COORDS_H #ifndef _NODE_COORDS_H
#define _NODE_COORDS_H #define _NODE_COORDS_H
#include <cassert>
#include <limits> #include <limits>
#include "../typedefs.h"
template<typename NodeT> template<typename NodeT>
struct NodeCoords { struct NodeCoords {
typedef unsigned key_type; typedef unsigned key_type;
typedef int value_type;
NodeCoords(int _lat, int _lon, NodeT _id) : lat(_lat), lon(_lon), id(_id) {} NodeCoords(int _lat, int _lon, NodeT _id) : lat(_lat), lon(_lon), id(_id) {}
NodeCoords() : lat(UINT_MAX), lon(UINT_MAX), id(UINT_MAX) {} NodeCoords() : lat(UINT_MAX), lon(UINT_MAX), id(UINT_MAX) {}
int lat; int lat;
@ -51,36 +54,21 @@ bool operator < (const NodeCoords<NodeT> & a, const NodeCoords<NodeT> & b)
return a.id < b.id; return a.id < b.id;
} }
struct duplet inline int return_dup( NodeCoords<unsigned int> n, int k )
{ {
typedef int value_type; switch(k)
inline value_type operator[](int const N) const { return d[N]; }
inline bool operator==(duplet const& other) const
{
return this->d[0] == other.d[0] && this->d[1] == other.d[1];
}
inline bool operator!=(duplet const& other) const
{
return this->d[0] != other.d[0] || this->d[1] != other.d[1];
}
friend std::ostream & operator<<(std::ostream & o, duplet const& d)
{ {
return o << "(" << d[0] << "," << d[1] << ")"; case 0:
return n.lat;
break;
case 1:
return n.lon;
break;
default:
assert(false);
return UINT_MAX;
break;
} }
duplet(unsigned _id, int x, int y) }
{
id = _id;
d[0] = x;
d[1] = y;
}
unsigned int id;
value_type d[2];
};
inline double return_dup( duplet d, int k ) { return d[k]; }
#endif //_NODE_COORDS_H #endif //_NODE_COORDS_H

View File

@ -40,13 +40,13 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <kdtree++/kdtree.hpp> #include <kdtree++/kdtree.hpp>
typedef KDTree::KDTree<2, duplet, std::pointer_to_binary_function<duplet,int,double> > duplet_tree_type; typedef KDTree::KDTree<2, NodeInfo, std::pointer_to_binary_function<NodeInfo,int,int> > KDTreeType;
class NodeInformationHelpDesk{ class NodeInformationHelpDesk{
public: public:
~NodeInformationHelpDesk(); ~NodeInformationHelpDesk();
NodeInformationHelpDesk() { int2ExtNodeMap = new vector<NodeInfo>();} NodeInformationHelpDesk() { int2ExtNodeMap = new vector<NodeInfo>();}
duplet_tree_type * initKDTree(ifstream& input); KDTreeType * initKDTree(ifstream& input);
NodeID getExternalNodeID(const NodeID node); NodeID getExternalNodeID(const NodeID node);
NodeInfo& getExternalNodeInfo(const NodeID node); NodeInfo& getExternalNodeInfo(const NodeID node);
@ -58,15 +58,15 @@ public:
inline NodeID findNearestNodeIDForLatLon(const int lat, const int lon, NodeCoords<NodeID> * data) const inline NodeID findNearestNodeIDForLatLon(const int lat, const int lon, NodeCoords<NodeID> * data) const
{ {
duplet dup = *(kdtree->find_nearest(duplet(0, lat, lon)).first); NodeInfo nearestNeighbor = *(kdtree->find_nearest(NodeInfo(lat, lon, 0)).first);
data->id = dup.id; data->id = nearestNeighbor.id;
data->lat = dup.d[1]; data->lat = nearestNeighbor.lat;
data->lon = dup.d[0]; data->lon = nearestNeighbor.lon;
return data->id; return data->id;
} }
private: private:
vector<NodeInfo> * int2ExtNodeMap; vector<NodeInfo> * int2ExtNodeMap;
duplet_tree_type * kdtree; KDTreeType * kdtree;
}; };
////////////////// //////////////////
@ -82,24 +82,22 @@ NodeInformationHelpDesk::~NodeInformationHelpDesk(){
/* @brief: initialize kd-tree and internal->external node id map /* @brief: initialize kd-tree and internal->external node id map
* *
*/ */
duplet_tree_type * NodeInformationHelpDesk::initKDTree(ifstream& in) KDTreeType * NodeInformationHelpDesk::initKDTree(ifstream& in)
{ {
// NodeID i = 0;
while(!in.eof()) while(!in.eof())
{ {
NodeInfo b; NodeInfo b;
in.read((char *)&b, sizeof(b)); in.read((char *)&b, sizeof(b));
int2ExtNodeMap->push_back(b); int2ExtNodeMap->push_back(b);
// i++;
} }
in.close(); in.close();
duplet_tree_type * tree = new duplet_tree_type(std::ptr_fun(return_dup)); KDTreeType * tree = new KDTreeType(std::ptr_fun(return_dup));
NodeID id = 0; NodeID id = 0;
for(vector<NodeInfo>::iterator it = int2ExtNodeMap->begin(); it != int2ExtNodeMap->end(); it++) for(vector<NodeInfo>::iterator it = int2ExtNodeMap->begin(); it != int2ExtNodeMap->end(); it++)
{ {
duplet super_dupre(id, it->lat, it->lon); it->id = id;
tree->insert(super_dupre); tree->insert(*it);
id++; id++;
} }
kdtree = tree; kdtree = tree;

View File

@ -58,8 +58,6 @@ public:
++edge; ++edge;
} }
_nodes[node].firstEdge = position; //=edge _nodes[node].firstEdge = position; //=edge
// _nodes[node].edges = edge - lastEdge;
// _nodes[node].size = edge - lastEdge;
position += edge - lastEdge; //remove position += edge - lastEdge; //remove
} }
_edges.resize( position ); //(edge) _edges.resize( position ); //(edge)
@ -125,15 +123,11 @@ public:
return smallestEdge; return smallestEdge;
} }
private: private:
struct _StrNode { struct _StrNode {
//index of the first edge //index of the first edge
EdgeIterator firstEdge; EdgeIterator firstEdge;
//amount of edges
// unsigned edges;
// unsigned size;
}; };
struct _StrEdge { struct _StrEdge {