Initial Import.

This commit is contained in:
Dennis Luxen
2010-07-09 09:05:40 +00:00
parent a44a309de5
commit d4a64d2168
28 changed files with 5010 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef EDGE_H
#define EDGE_H
#include <cassert>
class Edge
{
public:
bool operator< (const Edge& e) const {
if (source() == e.source()) {
if (target() == e.target()) {
if (weight() == e.weight()) {
return (isForward() && isBackward() &&
((! e.isForward()) || (! e.isBackward())));
}
return (weight() < e.weight());
}
return (target() < e.target());
}
return (source() < e.source());
}
/** Default constructor. target and weight are set to 0.*/
Edge() { assert(false); } //shall not be used.
explicit Edge(NodeID s, NodeID t, EdgeWeight w, bool f, bool b) : _source(s), _target(t), _weight(w), forward(f), backward(b) { }
NodeID target() const {return _target; }
NodeID source() const {return _source;}
EdgeWeight weight() const {return _weight; }
bool isBackward() const { return backward; }
bool isForward() const { return forward; }
private:
NodeID _source;
NodeID _target;
EdgeWeight _weight:30;
bool forward:1;
bool backward:1;
};
typedef Edge ImportEdge;
#endif // EDGE_H
+66
View File
@@ -0,0 +1,66 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef _NODE_COORDS_H
#define _NODE_COORDS_H
template<typename NodeT>
struct NodeCoords {
NodeCoords(int _lat, int _lon, NodeT _id) : lat(_lat), lon(_lon), id(_id) {}
NodeCoords() : lat(UINT_MAX), lon(UINT_MAX), id(UINT_MAX) {}
int lat;
int lon;
unsigned int id;
};
struct duplet
{
typedef int value_type;
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] << ")";
}
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
+141
View File
@@ -0,0 +1,141 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef KDTREE_H_
#define NODEINFORMATIONHELPDESK_H_
#include <omp.h>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <deque>
#include <fstream>
#include <iostream>
#include <limits>
#include <list>
#include <stack>
#include <string>
#include <vector>
#include "../typedefs.h"
#include <kdtree++/kdtree.hpp>
typedef KDTree::KDTree<2, duplet, std::pointer_to_binary_function<duplet,int,double> > duplet_tree_type;
class NodeInformationHelpDesk{
public:
~NodeInformationHelpDesk();
NodeInformationHelpDesk() { int2ExtNodeMap = new vector<NodeInfo>();}
duplet_tree_type * initKDTree(ifstream& input);
NodeID getExternalNodeID(const NodeID node);
NodeInfo& getExternalNodeInfo(const NodeID node);
int getLatitudeOfNode(const NodeID node);
int getLongitudeOfNode(const NodeID node);
NodeID getNumberOfNodes() const { return int2ExtNodeMap->size(); }
inline NodeID findNearestNodeIDForLatLon(const int lat, const int lon, NodeCoords<NodeID> * data) const
{
duplet dup = *(kdtree->find_nearest(duplet(0, lat, lon)).first);
data->id = dup.id;
data->lat = dup.d[1];
data->lon = dup.d[0];
return data->id;
}
private:
vector<NodeInfo> * int2ExtNodeMap;
duplet_tree_type * kdtree;
};
//////////////////
//implementation//
//////////////////
NodeInformationHelpDesk::~NodeInformationHelpDesk(){
// delete graph;
// delete calc;
// delete c;
}
/* @brief: initialize kd-tree and internal->external node id map
*
*/
duplet_tree_type * NodeInformationHelpDesk::initKDTree(ifstream& in)
{
// NodeID i = 0;
while(!in.eof())
{
NodeInfo b;
in.read((char *)&b, sizeof(b));
int2ExtNodeMap->push_back(b);
// i++;
}
in.close();
duplet_tree_type * tree = new duplet_tree_type(std::ptr_fun(return_dup));
NodeID id = 0;
for(vector<NodeInfo>::iterator it = int2ExtNodeMap->begin(); it != int2ExtNodeMap->end(); it++)
{
duplet super_dupre(id, it->lat, it->lon);
tree->insert(super_dupre);
id++;
}
kdtree = tree;
return tree;
}
NodeID NodeInformationHelpDesk::getExternalNodeID(const NodeID node)
{
// google::dense_hash_map<NodeID, NodeInfo>::iterator temp = int2ExtNodeMap->find(node);
// if(temp == int2ExtNodeMap->end())
// return UINT_MAX;
// return temp->second.id;
return int2ExtNodeMap->at(node).id;
}
NodeInfo& NodeInformationHelpDesk::getExternalNodeInfo(const NodeID node)
{
return int2ExtNodeMap->at(node);
}
int NodeInformationHelpDesk::getLatitudeOfNode(const NodeID node)
{
// google::dense_hash_map<NodeID, NodeInfo>::iterator temp = int2ExtNodeMap->find(node);
// if(temp == int2ExtNodeMap->end())
// return UINT_MAX;
// return temp->second.lat;
return int2ExtNodeMap->at(node).lat;
}
int NodeInformationHelpDesk::getLongitudeOfNode(const NodeID node)
{
// google::dense_hash_map<NodeID, NodeInfo>::iterator temp = int2ExtNodeMap->find(node);
// if(temp == int2ExtNodeMap->end())
// return UINT_MAX;
// return temp->second.lon;
return int2ExtNodeMap->at(node).lon;
}
#endif /*KDTREE_H_*/
+34
View File
@@ -0,0 +1,34 @@
/*
open source routing machine
Copyright (C) Dennis Luxen, others 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU AFFERO General Public License as published by
the Free Software Foundation; either version 3 of the License, or
any later version.
This program 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 Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
#ifndef TIMEUTIL_H_
#define TIMEUTIL_H_
#include <sys/time.h>
/** Returns a timestamp (now) in seconds (incl. a fractional part). */
inline double get_timestamp()
{
struct timeval tp;
gettimeofday(&tp, NULL);
return double(tp.tv_sec) + tp.tv_usec / 1000000.;
}
#endif /* TIMEUTIL_H_ */