duration tags on ferry ways get parsed now. Cheers to Mackerski!

This commit is contained in:
DennisOSRM 2012-03-15 16:39:35 +01:00
parent 64ab2da43b
commit 75353852fd
3 changed files with 48 additions and 16 deletions

View File

@ -21,6 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef EXTRACTORCALLBACKS_H_
#define EXTRACTORCALLBACKS_H_
#include <boost/algorithm/string/regex.hpp>
#include <boost/regex.hpp>
#include <stxxl.h>
#include <vector>
#include "ExtractorStructs.h"
@ -64,6 +67,24 @@ private:
StringMap * stringMap;
STXXLContainers * externalMemory;
struct DurationContainer {
int hours;
int minutes;
};
bool checkForValidTiming(const std::string &s, DurationContainer & duration) const {
boost::regex e ("((\\d|\\d\\d):)*(\\d|\\d\\d)",boost::regex_constants::icase|boost::regex_constants::perl);
std::vector< std::string > result;
boost::algorithm::split_regex( result, s, boost::regex( ":" ) ) ;
bool matched = regex_match(s, e);
if(matched) {
duration.hours = (result.size()== 2) ? atoi(result[0].c_str()) : 0;
duration.minutes = (result.size()== 2) ? atoi(result[1].c_str()) : atoi(result[0].c_str());
}
return matched;
}
public:
ExtractorCallbacks(STXXLContainers * ext, Settings set, StringMap * strMap) {
externalMemory = ext;
@ -122,6 +143,7 @@ public:
std::string oneway( w.keyVals.Find("oneway"));
std::string onewayClass( w.keyVals.Find("oneway:"+settings.accessTag));
std::string cycleway( w.keyVals.Find("cycleway"));
std::string duration ( w.keyVals.Find("duration"));
//Save the name of the way if it has one, ref has precedence over name tag.
if ( 0 < ref.length() )
@ -137,7 +159,13 @@ public:
//Is the route tag listed as usable way in the profile?
if(settings[route] > 0 || settings[man_made] > 0) {
w.useful = true;
w.speed = settings[route];
DurationContainer dc;
if(checkForValidTiming(duration, dc)){
w.speed = (600*(dc.hours*60+dc.minutes))/std::max((unsigned)(w.path.size()-1),1u);
w.isDurationSet = true;
} else {
w.speed = settings[route];
}
w.direction = _Way::bidirectional;
if(0 < settings[route])
highway = route;
@ -148,15 +176,16 @@ public:
//Is the highway tag listed as usable way?
if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) {
if(0 < settings[highway]) {
if(0 < maxspeed)
w.speed = std::min(maxspeed, settings[highway]);
else
w.speed = settings[highway];
} else {
w.speed = settings.defaultSpeed;
highway = "default";
if(!w.isDurationSet) {
if(0 < settings[highway]) {
if(0 < maxspeed)
w.speed = std::min(maxspeed, settings[highway]);
else
w.speed = settings[highway];
} else {
w.speed = settings.defaultSpeed;
highway = "default";
}
}
w.useful = true;
@ -225,7 +254,7 @@ public:
}
for(vector< NodeID >::size_type n = 0; n < w.path.size()-1; ++n) {
externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout, highway == settings.excludeFromGrid));
externalMemory->allEdges.push_back(_Edge(w.path[n], w.path[n+1], w.type, w.direction, w.speed, w.nameID, w.roundabout, highway == settings.excludeFromGrid, w.isDurationSet));
externalMemory->usedNodeIDs.push_back(w.path[n]);
}
externalMemory->usedNodeIDs.push_back(w.path[w.path.size()-1]);

View File

@ -91,6 +91,7 @@ struct _Way {
useful = false;
access = true;
roundabout = false;
isDurationSet = false;
}
enum {
@ -104,6 +105,7 @@ struct _Way {
bool useful;
bool access;
bool roundabout;
bool isDurationSet;
std::vector< NodeID > path;
HashTable<std::string, std::string> keyVals;
};
@ -137,10 +139,10 @@ struct _Relation {
};
struct _Edge {
_Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) {};
_Edge() : start(0), target(0), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false), isDurationSet(false) {};
_Edge(NodeID s, NodeID t) : start(s), target(t), type(0), direction(0), speed(0), nameID(0), isRoundabout(false), ignoreInGrid(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra, bool iing): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing) {
_Edge(NodeID s, NodeID t, short tp, short d, double sp): start(s), target(t), type(tp), direction(d), speed(sp), nameID(0), isRoundabout(false), ignoreInGrid(false), isDurationSet(false) { }
_Edge(NodeID s, NodeID t, short tp, short d, double sp, unsigned nid, bool isra, bool iing, bool ids): start(s), target(t), type(tp), direction(d), speed(sp), nameID(nid), isRoundabout(isra), ignoreInGrid(iing), isDurationSet(ids) {
assert(0 <= type);
}
NodeID start;
@ -151,6 +153,7 @@ struct _Edge {
unsigned nameID;
bool isRoundabout;
bool ignoreInGrid;
bool isDurationSet;
_Coordinate startCoord;
_Coordinate targetCoord;

View File

@ -408,8 +408,8 @@ int main (int argc, char *argv[]) {
double distance = ApproximateDistance(edgeIT->startCoord.lat, edgeIT->startCoord.lon, nodesIT->lat, nodesIT->lon);
assert(edgeIT->speed != -1);
double weight = ( distance * 10. ) / (edgeIT->speed / 3.6);
int intWeight = max(1, (int) weight);
int intDist = max(1, (int)distance);
int intWeight = std::max(1, (int)(edgeIT->isDurationSet ? edgeIT->speed : weight) );
int intDist = std::max(1, (int)distance);
short zero = 0;
short one = 1;