Certain type of edges, i.e. ferries, are now properly ignored from

nearest neighbor lookup. Fixes ticket 59.
This commit is contained in:
DennisOSRM 2011-12-16 14:05:30 +01:00
parent ad77d6cfec
commit f5226b2228
10 changed files with 61 additions and 45 deletions

View File

@ -52,6 +52,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
assert( edge.data.distance > 0 );
edge.data.shortcut = false;
edge.data.roundabout = i->isRoundabout();
edge.data.ignoreInGrid = i->ignoreInGrid();
edge.data.nameID = i->name();
edge.data.type = i->type();
edge.data.forward = i->isForward();
@ -140,6 +141,7 @@ void EdgeBasedGraphFactory::Run() {
currentNode.lat2 = inputNodeInfoList[v].lat;
currentNode.lon2 = inputNodeInfoList[v].lon;
currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;
currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid;
// short startHeight = srtmLookup.height(currentNode.lon1/100000.,currentNode.lat1/100000. );
// short targetHeight = srtmLookup.height(currentNode.lon2/100000.,currentNode.lat2/100000. );
@ -205,7 +207,7 @@ void EdgeBasedGraphFactory::Run() {
EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction);
edgeBasedEdges.push_back(newEdge);
if(_nodeBasedGraph->GetEdgeData(e1).type != INT_MAX ) {
if(_nodeBasedGraph->GetEdgeData(e1).type != SHRT_MAX ) {
EdgeBasedNode currentNode;
currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID;
currentNode.lat1 = inputNodeInfoList[u].lat;
@ -213,6 +215,8 @@ void EdgeBasedGraphFactory::Run() {
currentNode.lat2 = inputNodeInfoList[v].lat;
currentNode.lon2 = inputNodeInfoList[v].lon;
currentNode.id = edgeBasedSource;
currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid;
// short startHeight = srtmLookup.height(currentNode.lon1/100000.,currentNode.lat1/100000. );
// short targetHeight = srtmLookup.height(currentNode.lon2/100000.,currentNode.lat2/100000. );
// short heightDiff = startHeight - targetHeight;

View File

@ -41,11 +41,12 @@ private:
struct _NodeBasedEdgeData {
int distance;
unsigned edgeBasedNodeID;
unsigned nameID;
unsigned nameID:31;
bool shortcut:1;
bool forward:1;
bool backward:1;
bool roundabout:1;
bool ignoreInGrid:1;
short type;
} data;
@ -76,6 +77,7 @@ public:
NodeID id;
NodeID nameID;
unsigned weight;
bool ignoreInGrid;
};
private:

View File

@ -118,6 +118,18 @@ public:
w.roundabout = true;
}
//Is the route tag listed as usable way in the profile?
if(settings[route] > 0 || settings[man_made] > 0) {
w.useful = true;
w.speed = settings[route];
w.direction = _Way::bidirectional;
if(0 < settings[route])
highway = route;
else if (0 < settings[man_made]) {
highway = man_made;
}
}
//Is the highway tag listed as usable way?
if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) {
@ -154,22 +166,14 @@ public:
w.direction = _Way::opposite;
}
}
} else {
//Is the route tag listed as usable way in the profile?
if(settings[route] > 0 || settings[man_made] > 0) {
w.useful = true;
w.speed = settings[route];
w.direction = _Way::bidirectional;
if(0 < settings[route])
highway = route;
else if (0 < settings[man_made]) {
highway = man_made;
}
}
}
if ( w.useful && w.access && (1 < w.path.size()) ) { //Only true if the way is specified by the speed profile
//TODO: type is not set, perhaps use a bimap'ed speed profile to do set the type correctly?
w.type = settings.GetHighwayTypeID(highway);
if(0 > w.type) {
ERR("Resolved highway " << highway << " to " << w.type);
}
//Get the unique identifier for the street name
const StringMap::const_iterator strit = stringMap->find(w.name);
@ -195,7 +199,7 @@ public:
}
for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) {
externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout));
externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout, highway == settings.excludeFromGrid));
externalMemory->usedNodeIDs.push_back(w.path[n]);
}
externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]);

View File

@ -36,7 +36,7 @@ struct _PathData {
};
typedef boost::unordered_map<std::string, NodeID > StringMap;
typedef boost::unordered_map<std::string, std::pair<int, int> > StringToIntPairMap;
typedef boost::unordered_map<std::string, std::pair<int, short> > StringToIntPairMap;
struct _Node : NodeInfo{
_Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {}
@ -134,10 +134,12 @@ struct _Relation {
};
struct _Edge {
_Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false) {};
_Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra) { }
_Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) {};
_Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra, bool iing): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing) {
assert(0 <= type);
}
NodeID start;
NodeID target;
short type;
@ -145,6 +147,7 @@ struct _Edge {
double speed;
unsigned nameID;
bool isRoundabout;
bool ignoreInGrid;
_Coordinate startCoord;
_Coordinate targetCoord;
@ -265,10 +268,11 @@ struct Settings {
}
int GetHighwayTypeID(const std::string & param) const {
if(param == excludeFromGrid) {
return INT_MAX;
return SHRT_MAX;
}
assert(param != "ferry");
if(speedProfile.find(param) == speedProfile.end()) {
DEBUG("There is a bug with highway \"" << param << "\"");
ERR("There is a bug with highway \"" << param << "\"");
return -1;
} else {
return speedProfile.at(param).second;

View File

@ -42,10 +42,10 @@ public:
/** Default constructor. target and weight are set to 0.*/
NodeBasedEdge() :
_source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false) { assert(false); } //shall not be used.
_source(0), _target(0), _name(0), _weight(0), forward(0), backward(0), _type(0), _roundabout(false), _ignoreInGrid(false) { assert(false); } //shall not be used.
explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra) :
_source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra) { assert(ty >= 0); }
explicit NodeBasedEdge(NodeID s, NodeID t, NodeID n, EdgeWeight w, bool f, bool b, short ty, bool ra, bool ig) :
_source(s), _target(t), _name(n), _weight(w), forward(f), backward(b), _type(ty), _roundabout(ra), _ignoreInGrid(ig) { if(ty < 0) {ERR("Type: " << ty);}; }
NodeID target() const {return _target; }
NodeID source() const {return _source; }
@ -57,6 +57,7 @@ public:
bool isForward() const { return forward; }
bool isLocatable() const { return _type != 14; }
bool isRoundabout() const { return _roundabout; }
bool ignoreInGrid() const { return _ignoreInGrid; }
NodeID _source;
NodeID _target;
@ -66,6 +67,7 @@ public:
bool backward;
short _type;
bool _roundabout;
bool _ignoreInGrid;
};
class EdgeBasedEdge {

View File

@ -85,12 +85,13 @@ public:
ramInFile.close();
}
template<typename EdgeT, typename NodeInfoT>
void ConstructGrid(std::vector<EdgeT> & edgeList, std::vector<NodeInfoT> * int2ExtNodeMap, char * ramIndexOut, char * fileIndexOut) {
template<typename EdgeT>
void ConstructGrid(std::vector<EdgeT> & edgeList, char * ramIndexOut, char * fileIndexOut) {
Percent p(edgeList.size());
BOOST_FOREACH(EdgeT & edge, edgeList) {
p.printIncrement();
if(edge.ignoreInGrid)
continue;
int slat = 100000*lat2y(edge.lat1/100000.);
int slon = edge.lon1;
int tlat = 100000*lat2y(edge.lat2/100000.);

View File

@ -38,25 +38,24 @@ struct ObjectsForQueryStruct {
QueryGraph * graph;
ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") {
std::cout << "[objects] loading query data structures ..." << std::flush;
ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
INFO("loading graph data");
std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary);
//Deserialize road network graph
std::vector< QueryGraph::_StrNode> nodeList;
std::vector< QueryGraph::_StrEdge> edgeList;
const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList);
graph = new QueryGraph(nodeList, edgeList);
INFO("Graph has " << graph->GetNumberOfNodes() << " nodes");
INFO("Graph has " << graph->GetNumberOfEdges() << " edges");
assert(0 == nodeList.size());
assert(0 == edgeList.size());
INFO("Loading nearest neighbor indices");
//Init nearest neighbor data structure
ifstream nodesInStream(nodesPath.c_str(), ios::binary);
std::ifstream nodesInStream(nodesPath.c_str(), ios::binary);
nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n);
nodeHelpDesk->initNNGrid(nodesInStream);
//deserialize street name list
ifstream namesInStream(namesPath.c_str(), ios::binary);
INFO("Loading names index");
std::ifstream namesInStream(namesPath.c_str(), ios::binary);
unsigned size(0);
namesInStream.read((char *)&size, sizeof(unsigned));
names = new std::vector<std::string>();
@ -72,7 +71,7 @@ struct ObjectsForQueryStruct {
}
hsgrInStream.close();
namesInStream.close();
std::cout << "ok" << std::endl;
INFO("All query data structures loaded");
}
~ObjectsForQueryStruct() {

View File

@ -142,7 +142,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
short type;
NodeID nameID;
int length;
bool isRoundabout;
bool isRoundabout, ignoreInGrid;
for (EdgeID i=0; i<m; ++i) {
in.read((char*)&source, sizeof(unsigned));
@ -153,6 +153,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
in.read((char*)&type, sizeof(short));
in.read((char*)&nameID, sizeof(unsigned));
in.read((char*)&isRoundabout, sizeof(bool));
in.read((char*)&ignoreInGrid, sizeof(bool));
GUARANTEE(length > 0, "loaded null length edge" );
GUARANTEE(weight > 0, "loaded null weight");
@ -163,6 +164,8 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
if (1 == dir) { backward = false; }
if (2 == dir) { forward = false; }
assert(type >= 0);
// translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
@ -182,7 +185,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
target = intNodeID->second;
GUARANTEE(source != UINT_MAX && target != UINT_MAX, "nonexisting source or target");
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout );
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout, ignoreInGrid );
edgeList.push_back(inputEdge);
}
ext2IntNodeMap.clear();
@ -358,7 +361,6 @@ template<typename NodeT, typename EdgeT>
unsigned readHSGRFromStream(istream &in, vector<NodeT>& nodeList, vector<EdgeT> & edgeList) {
unsigned numberOfNodes = 0;
in.read((char*) & numberOfNodes, sizeof(unsigned));
INFO("Loading " << numberOfNodes << " nodes");
nodeList.resize(numberOfNodes);
NodeT currentNode;
for(unsigned nodeCounter = 0; nodeCounter < numberOfNodes; ++nodeCounter ) {
@ -368,7 +370,6 @@ unsigned readHSGRFromStream(istream &in, vector<NodeT>& nodeList, vector<EdgeT>
unsigned numberOfEdges = 0;
in.read((char*) &numberOfEdges, sizeof(unsigned));
INFO("Loading " << numberOfEdges << " edges");
edgeList.resize(numberOfEdges);
EdgeT currentEdge;
for(unsigned edgeCounter = 0; edgeCounter < numberOfEdges; ++edgeCounter) {

View File

@ -126,7 +126,7 @@ int main (int argc, char *argv[]) {
WritableGrid * writeableGrid = new WritableGrid();
INFO("building grid ...");
writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut);
writeableGrid->ConstructGrid(nodeBasedEdgeList, ramIndexOut, fileIndexOut);
DELETE( writeableGrid );
nodeBasedEdgeList.clear();
std::vector<EdgeBasedGraphFactory::EdgeBasedNode>().swap(nodeBasedEdgeList);

View File

@ -397,8 +397,6 @@ int main (int argc, char *argv[]) {
double weight = ( distance * 10. ) / (edgeIT->speed / 3.6);
int intWeight = max(1, (int) weight);
int intDist = max(1, (int)distance);
int ferryIndex = settings["ferry"];
assert(ferryIndex != -1);
short zero = 0;
short one = 1;
@ -429,6 +427,7 @@ int main (int argc, char *argv[]) {
fout.write((char*)&edgeIT->type, sizeof(short));
fout.write((char*)&edgeIT->nameID, sizeof(unsigned));
fout.write((char*)&edgeIT->isRoundabout, sizeof(bool));
fout.write((char*)&edgeIT->ignoreInGrid, sizeof(bool));
}
++usedEdgeCounter;
++edgeIT;