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"
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) */{
#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);

View File

@ -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 @@ public:
private:
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
HashTable<NodeID, bool> _bollardNodes;
HashTable<NodeID, bool> _trafficLights;
std::vector<_Restriction> & inputRestrictions;
std::vector<NodeInfo> & inputNodeInfoList;
@ -95,7 +98,7 @@ private:
public:
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();
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;
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<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 {
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;
};

View File

@ -219,6 +219,13 @@ private:
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;
}

View File

@ -253,7 +253,12 @@ private:
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;
}
}
}

View File

@ -96,21 +96,24 @@ NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
return n;
}
template<typename EdgeT>
NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap, vector<_Restriction> & inputRestrictions) {
NodeID n, source, target, id;
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;
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; i<n; ++i) {
in.read((char*)&id, sizeof(unsigned));
in.read((char*)&ycoord, sizeof(int));
in.read((char*)&xcoord, sizeof(int));
int2ExtNodeMap->push_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) {

View File

@ -58,22 +58,13 @@ typedef BaseConfiguration ContractorConfiguration;
std::vector<NodeInfo> internalToExternaleNodeMapping;
std::vector<_Restriction> inputRestrictions;
std::vector<NodeID> bollardNodes;
std::vector<NodeID> trafficLightNodes;
int main (int argc, char *argv[]) {
if(argc < 3) {
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();
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<ImportEdge> 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<ImportEdge>().swap(edgeList);

View File

@ -100,7 +100,7 @@ int main (int argc, char *argv[]) {
boost::property_tree::ptree pt;
try {
INFO("Loading speed profiles")
INFO("Loading speed profiles");
boost::property_tree::ini_parser::read_ini("speedprofile.ini", pt);
INFO("Found the following speed profiles: ");
int profileCounter(0);
@ -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;