diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index 2377258f8..f2376727e 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -118,9 +118,21 @@ private: DeallocatingVector edgeBasedNodes; public: - TarjanSCC(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI) : inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) { - BOOST_FOREACH(_Restriction & restriction, irs) { - std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); + TarjanSCC( + int nodes, + std::vector & inputEdges, + std::vector & bn, + std::vector & tl, + std::vector & irs, + std::vector & nI + ) : + inputNodeInfoList(nI), + numberOfTurnRestrictions(irs.size()) + { + BOOST_FOREACH(const TurnRestriction & restriction, irs) { + std::pair restrictionSource = std::make_pair( + restriction.fromNode, restriction.viaNode + ); unsigned index; RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource); if(restrIter == _restrictionMap.end()) { @@ -138,7 +150,9 @@ public: } } - _restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly)); + _restrictionBucketVector.at(index).push_back( + std::make_pair(restriction.toNode, restriction.flags.isOnly) + ); } BOOST_FOREACH(NodeID id, bn) { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index fa5b4d722..c6d138040 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -20,8 +20,18 @@ #include "EdgeBasedGraphFactory.h" -EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, SpeedProfileProperties sp) : speedProfile(sp), inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()) { - BOOST_FOREACH(const _Restriction & restriction, irs) { +EdgeBasedGraphFactory::EdgeBasedGraphFactory( + int nodes, std::vector & inputEdges, + std::vector & bn, + std::vector & tl, + std::vector & input_restrictions_list, + std::vector & inputNodeInfoList, + SpeedProfileProperties speedProfile +) : speedProfile(speedProfile), + m_turn_restrictions_count(0), + inputNodeInfoList(inputNodeInfoList) +{ + BOOST_FOREACH(const TurnRestriction & restriction, input_restrictions_list) { std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); unsigned index; RestrictionMap::iterator restrIter = _restrictionMap.find(restrictionSource); @@ -36,10 +46,11 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector continue; else if(restriction.flags.isOnly){ //We are going to insert an is_only_*-restriction. There can be only one. + m_turn_restrictions_count -= _restrictionBucketVector.at(index).size(); _restrictionBucketVector.at(index).clear(); } } - + ++m_turn_restrictions_count; _restrictionBucketVector.at(index).push_back(std::make_pair(restriction.toNode, restriction.flags.isOnly)); } @@ -48,36 +59,36 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector DeallocatingVector< _NodeBasedEdge > edges; _NodeBasedEdge edge; - for ( std::vector< ImportEdge >::const_iterator i = inputEdges.begin(); i != inputEdges.end(); ++i ) { - if(!i->isForward()) { - edge.source = i->target(); - edge.target = i->source(); - edge.data.backward = i->isForward(); - edge.data.forward = i->isBackward(); + BOOST_FOREACH(const ImportEdge & import_edge, inputEdges) { + if(!import_edge.isForward()) { + edge.source = import_edge.target(); + edge.target = import_edge.source(); + edge.data.backward = import_edge.isForward(); + edge.data.forward = import_edge.isBackward(); } else { - edge.source = i->source(); - edge.target = i->target(); - edge.data.forward = i->isForward(); - edge.data.backward = i->isBackward(); + edge.source = import_edge.source(); + edge.target = import_edge.target(); + edge.data.forward = import_edge.isForward(); + edge.data.backward = import_edge.isBackward(); } if(edge.source == edge.target) { continue; } - edge.data.distance = (std::max)((int)i->weight(), 1 ); + edge.data.distance = (std::max)((int)import_edge.weight(), 1 ); 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.isAccessRestricted = i->isAccessRestricted(); + edge.data.roundabout = import_edge.isRoundabout(); + edge.data.ignoreInGrid = import_edge.ignoreInGrid(); + edge.data.nameID = import_edge.name(); + edge.data.type = import_edge.type(); + edge.data.isAccessRestricted = import_edge.isAccessRestricted(); edge.data.edgeBasedNodeID = edges.size(); - edge.data.contraFlow = i->isContraFlow(); + edge.data.contraFlow = import_edge.isContraFlow(); edges.push_back( edge ); if( edge.data.backward ) { std::swap( edge.source, edge.target ); - edge.data.forward = i->isBackward(); - edge.data.backward = i->isForward(); + edge.data.forward = import_edge.isBackward(); + edge.data.backward = import_edge.isForward(); edge.data.edgeBasedNodeID = edges.size(); edges.push_back( edge ); } @@ -105,7 +116,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector & node nodes.swap(edgeBasedNodes); } -NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn(const NodeID u, const NodeID v) const { +NodeID EdgeBasedGraphFactory::CheckForEmanatingIsOnlyTurn( + const NodeID u, + const NodeID v +) const { const std::pair < NodeID, NodeID > restrictionSource = std::make_pair(u, v); RestrictionMap::const_iterator restrIter = _restrictionMap.find(restrictionSource); if (restrIter != _restrictionMap.end()) { diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 43563b3b7..c53d69464 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -105,6 +105,25 @@ public: bool has_turn_penalty_function; } speedProfile; + explicit EdgeBasedGraphFactory( + int nodes, + std::vector & inputEdges, + std::vector & _bollardNodes, + std::vector & trafficLights, + std::vector & inputRestrictions, + std::vector & nI, + SpeedProfileProperties speedProfile + ); + + void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); + void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); + void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); + void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); + TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; + int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const; + + unsigned GetNumberOfNodes() const; + private: struct _NodeBasedEdgeData { int distance; @@ -129,6 +148,8 @@ private: TurnInstruction turnInstruction; }; + unsigned m_turn_restrictions_count; + typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph; typedef _NodeBasedDynamicGraph::InputEdge _NodeBasedEdge; std::vector inputNodeInfoList; @@ -158,17 +179,6 @@ private: template double GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const; -public: - explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & _bollardNodes, std::vector & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector & nI, SpeedProfileProperties speedProfile); - - void Run(const char * originalEdgeDataFilename, lua_State *myLuaState); - void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges ); - void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); - void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData); - TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; - int GetTurnPenalty(const NodeID u, const NodeID v, const NodeID w, lua_State *myLuaState) const; - - unsigned GetNumberOfNodes() const; }; #endif /* EDGEBASEDGRAPHFACTORY_H_ */ diff --git a/DataStructures/Restriction.h b/DataStructures/Restriction.h index fc40fb0ba..2693700e7 100644 --- a/DataStructures/Restriction.h +++ b/DataStructures/Restriction.h @@ -23,14 +23,16 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef RESTRICTION_H_ #define RESTRICTION_H_ +#include "../typedefs.h" #include -struct _Restriction { +struct TurnRestriction { NodeID viaNode; NodeID fromNode; NodeID toNode; struct Bits { //mostly unused - Bits() : + Bits() + : isOnly(false), unused1(false), unused2(false), @@ -38,9 +40,8 @@ struct _Restriction { unused4(false), unused5(false), unused6(false), - unused7(false) { - - } + unused7(false) + { } bool isOnly:1; bool unused1:1; @@ -52,14 +53,14 @@ struct _Restriction { bool unused7:1; } flags; - _Restriction(NodeID vn) : - viaNode(vn), + TurnRestriction(NodeID viaNode) : + viaNode(viaNode), fromNode(UINT_MAX), toNode(UINT_MAX) { } - _Restriction(const bool isOnly = false) : + TurnRestriction(const bool isOnly = false) : viaNode(UINT_MAX), fromNode(UINT_MAX), toNode(UINT_MAX) { @@ -68,13 +69,32 @@ struct _Restriction { }; struct _RawRestrictionContainer { - _Restriction restriction; + TurnRestriction restriction; EdgeID fromWay; EdgeID toWay; unsigned viaNode; - _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;} - _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;} + _RawRestrictionContainer( + EdgeID fromWay, + EdgeID toWay, + NodeID vn, + unsigned vw + ) : + fromWay(fromWay), + toWay(toWay), + viaNode(vw) + { + restriction.viaNode = vn; + } + _RawRestrictionContainer( + bool isOnly = false + ) : + fromWay(UINT_MAX), + toWay(UINT_MAX), + viaNode(UINT_MAX) + { + restriction.flags.isOnly = isOnly; + } static _RawRestrictionContainer min_value() { return _RawRestrictionContainer(0, 0, 0, 0); diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 255d545e4..515c78b84 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -125,7 +125,7 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned)); for(restrictionsIT = restrictionsVector.begin(); restrictionsIT != restrictionsVector.end(); ++restrictionsIT) { if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { - restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(_Restriction)); + restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(TurnRestriction)); } } restrictionsOutstream.close(); diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index 2273456c7..12d0a1d64 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -43,19 +43,21 @@ typedef QueryEdge::EdgeData EdgeData; typedef DynamicGraph::InputEdge InputEdge; std::vector internal_to_external_node_map; -std::vector<_Restriction> restrictions_vector; +std::vector restrictions_vector; std::vector bollard_node_IDs_vector; std::vector traffic_light_node_IDs_vector; -int main (int argument_count, char *argument_values[]) { +int main (int argc, char * argv[]) { LogPolicy::GetInstance().Unmute(); - if(argument_count < 3) { - std::cerr << "usage:\n" << argument_values[0] << " " << std::endl; + if(argc < 3) { + SimpleLogger().Write(logWARNING) << + "usage:\n" << argv[0] << " "; return -1; } - SimpleLogger().Write() << "Using restrictions from file: " << argument_values[2]; - std::ifstream restriction_ifstream(argument_values[2], std::ios::binary); + SimpleLogger().Write() << + "Using restrictions from file: " << argv[2]; + std::ifstream restriction_ifstream(argv[2], std::ios::binary); if(!restriction_ifstream.good()) { throw OSRMException("Could not access files"); } @@ -68,15 +70,12 @@ int main (int argument_count, char *argument_values[]) { restriction_ifstream.read( (char *)&(restrictions_vector[0]), - usable_restriction_count*sizeof(_Restriction) + usable_restriction_count*sizeof(TurnRestriction) ); restriction_ifstream.close(); std::ifstream input_stream; - input_stream.open( - argument_values[1], - std::ifstream::in | std::ifstream::binary - ); + input_stream.open( argv[1], std::ifstream::in | std::ifstream::binary ); if (!input_stream.is_open()) { throw OSRMException("Cannot open osrm file"); @@ -115,7 +114,7 @@ int main (int argument_count, char *argument_values[]) { tarjan->Run(); - std::vector<_Restriction>().swap(restrictions_vector); + std::vector().swap(restrictions_vector); std::vector().swap(bollard_node_IDs_vector); std::vector().swap(traffic_light_node_IDs_vector); SimpleLogger().Write() << "finished component analysis"; diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index a31a9f640..7a674da01 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -60,7 +60,7 @@ NodeID readBinaryOSRMGraphFromStream( std::vector &bollardNodes, std::vector &trafficLightNodes, std::vector * int2ExtNodeMap, - std::vector<_Restriction> & inputRestrictions + std::vector & inputRestrictions ) { const UUID uuid_orig; UUID uuid_loaded; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index daa6138de..a3c6ceb20 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -53,7 +53,7 @@ typedef StaticGraph::InputEdge StaticEdge; typedef IniFile ContractorConfiguration; std::vector internalToExternalNodeMapping; -std::vector<_Restriction> inputRestrictions; +std::vector inputRestrictions; std::vector bollardNodes; std::vector trafficLightNodes; std::vector edgeList; @@ -85,7 +85,7 @@ int main (int argc, char *argv[]) { "Could not access files" << std::endl; } - _Restriction restriction; + TurnRestriction restriction; UUID uuid_loaded, uuid_orig; unsigned usableRestrictionsCounter(0); restrictionsInstream.read((char*)&uuid_loaded, sizeof(UUID)); @@ -95,9 +95,15 @@ int main (int argc, char *argv[]) { "Reprocess to get rid of this warning."; } - restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); + restrictionsInstream.read( + (char*)&usableRestrictionsCounter, + sizeof(unsigned) + ); inputRestrictions.resize(usableRestrictionsCounter); - restrictionsInstream.read((char *)&(inputRestrictions[0]), usableRestrictionsCounter*sizeof(_Restriction)); + restrictionsInstream.read( + (char *)&(inputRestrictions[0]), + usableRestrictionsCounter*sizeof(TurnRestriction) + ); restrictionsInstream.close(); std::ifstream in; @@ -190,7 +196,7 @@ int main (int argc, char *argv[]) { EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile); std::vector().swap(edgeList); edgeBasedGraphFactory->Run(edgeOut.c_str(), myLuaState); - std::vector<_Restriction>().swap(inputRestrictions); + std::vector().swap(inputRestrictions); std::vector().swap(bollardNodes); std::vector().swap(trafficLightNodes); NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); diff --git a/extractor.cpp b/extractor.cpp index 29296f919..d39c00ab6 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -46,7 +46,6 @@ int main (int argc, char *argv[]) { try { LogPolicy::GetInstance().Unmute(); double startup_time = get_timestamp(); - if(argc < 2) { SimpleLogger().Write(logWARNING) << "usage: \n" << @@ -59,6 +58,7 @@ int main (int argc, char *argv[]) { ScriptingEnvironment scriptingEnvironment((argc > 2 ? argv[2] : "profile.lua")); unsigned number_of_threads = omp_get_num_procs(); + if(testDataFile("extractor.ini")) { IniFile extractorConfig("extractor.ini"); unsigned rawNumber = stringToInt(extractorConfig.GetParameter("Threads"));