Skip to content

Commit

Permalink
barrier=bollard is now used. Fixes ticket #9 and saves about .5% RAM in
Browse files Browse the repository at this point in the history
metropolitan areas
  • Loading branch information
DennisOSRM committed Jan 2, 2012
1 parent 057e3a9 commit 7025614
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 67 deletions.
16 changes: 15 additions & 1 deletion Contractor/EdgeBasedGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion Contractor/EdgeBasedGraphFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -82,6 +83,8 @@ class EdgeBasedGraphFactory {

private:
boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph;
HashTable<NodeID, bool> _bollardNodes;
HashTable<NodeID, bool> _trafficLights;

std::vector<_Restriction> & inputRestrictions;
std::vector<NodeInfo> & inputNodeInfoList;
Expand All @@ -95,7 +98,7 @@ class EdgeBasedGraphFactory {

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();
Expand Down
16 changes: 10 additions & 6 deletions DataStructures/ExtractorStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand All @@ -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;
};

Expand Down
7 changes: 7 additions & 0 deletions DataStructures/PBFParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion DataStructures/XMLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions Util/GraphLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
33 changes: 19 additions & 14 deletions createHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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);

Expand Down
31 changes: 17 additions & 14 deletions extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("")) {
Expand All @@ -118,28 +118,29 @@ 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;
} else {
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());
}
}
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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()) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 21 additions & 21 deletions speedprofile.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7025614

Please sign in to comment.