barrier=bollard is now used. Fixes ticket #9 and saves about .5% RAM in

metropolitan areas
This commit is contained in:
DennisOSRM 2012-01-02 13:09:20 +01:00
parent 057e3a936e
commit 70256146fc
9 changed files with 111 additions and 67 deletions

View File

@ -29,13 +29,25 @@
#include "EdgeBasedGraphFactory.h" #include "EdgeBasedGraphFactory.h"
template<> template<>
EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI, std::string & srtm) EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<NodeID> & bn, std::vector<NodeID> & tl, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI, std::string & srtm)
: inputRestrictions(irs), inputNodeInfoList(nI)/*, srtmLookup(srtm) */{ : inputRestrictions(irs), inputNodeInfoList(nI)/*, srtmLookup(srtm) */{
#ifdef _GLIBCXX_PARALLEL #ifdef _GLIBCXX_PARALLEL
__gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom); __gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom);
#else #else
std::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom); std::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom);
BOOST_FOREACH(NodeID id, bn) {
_bollardNodes.Add(id, true);
}
BOOST_FOREACH(NodeID id, tl) {
_trafficLights.Add(id, true);
}
INFO("bollards: " << _bollardNodes.Size());
INFO("signals: " << _trafficLights.Size());
#endif #endif
std::vector< _NodeBasedEdge > edges; std::vector< _NodeBasedEdge > edges;
@ -117,6 +129,8 @@ void EdgeBasedGraphFactory::Run() {
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
++nodeBasedEdgeCounter; ++nodeBasedEdgeCounter;
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
if(_bollardNodes.Find(v) == true)
continue;
//loop over all reachable edges (v,w) //loop over all reachable edges (v,w)
bool isOnlyAllowed(false); bool isOnlyAllowed(false);

View File

@ -31,6 +31,7 @@
#include "../typedefs.h" #include "../typedefs.h"
#include "../DataStructures/DynamicGraph.h" #include "../DataStructures/DynamicGraph.h"
#include "../DataStructures/ExtractorStructs.h" #include "../DataStructures/ExtractorStructs.h"
#include "../DataStructures/HashTable.h"
#include "../DataStructures/ImportEdge.h" #include "../DataStructures/ImportEdge.h"
#include "../DataStructures/Percent.h" #include "../DataStructures/Percent.h"
#include "../DataStructures/TurnInstructions.h" #include "../DataStructures/TurnInstructions.h"
@ -82,6 +83,8 @@ public:
private: private:
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
HashTable<NodeID, bool> _bollardNodes;
HashTable<NodeID, bool> _trafficLights;
std::vector<_Restriction> & inputRestrictions; std::vector<_Restriction> & inputRestrictions;
std::vector<NodeInfo> & inputNodeInfoList; std::vector<NodeInfo> & inputNodeInfoList;
@ -95,7 +98,7 @@ private:
public: public:
template< class InputEdgeT > template< class InputEdgeT >
explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, std::string & srtm); explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<NodeID> & _bollardNodes, std::vector<NodeID> & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, std::string & srtm);
virtual ~EdgeBasedGraphFactory(); virtual ~EdgeBasedGraphFactory();
void Run(); void Run();

View File

@ -39,18 +39,21 @@ typedef boost::unordered_map<std::string, NodeID > StringMap;
typedef boost::unordered_map<std::string, std::pair<int, short> > StringToIntPairMap; typedef boost::unordered_map<std::string, std::pair<int, short> > StringToIntPairMap;
struct _Node : NodeInfo{ struct _Node : NodeInfo{
_Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {} _Node(int _lat, int _lon, unsigned int _id, bool _bollard, bool _trafficLight) : NodeInfo(_lat, _lon, _id), bollard(_bollard), trafficLight(_trafficLight) {}
_Node() {} _Node() : bollard(false), trafficLight(false) {}
static _Node min_value() { static _Node min_value() {
return _Node(0,0,0); return _Node(0,0,0, false, false);
} }
static _Node max_value() { static _Node max_value() {
return _Node((numeric_limits<int>::max)(), (numeric_limits<int>::max)(), (numeric_limits<unsigned int>::max)()); return _Node((numeric_limits<int>::max)(), (numeric_limits<int>::max)(), (numeric_limits<unsigned int>::max)(), false, false);
} }
NodeID key() const { NodeID key() const {
return id; return id;
} }
bool bollard;
bool trafficLight;
}; };
struct _Coordinate { struct _Coordinate {
@ -258,7 +261,7 @@ struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDSta
}; };
struct Settings { struct Settings {
Settings() : obeyPollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar"), defaultSpeed(30), excludeFromGrid("ferry") {} Settings() : obeyBollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar"), defaultSpeed(30), trafficLightPenalty(0), excludeFromGrid("ferry") {}
StringToIntPairMap speedProfile; StringToIntPairMap speedProfile;
int operator[](const std::string & param) const { int operator[](const std::string & param) const {
if(speedProfile.find(param) == speedProfile.end()) if(speedProfile.find(param) == speedProfile.end())
@ -278,11 +281,12 @@ struct Settings {
return speedProfile.at(param).second; return speedProfile.at(param).second;
} }
} }
bool obeyPollards; bool obeyBollards;
bool obeyOneways; bool obeyOneways;
bool useRestrictions; bool useRestrictions;
std::string accessTag; std::string accessTag;
int defaultSpeed; int defaultSpeed;
int trafficLightPenalty;
std::string excludeFromGrid; std::string excludeFromGrid;
}; };

View File

@ -219,6 +219,13 @@ private:
int keyValue = dense.keys_vals ( denseTagIndex+1 ); int keyValue = dense.keys_vals ( denseTagIndex+1 );
std::string key = threadData->PBFprimitiveBlock.stringtable().s(tagValue).data(); std::string key = threadData->PBFprimitiveBlock.stringtable().s(tagValue).data();
std::string value = threadData->PBFprimitiveBlock.stringtable().s(keyValue).data(); std::string value = threadData->PBFprimitiveBlock.stringtable().s(keyValue).data();
if("barrier" == key && "bollard" == value) {
n.bollard = true;
}
if("highway" == key && "traffic_signals" == value) {
n.trafficLight = true;
}
keyVals.Add(key, value); keyVals.Add(key, value);
denseTagIndex += 2; denseTagIndex += 2;
} }

View File

@ -253,7 +253,12 @@ private:
if ( k != NULL && value != NULL ) { if ( k != NULL && value != NULL ) {
if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 1 ) { if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 1 ) {
if ( xmlStrEqual( value, ( const xmlChar* ) "traffic_signals" ) == 1 ){ if ( xmlStrEqual( value, ( const xmlChar* ) "traffic_signals" ) == 1 ){
//node.trafficSignal = true; node.trafficLight = true;
}
}
if ( xmlStrEqual( k, ( const xmlChar* ) "barrier" ) == 1 ) {
if ( xmlStrEqual( value, ( const xmlChar* ) "bollard" ) == 1 ){
node.bollard = true;
} }
} }
} }

View File

@ -96,21 +96,24 @@ NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
return n; return n;
} }
template<typename EdgeT> template<typename EdgeT>
NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap, vector<_Restriction> & inputRestrictions) { NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeID> &bollardNodes, std::vector<NodeID> &trafficLightNodes, std::vector<NodeInfo> * int2ExtNodeMap, std::vector<_Restriction> & inputRestrictions) {
NodeID n, source, target, id; NodeID n, source, target;
EdgeID m; EdgeID m;
short dir; short dir;// direction (0 = open, 1 = forward, 2+ = open)
int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext2IntNodeMap;
in.read((char*)&n, sizeof(NodeID)); in.read((char*)&n, sizeof(NodeID));
DEBUG("Importing n = " << n << " nodes "); DEBUG("Importing n = " << n << " nodes ");
_Node node;
for (NodeID i=0; i<n; ++i) { for (NodeID i=0; i<n; ++i) {
in.read((char*)&id, sizeof(unsigned)); in.read((char*)&node, sizeof(_Node));
in.read((char*)&ycoord, sizeof(int)); int2ExtNodeMap->push_back(NodeInfo(node.lat, node.lon, node.id));
in.read((char*)&xcoord, sizeof(int)); ext2IntNodeMap.insert(make_pair(node.id, i));
int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); if(node.bollard)
ext2IntNodeMap.insert(make_pair(id, i)); bollardNodes.push_back(i);
if(node.trafficLight)
trafficLightNodes.push_back(i);
} }
in.read((char*)&m, sizeof(unsigned)); in.read((char*)&m, sizeof(unsigned));
DEBUG(" and " << m << " edges "); DEBUG(" and " << m << " edges ");
for(unsigned i = 0; i < inputRestrictions.size(); ++i) { for(unsigned i = 0; i < inputRestrictions.size(); ++i) {

View File

@ -58,22 +58,13 @@ typedef BaseConfiguration ContractorConfiguration;
std::vector<NodeInfo> internalToExternaleNodeMapping; std::vector<NodeInfo> internalToExternaleNodeMapping;
std::vector<_Restriction> inputRestrictions; std::vector<_Restriction> inputRestrictions;
std::vector<NodeID> bollardNodes;
std::vector<NodeID> trafficLightNodes;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
if(argc < 3) { if(argc < 3) {
ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>"); ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>");
} }
INFO("Using restrictions from file: " << argv[2]);
std::ifstream restrictionsInstream(argv[2], ios::binary);
_Restriction restriction;
unsigned usableRestrictionsCounter(0);
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
for(unsigned i = 0; i < usableRestrictionsCounter; ++i) {
restrictionsInstream.read((char *)&(restriction), sizeof(_Restriction));
inputRestrictions.push_back(restriction);
}
restrictionsInstream.close();
INFO("Loaded " << inputRestrictions.size() << " restrictions from file");
unsigned numberOfThreads = omp_get_num_procs(); unsigned numberOfThreads = omp_get_num_procs();
std::string SRTM_ROOT; std::string SRTM_ROOT;
@ -88,13 +79,26 @@ int main (int argc, char *argv[]) {
INFO("Loading SRTM from/to " << SRTM_ROOT); INFO("Loading SRTM from/to " << SRTM_ROOT);
omp_set_num_threads(numberOfThreads); omp_set_num_threads(numberOfThreads);
INFO("preprocessing data from input file " << argv[1] << " using STL " INFO("preprocessing data from input file " << argv[2] << " using STL "
#ifdef _GLIBCXX_PARALLEL #ifdef _GLIBCXX_PARALLEL
"parallel (GCC)" "parallel (GCC)"
#else #else
"serial" "serial"
#endif #endif
" mode"); " mode");
INFO("Using restrictions from file: " << argv[2]);
std::ifstream restrictionsInstream(argv[2], ios::binary);
_Restriction restriction;
unsigned usableRestrictionsCounter(0);
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
for(unsigned i = 0; i < usableRestrictionsCounter; ++i) {
restrictionsInstream.read((char *)&(restriction), sizeof(_Restriction));
inputRestrictions.push_back(restriction);
}
restrictionsInstream.close();
ifstream in; ifstream in;
in.open (argv[1], ifstream::in | ifstream::binary); in.open (argv[1], ifstream::in | ifstream::binary);
if (!in.is_open()) { if (!in.is_open()) {
@ -108,10 +112,11 @@ int main (int argc, char *argv[]) {
char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels"); char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels");
std::vector<ImportEdge> edgeList; std::vector<ImportEdge> edgeList;
NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions); NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternaleNodeMapping, inputRestrictions);
in.close(); in.close();
INFO("Loaded " << inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights");
EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, inputRestrictions, internalToExternaleNodeMapping, SRTM_ROOT); EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternaleNodeMapping, SRTM_ROOT);
edgeList.clear(); edgeList.clear();
std::vector<ImportEdge>().swap(edgeList); std::vector<ImportEdge>().swap(edgeList);

View File

@ -100,8 +100,8 @@ int main (int argc, char *argv[]) {
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
try { try {
INFO("Loading speed profiles") INFO("Loading speed profiles");
boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt); boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt);
INFO("Found the following speed profiles: "); INFO("Found the following speed profiles: ");
int profileCounter(0); int profileCounter(0);
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) { BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) {
@ -118,21 +118,18 @@ int main (int argc, char *argv[]) {
if(name == "obeyOneways") { if(name == "obeyOneways") {
if(value == "no") if(value == "no")
settings.obeyOneways = false; settings.obeyOneways = false;
continue;
} else { } else {
if(name == "obeyPollards") { if(name == "obeyBollards") {
if(value == "no") if(value == "no") {
settings.obeyPollards = false; settings.obeyBollards = false;
continue; }
} else { } else {
if(name == "useRestrictions") { if(name == "useRestrictions") {
if(value == "no") if(value == "no")
settings.useRestrictions = false; settings.useRestrictions = false;
continue;
} else { } else {
if(name == "accessTag") { if(name == "accessTag") {
settings.accessTag = value; settings.accessTag = value;
continue;
} else { } else {
if(name == "excludeFromGrid") { if(name == "excludeFromGrid") {
settings.excludeFromGrid = value; settings.excludeFromGrid = value;
@ -140,6 +137,10 @@ int main (int argc, char *argv[]) {
if(name == "defaultSpeed") { if(name == "defaultSpeed") {
settings.defaultSpeed = atoi(value.c_str()); settings.defaultSpeed = atoi(value.c_str());
settings.speedProfile["default"] = std::make_pair(settings.defaultSpeed, settings.speedProfile.size() ); settings.speedProfile["default"] = std::make_pair(settings.defaultSpeed, settings.speedProfile.size() );
} else {
if( name == "trafficLightPenalty") {
settings.trafficLightPenalty = atoi(value.c_str());
}
} }
} }
} }
@ -289,7 +290,7 @@ int main (int argc, char *argv[]) {
++restrictionsIT; ++restrictionsIT;
} }
cout << "ok, after " << get_timestamp() - time << "s" << endl; cout << "ok, after " << get_timestamp() - time << "s" << endl;
INFO("usable restrictions: " << usableRestrictionsCounter); INFO("usable restrictions: " << usableRestrictionsCounter );
//serialize restrictions //serialize restrictions
ofstream restrictionsOutstream; ofstream restrictionsOutstream;
restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary); restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary);
@ -305,7 +306,8 @@ int main (int argc, char *argv[]) {
fout.open(outputFileName.c_str(), ios::binary); fout.open(outputFileName.c_str(), ios::binary);
fout.write((char*)&usedNodeCounter, sizeof(unsigned)); fout.write((char*)&usedNodeCounter, sizeof(unsigned));
time = get_timestamp(); time = get_timestamp();
cout << "[extractor] Confirming used nodes ... " << flush; cout << "[extractor] Confirming/Writing used nodes ... " << flush;
STXXLNodeVector::iterator nodesIT = externalMemory.allNodes.begin(); STXXLNodeVector::iterator nodesIT = externalMemory.allNodes.begin();
STXXLNodeIDVector::iterator usedNodeIDsIT = externalMemory.usedNodeIDs.begin(); STXXLNodeIDVector::iterator usedNodeIDsIT = externalMemory.usedNodeIDs.begin();
while(usedNodeIDsIT != externalMemory.usedNodeIDs.end() && nodesIT != externalMemory.allNodes.end()) { while(usedNodeIDsIT != externalMemory.usedNodeIDs.end() && nodesIT != externalMemory.allNodes.end()) {
@ -318,9 +320,9 @@ int main (int argc, char *argv[]) {
continue; continue;
} }
if(*usedNodeIDsIT == nodesIT->id) { if(*usedNodeIDsIT == nodesIT->id) {
fout.write((char*)&(nodesIT->id), sizeof(unsigned)); if(!settings.obeyBollards && nodesIT->bollard)
fout.write((char*)&(nodesIT->lon), sizeof(int)); nodesIT->bollard = false;
fout.write((char*)&(nodesIT->lat), sizeof(int)); fout.write((char*)&(*nodesIT), sizeof(_Node));
++usedNodeCounter; ++usedNodeCounter;
++usedNodeIDsIT; ++usedNodeIDsIT;
++nodesIT; ++nodesIT;
@ -378,6 +380,7 @@ int main (int argc, char *argv[]) {
// Traverse list of edges and nodes in parallel and set target coord // Traverse list of edges and nodes in parallel and set target coord
nodesIT = externalMemory.allNodes.begin(); nodesIT = externalMemory.allNodes.begin();
edgeIT = externalMemory.allEdges.begin(); edgeIT = externalMemory.allEdges.begin();
while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) { while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) {
if(edgeIT->target < nodesIT->id){ if(edgeIT->target < nodesIT->id){
++edgeIT; ++edgeIT;

View File

@ -1,25 +1,25 @@
[car] [car]
motorway = 110 motorway = 110
motorway_link = 90 motorway_link = 90
trunk = 90 trunk = 90
trunk_link = 70 trunk_link = 70
primary = 70 primary = 70
primary_link = 60 primary_link = 60
secondary = 60 secondary = 60
secondary_link = 50 secondary_link = 50
tertiary = 55 tertiary = 55
unclassified = 25 unclassified = 25
residential = 40 residential = 40
living_street = 10 living_street = 10
service = 30 service = 30
ferry = 5 ferry = 5
pier = 5 pier = 5
obeyBollards = yes obeyBollards = yes
obeyOneways = yes obeyOneways = yes
useRestrictions = yes useRestrictions = yes
accessTag = motorcar accessTag = motorcar
excludeFromGrid = ferry excludeFromGrid = ferry
defaultSpeed = 50 defaultSpeed = 50
trafficLightPenalty = 15 trafficLightPenalty = 15
[bike] [bike]
trunk = 16 trunk = 16