diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 7a2ce3e0b..af78b46eb 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -24,14 +24,30 @@ #include #endif #include +#include +#include +#include #include "../Util/OpenMPReplacement.h" #include "EdgeBasedGraphFactory.h" template<> -EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, 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, boost::property_tree::ptree speedProfile, std::string & srtm) : inputRestrictions(irs), inputNodeInfoList(nI)/*, srtmLookup(srtm) */{ + std::string usedSpeedProfile(speedProfile.get_child("").begin()->first); + BOOST_FOREACH(boost::property_tree::ptree::value_type &v, speedProfile.get_child(usedSpeedProfile)) { + if("trafficSignalPenalty" == v.first) { + std::string value = v.second.get(""); + try { + trafficSignalPenalty = 10*boost::lexical_cast(v.second.get("")); + } catch(boost::bad_lexical_cast &) { + trafficSignalPenalty = 0; + } + } + } + INFO("Using traffic signal penalty: " << trafficSignalPenalty ); + #ifdef _GLIBCXX_PARALLEL __gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom); #else @@ -225,6 +241,10 @@ void EdgeBasedGraphFactory::Run() { unsigned nameID = _nodeBasedGraph->GetEdgeData(e2).nameID; short turnInstruction = AnalyzeTurn(u, v, w); + if(_trafficLights.find(v) != _trafficLights.end()) { + distance += trafficSignalPenalty; + } + //create edge-based graph edge EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction); edgeBasedEdges.push_back(newEdge); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 9476a1cc0..4d457d71a 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -26,8 +26,13 @@ #define EDGEBASEDGRAPHFACTORY_H_ #include +#include +#include + #include +#include + #include "../typedefs.h" #include "../DataStructures/DynamicGraph.h" #include "../DataStructures/ExtractorStructs.h" @@ -35,6 +40,8 @@ #include "../DataStructures/ImportEdge.h" #include "../DataStructures/Percent.h" #include "../DataStructures/TurnInstructions.h" +#include "../Util/BaseConfiguration.h" + //#include "../Util/SRTMLookup.h" class EdgeBasedGraphFactory { @@ -82,12 +89,13 @@ public: }; private: - boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; - boost::unordered_map _barrierNodes; - boost::unordered_map _trafficLights; + boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; + boost::unordered_map _barrierNodes; + boost::unordered_map _trafficLights; std::vector<_Restriction> & inputRestrictions; - std::vector & inputNodeInfoList; + std::vector & inputNodeInfoList; + int trafficSignalPenalty; std::vector edgeBasedEdges; std::vector edgeBasedNodes; @@ -98,7 +106,7 @@ private: public: template< class InputEdgeT > - explicit EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & _bollardNodes, std::vector & trafficLights, 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, boost::property_tree::ptree speedProfile, std::string & srtm); virtual ~EdgeBasedGraphFactory(); void Run(); diff --git a/createHierarchy.cpp b/createHierarchy.cpp index 33eb762df..15df54150 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -29,6 +29,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #endif #include +#include +#include #include #include @@ -81,14 +83,6 @@ 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[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; @@ -118,7 +112,12 @@ int main (int argc, char *argv[]) { in.close(); INFO("Loaded " << inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); - EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternaleNodeMapping, SRTM_ROOT); + if(!testDataFile("speedprofile.ini")) { + ERR("Need speedprofile.ini to apply traffic signal penalty"); + } + boost::property_tree::ptree speedProfile; + boost::property_tree::ini_parser::read_ini("speedprofile.ini", speedProfile); + EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternaleNodeMapping, speedProfile, SRTM_ROOT); edgeList.clear(); std::vector().swap(edgeList);