diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 05050df2ef8..18a7c86e752 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -29,13 +29,25 @@ #include "EdgeBasedGraphFactory.h" template<> -EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector<_Restriction> & irs, std::vector & nI, std::string & srtm) +EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, std::string & srtm) : inputRestrictions(irs), inputNodeInfoList(nI)/*, srtmLookup(srtm) */{ #ifdef _GLIBCXX_PARALLEL __gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom); #else 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 std::vector< _NodeBasedEdge > edges; @@ -117,6 +129,8 @@ void EdgeBasedGraphFactory::Run() { for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { ++nodeBasedEdgeCounter; _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); + if(_bollardNodes.Find(v) == true) + continue; //loop over all reachable edges (v,w) bool isOnlyAllowed(false); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 162b3ac45a1..b08be94276b 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -31,6 +31,7 @@ #include "../typedefs.h" #include "../DataStructures/DynamicGraph.h" #include "../DataStructures/ExtractorStructs.h" +#include "../DataStructures/HashTable.h" #include "../DataStructures/ImportEdge.h" #include "../DataStructures/Percent.h" #include "../DataStructures/TurnInstructions.h" @@ -82,6 +83,8 @@ class EdgeBasedGraphFactory { private: boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; + HashTable _bollardNodes; + HashTable _trafficLights; std::vector<_Restriction> & inputRestrictions; std::vector & inputNodeInfoList; @@ -95,7 +98,7 @@ class EdgeBasedGraphFactory { public: template< class InputEdgeT > - explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector<_Restriction> & inputRestrictions, std::vector & nI, std::string & srtm); + explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & _bollardNodes, std::vector & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector & nI, std::string & srtm); virtual ~EdgeBasedGraphFactory(); void Run(); diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index 79ab9497914..25812f84c01 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -39,18 +39,21 @@ typedef boost::unordered_map StringMap; typedef boost::unordered_map > StringToIntPairMap; struct _Node : NodeInfo{ - _Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {} - _Node() {} + _Node(int _lat, int _lon, unsigned int _id, bool _bollard, bool _trafficLight) : NodeInfo(_lat, _lon, _id), bollard(_bollard), trafficLight(_trafficLight) {} + _Node() : bollard(false), trafficLight(false) {} static _Node min_value() { - return _Node(0,0,0); + return _Node(0,0,0, false, false); } static _Node max_value() { - return _Node((numeric_limits::max)(), (numeric_limits::max)(), (numeric_limits::max)()); + return _Node((numeric_limits::max)(), (numeric_limits::max)(), (numeric_limits::max)(), false, false); } NodeID key() const { return id; } + bool bollard; + bool trafficLight; + }; struct _Coordinate { @@ -258,7 +261,7 @@ struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDSta }; 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; int operator[](const std::string & param) const { if(speedProfile.find(param) == speedProfile.end()) @@ -278,11 +281,12 @@ struct Settings { return speedProfile.at(param).second; } } - bool obeyPollards; + bool obeyBollards; bool obeyOneways; bool useRestrictions; std::string accessTag; int defaultSpeed; + int trafficLightPenalty; std::string excludeFromGrid; }; diff --git a/DataStructures/PBFParser.h b/DataStructures/PBFParser.h index ef0e4a4f237..ecff19c263c 100644 --- a/DataStructures/PBFParser.h +++ b/DataStructures/PBFParser.h @@ -219,6 +219,13 @@ class PBFParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { int keyValue = dense.keys_vals ( denseTagIndex+1 ); std::string key = threadData->PBFprimitiveBlock.stringtable().s(tagValue).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); denseTagIndex += 2; } diff --git a/DataStructures/XMLParser.h b/DataStructures/XMLParser.h index 010287ebec5..6722688134d 100644 --- a/DataStructures/XMLParser.h +++ b/DataStructures/XMLParser.h @@ -253,7 +253,12 @@ class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { if ( k != NULL && value != NULL ) { if ( xmlStrEqual( k, ( const xmlChar* ) "highway" ) == 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; } } } diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 0c50b7104d2..75dbfad4b8a 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -96,21 +96,24 @@ NodeID readOSRMGraphFromStream(istream &in, vector& edgeList, vector -NodeID readBinaryOSRMGraphFromStream(istream &in, vector& edgeList, vector * int2ExtNodeMap, vector<_Restriction> & inputRestrictions) { - NodeID n, source, target, id; +NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector& edgeList, std::vector &bollardNodes, std::vector &trafficLightNodes, std::vector * int2ExtNodeMap, std::vector<_Restriction> & inputRestrictions) { + NodeID n, source, target; EdgeID m; - short dir; - int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) + short dir;// direction (0 = open, 1 = forward, 2+ = open) ExternalNodeMap ext2IntNodeMap; in.read((char*)&n, sizeof(NodeID)); DEBUG("Importing n = " << n << " nodes "); + _Node node; for (NodeID i=0; ipush_back(NodeInfo(xcoord, ycoord, id)); - ext2IntNodeMap.insert(make_pair(id, i)); + in.read((char*)&node, sizeof(_Node)); + int2ExtNodeMap->push_back(NodeInfo(node.lat, node.lon, node.id)); + ext2IntNodeMap.insert(make_pair(node.id, i)); + if(node.bollard) + bollardNodes.push_back(i); + if(node.trafficLight) + trafficLightNodes.push_back(i); } + in.read((char*)&m, sizeof(unsigned)); DEBUG(" and " << m << " edges "); for(unsigned i = 0; i < inputRestrictions.size(); ++i) { diff --git a/createHierarchy.cpp b/createHierarchy.cpp index d1889779685..8fae4782687 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -58,22 +58,13 @@ typedef BaseConfiguration ContractorConfiguration; std::vector internalToExternaleNodeMapping; std::vector<_Restriction> inputRestrictions; +std::vector bollardNodes; +std::vector trafficLightNodes; int main (int argc, char *argv[]) { if(argc < 3) { ERR("usage: " << std::endl << argv[0] << " "); } - 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(); std::string SRTM_ROOT; @@ -88,13 +79,26 @@ int main (int argc, char *argv[]) { INFO("Loading SRTM from/to " << SRTM_ROOT); 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 "parallel (GCC)" #else "serial" #endif " 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; in.open (argv[1], ifstream::in | ifstream::binary); if (!in.is_open()) { @@ -108,10 +112,11 @@ int main (int argc, char *argv[]) { char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels"); std::vector edgeList; - NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions); + NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternaleNodeMapping, inputRestrictions); 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(); std::vector().swap(edgeList); diff --git a/extractor.cpp b/extractor.cpp index 1c6679544a3..d85013f3105 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -100,8 +100,8 @@ int main (int argc, char *argv[]) { boost::property_tree::ptree pt; try { - INFO("Loading speed profiles") - boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt); + INFO("Loading speed profiles"); + boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt); INFO("Found the following speed profiles: "); int profileCounter(0); 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(value == "no") settings.obeyOneways = false; - continue; } else { - if(name == "obeyPollards") { - if(value == "no") - settings.obeyPollards = false; - continue; + if(name == "obeyBollards") { + if(value == "no") { + settings.obeyBollards = false; + } } else { if(name == "useRestrictions") { if(value == "no") settings.useRestrictions = false; - continue; } else { if(name == "accessTag") { settings.accessTag = value; - continue; } else { if(name == "excludeFromGrid") { settings.excludeFromGrid = value; @@ -140,6 +137,10 @@ int main (int argc, char *argv[]) { if(name == "defaultSpeed") { settings.defaultSpeed = atoi(value.c_str()); 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; } cout << "ok, after " << get_timestamp() - time << "s" << endl; - INFO("usable restrictions: " << usableRestrictionsCounter); + INFO("usable restrictions: " << usableRestrictionsCounter ); //serialize restrictions ofstream restrictionsOutstream; 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.write((char*)&usedNodeCounter, sizeof(unsigned)); time = get_timestamp(); - cout << "[extractor] Confirming used nodes ... " << flush; + cout << "[extractor] Confirming/Writing used nodes ... " << flush; + STXXLNodeVector::iterator nodesIT = externalMemory.allNodes.begin(); STXXLNodeIDVector::iterator usedNodeIDsIT = externalMemory.usedNodeIDs.begin(); while(usedNodeIDsIT != externalMemory.usedNodeIDs.end() && nodesIT != externalMemory.allNodes.end()) { @@ -318,9 +320,9 @@ int main (int argc, char *argv[]) { continue; } if(*usedNodeIDsIT == nodesIT->id) { - fout.write((char*)&(nodesIT->id), sizeof(unsigned)); - fout.write((char*)&(nodesIT->lon), sizeof(int)); - fout.write((char*)&(nodesIT->lat), sizeof(int)); + if(!settings.obeyBollards && nodesIT->bollard) + nodesIT->bollard = false; + fout.write((char*)&(*nodesIT), sizeof(_Node)); ++usedNodeCounter; ++usedNodeIDsIT; ++nodesIT; @@ -378,6 +380,7 @@ int main (int argc, char *argv[]) { // Traverse list of edges and nodes in parallel and set target coord nodesIT = externalMemory.allNodes.begin(); edgeIT = externalMemory.allEdges.begin(); + while(edgeIT != externalMemory.allEdges.end() && nodesIT != externalMemory.allNodes.end()) { if(edgeIT->target < nodesIT->id){ ++edgeIT; diff --git a/speedprofile.ini b/speedprofile.ini index 28506a1cdfa..2a504a0cd11 100644 --- a/speedprofile.ini +++ b/speedprofile.ini @@ -1,25 +1,25 @@ [car] - motorway = 110 - motorway_link = 90 - trunk = 90 - trunk_link = 70 - primary = 70 - primary_link = 60 - secondary = 60 - secondary_link = 50 - tertiary = 55 - unclassified = 25 - residential = 40 - living_street = 10 - service = 30 - ferry = 5 - pier = 5 - obeyBollards = yes - obeyOneways = yes - useRestrictions = yes - accessTag = motorcar - excludeFromGrid = ferry - defaultSpeed = 50 + motorway = 110 + motorway_link = 90 + trunk = 90 + trunk_link = 70 + primary = 70 + primary_link = 60 + secondary = 60 + secondary_link = 50 + tertiary = 55 + unclassified = 25 + residential = 40 + living_street = 10 + service = 30 + ferry = 5 + pier = 5 + obeyBollards = yes + obeyOneways = yes + useRestrictions = yes + accessTag = motorcar + excludeFromGrid = ferry + defaultSpeed = 50 trafficLightPenalty = 15 [bike] trunk = 16