kdtree usage simplified and dropped intermediate data structures

kdtree build-up twice at fast
int2ext node map holds iterators instead of object copies
some functions const'ed
buggy defines fixed
This commit is contained in:
Dennis Luxen 2010-07-14 16:29:18 +00:00
parent 61c19405fd
commit 72e314d1c0
4 changed files with 47 additions and 68 deletions

View File

@ -25,7 +25,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <deque> #include <deque>
#include "BinaryHeap.h" #include "BinaryHeap.h"
//#include "DynamicGraph.h"
#include "../typedefs.h" #include "../typedefs.h"
struct _HeapData { struct _HeapData {
@ -43,7 +42,7 @@ public:
SearchEngine(GraphT * g, KDTST * k) : _graph(g), kdtree(k) {} SearchEngine(GraphT * g, KDTST * k) : _graph(g), kdtree(k) {}
~SearchEngine() {} ~SearchEngine() {}
NodeInfo& getNodeInfo(NodeID id) const const NodeInfo& getNodeInfo(NodeID id) const
{ {
return kdtree->getExternalNodeInfo(id); return kdtree->getExternalNodeInfo(id);
} }

View File

@ -35,7 +35,7 @@ struct NodeCoords {
NodeCoords() : lat(UINT_MAX), lon(UINT_MAX), id(UINT_MAX) {} NodeCoords() : lat(UINT_MAX), lon(UINT_MAX), id(UINT_MAX) {}
int lat; int lat;
int lon; int lon;
unsigned int id; NodeT id;
static NodeCoords<NodeT> min_value() static NodeCoords<NodeT> min_value()
{ {
@ -46,6 +46,22 @@ struct NodeCoords {
return NodeCoords<NodeT>(numeric_limits<int>::max(), numeric_limits<int>::max(), numeric_limits<NodeT>::max()); return NodeCoords<NodeT>(numeric_limits<int>::max(), numeric_limits<int>::max(), numeric_limits<NodeT>::max());
} }
value_type operator[](size_t n) const
{
switch(n)
{
case 0:
return lat;
break;
case 1:
return lon;
break;
default:
assert(false);
return UINT_MAX;
break;
}
}
}; };
template<typename NodeT> template<typename NodeT>
@ -53,22 +69,4 @@ bool operator < (const NodeCoords<NodeT> & a, const NodeCoords<NodeT> & b)
{ {
return a.id < b.id; return a.id < b.id;
} }
inline int return_dup( NodeCoords<unsigned int> n, int k )
{
switch(k)
{
case 0:
return n.lat;
break;
case 1:
return n.lon;
break;
default:
assert(false);
return UINT_MAX;
break;
}
}
#endif //_NODE_COORDS_H #endif //_NODE_COORDS_H

View File

@ -18,7 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt. or see http://www.gnu.org/licenses/agpl.txt.
*/ */
#ifndef KDTREE_H_ #ifndef NODEINFORMATIONHELPDESK_H_
#define NODEINFORMATIONHELPDESK_H_ #define NODEINFORMATIONHELPDESK_H_
#include <omp.h> #include <omp.h>
@ -40,18 +40,18 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <kdtree++/kdtree.hpp> #include <kdtree++/kdtree.hpp>
typedef KDTree::KDTree<2, NodeInfo, std::pointer_to_binary_function<NodeInfo,int,int> > KDTreeType; typedef KDTree::KDTree<2, NodeInfo > KDTreeType;
class NodeInformationHelpDesk{ class NodeInformationHelpDesk{
public: public:
~NodeInformationHelpDesk(); ~NodeInformationHelpDesk();
NodeInformationHelpDesk() { int2ExtNodeMap = new vector<NodeInfo>();} NodeInformationHelpDesk() { int2ExtNodeMap = new vector<KDTreeType::iterator>();}
KDTreeType * initKDTree(ifstream& input); KDTreeType * initKDTree(ifstream& input);
NodeID getExternalNodeID(const NodeID node); NodeID getExternalNodeID(const NodeID node);
NodeInfo& getExternalNodeInfo(const NodeID node); const NodeInfo& getExternalNodeInfo(const NodeID node) const;
int getLatitudeOfNode(const NodeID node); int getLatitudeOfNode(const NodeID node) const;
int getLongitudeOfNode(const NodeID node); int getLongitudeOfNode(const NodeID node) const;
NodeID getNumberOfNodes() const { return int2ExtNodeMap->size(); } NodeID getNumberOfNodes() const { return int2ExtNodeMap->size(); }
@ -65,7 +65,7 @@ public:
return data->id; return data->id;
} }
private: private:
vector<NodeInfo> * int2ExtNodeMap; vector<KDTreeType::iterator> * int2ExtNodeMap;
KDTreeType * kdtree; KDTreeType * kdtree;
}; };
@ -84,56 +84,41 @@ NodeInformationHelpDesk::~NodeInformationHelpDesk(){
*/ */
KDTreeType * NodeInformationHelpDesk::initKDTree(ifstream& in) KDTreeType * NodeInformationHelpDesk::initKDTree(ifstream& in)
{ {
kdtree = new KDTreeType();
NodeID id = 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); b.id = id;
} KDTreeType::iterator kdit = kdtree->insert(b);
in.close(); int2ExtNodeMap->push_back(kdit);
KDTreeType * tree = new KDTreeType(std::ptr_fun(return_dup));
NodeID id = 0;
for(vector<NodeInfo>::iterator it = int2ExtNodeMap->begin(); it != int2ExtNodeMap->end(); it++)
{
it->id = id;
tree->insert(*it);
id++; id++;
} }
kdtree = tree; in.close();
return tree; // kdtree->optimise();
return kdtree;
} }
NodeID NodeInformationHelpDesk::getExternalNodeID(const NodeID node) NodeID NodeInformationHelpDesk::getExternalNodeID(const NodeID node)
{ {
// google::dense_hash_map<NodeID, NodeInfo>::iterator temp = int2ExtNodeMap->find(node);
// if(temp == int2ExtNodeMap->end()) return int2ExtNodeMap->at(node)->id;
// return UINT_MAX;
// return temp->second.id;
return int2ExtNodeMap->at(node).id;
} }
NodeInfo& NodeInformationHelpDesk::getExternalNodeInfo(const NodeID node) const NodeInfo& NodeInformationHelpDesk::getExternalNodeInfo(const NodeID node) const
{ {
return int2ExtNodeMap->at(node); return *(int2ExtNodeMap->at(node) );
} }
int NodeInformationHelpDesk::getLatitudeOfNode(const NodeID node) int NodeInformationHelpDesk::getLatitudeOfNode(const NodeID node) const
{ {
// google::dense_hash_map<NodeID, NodeInfo>::iterator temp = int2ExtNodeMap->find(node); return int2ExtNodeMap->at(node)->lat;
// if(temp == int2ExtNodeMap->end())
// return UINT_MAX;
// return temp->second.lat;
return int2ExtNodeMap->at(node).lat;
} }
int NodeInformationHelpDesk::getLongitudeOfNode(const NodeID node) int NodeInformationHelpDesk::getLongitudeOfNode(const NodeID node) const
{ {
// google::dense_hash_map<NodeID, NodeInfo>::iterator temp = int2ExtNodeMap->find(node); return int2ExtNodeMap->at(node)->lon;
// if(temp == int2ExtNodeMap->end())
// return UINT_MAX;
// return temp->second.lon;
return int2ExtNodeMap->at(node).lon;
} }
#endif /*KDTREE_H_*/ #endif /*NODEINFORMATIONHELPDESK_H_*/

View File

@ -40,20 +40,17 @@ or see http://www.gnu.org/licenses/agpl.txt.
using namespace std; using namespace std;
//typedef google::dense_hash_map<NodeID, NodeInfo> NodeMap;
typedef ContractionCleanup::Edge::EdgeData EdgeData; typedef ContractionCleanup::Edge::EdgeData EdgeData;
typedef StaticGraph<EdgeData>::InputEdge GraphEdge; typedef StaticGraph<EdgeData>::InputEdge GraphEdge;
typedef http::server<StaticGraph<EdgeData> > server; typedef http::server<StaticGraph<EdgeData> > server;
//NodeMap * int2ExtNodeMap = new NodeMap();
/* /*
* TODO: Description of command line arguments * TODO: Description of command line arguments
*/ */
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
double time; // timemeasure double time;
if(argc < 2) if(argc < 2)
{ {