traffic signal penalty gets incorporated now into routing data.

This commit is contained in:
DennisOSRM 2012-02-28 16:25:01 +01:00
parent 8d83ce47e9
commit 300f7370c8
3 changed files with 42 additions and 15 deletions

View File

@ -24,14 +24,30 @@
#include <algorithm> #include <algorithm>
#endif #endif
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include "../Util/OpenMPReplacement.h" #include "../Util/OpenMPReplacement.h"
#include "EdgeBasedGraphFactory.h" #include "EdgeBasedGraphFactory.h"
template<> template<>
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) EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdge> & inputEdges, std::vector<NodeID> & bn, std::vector<NodeID> & tl, std::vector<_Restriction> & irs, std::vector<NodeInfo> & nI, boost::property_tree::ptree speedProfile, std::string & srtm)
: inputRestrictions(irs), inputNodeInfoList(nI)/*, srtmLookup(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<std::string>("");
try {
trafficSignalPenalty = 10*boost::lexical_cast<int>(v.second.get<std::string>(""));
} catch(boost::bad_lexical_cast &) {
trafficSignalPenalty = 0;
}
}
}
INFO("Using traffic signal penalty: " << trafficSignalPenalty );
#ifdef _GLIBCXX_PARALLEL #ifdef _GLIBCXX_PARALLEL
__gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom); __gnu_parallel::sort(inputRestrictions.begin(), inputRestrictions.end(), CmpRestrictionByFrom);
#else #else
@ -225,6 +241,10 @@ void EdgeBasedGraphFactory::Run() {
unsigned nameID = _nodeBasedGraph->GetEdgeData(e2).nameID; unsigned nameID = _nodeBasedGraph->GetEdgeData(e2).nameID;
short turnInstruction = AnalyzeTurn(u, v, w); short turnInstruction = AnalyzeTurn(u, v, w);
if(_trafficLights.find(v) != _trafficLights.end()) {
distance += trafficSignalPenalty;
}
//create edge-based graph edge //create edge-based graph edge
EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction); EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction);
edgeBasedEdges.push_back(newEdge); edgeBasedEdges.push_back(newEdge);

View File

@ -26,8 +26,13 @@
#define EDGEBASEDGRAPHFACTORY_H_ #define EDGEBASEDGRAPHFACTORY_H_
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <vector> #include <vector>
#include <cstdlib>
#include "../typedefs.h" #include "../typedefs.h"
#include "../DataStructures/DynamicGraph.h" #include "../DataStructures/DynamicGraph.h"
#include "../DataStructures/ExtractorStructs.h" #include "../DataStructures/ExtractorStructs.h"
@ -35,6 +40,8 @@
#include "../DataStructures/ImportEdge.h" #include "../DataStructures/ImportEdge.h"
#include "../DataStructures/Percent.h" #include "../DataStructures/Percent.h"
#include "../DataStructures/TurnInstructions.h" #include "../DataStructures/TurnInstructions.h"
#include "../Util/BaseConfiguration.h"
//#include "../Util/SRTMLookup.h" //#include "../Util/SRTMLookup.h"
class EdgeBasedGraphFactory { class EdgeBasedGraphFactory {
@ -82,12 +89,13 @@ public:
}; };
private: private:
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
boost::unordered_map<NodeID, bool> _barrierNodes; boost::unordered_map<NodeID, bool> _barrierNodes;
boost::unordered_map<NodeID, bool> _trafficLights; boost::unordered_map<NodeID, bool> _trafficLights;
std::vector<_Restriction> & inputRestrictions; std::vector<_Restriction> & inputRestrictions;
std::vector<NodeInfo> & inputNodeInfoList; std::vector<NodeInfo> & inputNodeInfoList;
int trafficSignalPenalty;
std::vector<EdgeBasedEdge> edgeBasedEdges; std::vector<EdgeBasedEdge> edgeBasedEdges;
std::vector<EdgeBasedNode> edgeBasedNodes; std::vector<EdgeBasedNode> edgeBasedNodes;
@ -98,7 +106,7 @@ private:
public: public:
template< class InputEdgeT > template< class InputEdgeT >
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); explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<NodeID> & _bollardNodes, std::vector<NodeID> & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, boost::property_tree::ptree speedProfile, std::string & srtm);
virtual ~EdgeBasedGraphFactory(); virtual ~EdgeBasedGraphFactory();
void Run(); void Run();

View File

@ -29,6 +29,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
#endif #endif
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <fstream> #include <fstream>
#include <istream> #include <istream>
@ -81,14 +83,6 @@ 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[2] << " using STL "
#ifdef _GLIBCXX_PARALLEL
"parallel (GCC)"
#else
"serial"
#endif
" mode");
INFO("Using restrictions from file: " << argv[2]); INFO("Using restrictions from file: " << argv[2]);
std::ifstream restrictionsInstream(argv[2], ios::binary); std::ifstream restrictionsInstream(argv[2], ios::binary);
_Restriction restriction; _Restriction restriction;
@ -118,7 +112,12 @@ int main (int argc, char *argv[]) {
in.close(); in.close();
INFO("Loaded " << inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); 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(); edgeList.clear();
std::vector<ImportEdge>().swap(edgeList); std::vector<ImportEdge>().swap(edgeList);