switch edge-expanded street name indexes to be first segment names (18 failed tests left)

This commit is contained in:
Dennis Luxen
2014-03-28 17:13:00 +01:00
parent 549bcb502b
commit 752fb880be
10 changed files with 202 additions and 77 deletions
+49 -31
View File
@@ -31,18 +31,18 @@ DescriptionFactory::DescriptionFactory() : entireLength(0) { }
DescriptionFactory::~DescriptionFactory() { }
inline double DescriptionFactory::DegreeToRadian(const double degree) const {
return degree * (M_PI/180);
inline double DescriptionFactory::DegreeToRadian(const double degree) const
{
return degree * (M_PI/180.);
}
inline double DescriptionFactory::RadianToDegree(const double radian) const {
return radian * (180/M_PI);
inline double DescriptionFactory::RadianToDegree(const double radian) const
{
return radian * (180./M_PI);
}
double DescriptionFactory::GetBearing(
const FixedPointCoordinate & A,
const FixedPointCoordinate & B
) const {
double DescriptionFactory::GetBearing(const FixedPointCoordinate & A, const FixedPointCoordinate & B) const
{
double delta_long = DegreeToRadian(B.lon/COORDINATE_PRECISION - A.lon/COORDINATE_PRECISION);
const double lat1 = DegreeToRadian(A.lat/COORDINATE_PRECISION);
@@ -51,24 +51,42 @@ double DescriptionFactory::GetBearing(
const double y = sin(delta_long) * cos(lat2);
const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long);
double result = RadianToDegree(atan2(y, x));
while(result < 0.) {
while (result < 0.)
{
result += 360.;
}
while(result >= 360.) {
while (result >= 360.)
{
result -= 360.;
}
return result;
}
void DescriptionFactory::SetStartSegment(const PhantomNode & start) {
start_phantom = start;
void DescriptionFactory::SetStartSegment(const PhantomNode & source, const bool source_traversed_in_reverse)
{
int fwd_weight = source.forward_weight;
int rev_weight = source.reverse_weight;
int fwd_offset = source.forward_offset;
int rev_offset = source.reverse_offset;
SimpleLogger().Write(logDEBUG) << "df source, traversed in reverse: " << (source_traversed_in_reverse ? "y" : "n") << ", location: " << source.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset;
SimpleLogger().Write(logDEBUG) << "duration of first segment: " << (source_traversed_in_reverse ? source.GetReverseWeightPlusOffset() : source.GetForwardWeightPlusOffset());
start_phantom = source;
AppendSegment(
start.location,
PathData(0, start.name_id, 10, start.forward_weight)
source.location,
PathData(0, source.name_id, 10, source.forward_weight)
);
}
void DescriptionFactory::SetEndSegment(const PhantomNode & target) {
void DescriptionFactory::SetEndSegment(const PhantomNode & target, const bool target_traversed_in_reverse)
{
int fwd_weight = target.forward_weight;
int rev_weight = target.reverse_weight;
int fwd_offset = target.forward_offset;
int rev_offset = target.reverse_offset;
SimpleLogger().Write(logDEBUG) << "df target, traversed in reverse: " << (target_traversed_in_reverse ? "y" : "n") << ", location: " << target.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset;
SimpleLogger().Write(logDEBUG) << "duration of last segment: " << (target_traversed_in_reverse ? target.GetReverseWeightPlusOffset() : target.GetForwardWeightPlusOffset());
target_phantom = target;
pathDescription.push_back(
SegmentInformation(
@@ -86,22 +104,22 @@ void DescriptionFactory::AppendSegment(
const FixedPointCoordinate & coordinate,
const PathData & data
) {
if(
( 1 == pathDescription.size()) &&
( pathDescription.back().location == coordinate)
) {
pathDescription.back().name_id = data.name_id;
} else {
pathDescription.push_back(
SegmentInformation(
coordinate,
data.name_id,
data.durationOfSegment,
0,
data.turnInstruction
)
);
}
// if(
// ( 1 == pathDescription.size()) &&
// ( pathDescription.back().location == coordinate)
// ) {
// pathDescription.back().name_id = data.name_id;
// } else {
pathDescription.push_back(
SegmentInformation(
coordinate,
data.name_id,
data.durationOfSegment,
0,
data.turnInstruction
)
);
// }
}
void DescriptionFactory::AppendEncodedPolylineString(
+8 -6
View File
@@ -87,8 +87,8 @@ public:
void AppendUnencodedPolylineString(std::vector<std::string> &output) const;
void AppendSegment(const FixedPointCoordinate & coordinate, const PathData & data);
void BuildRouteSummary(const double distance, const unsigned time);
void SetStartSegment(const PhantomNode & start_phantom);
void SetEndSegment(const PhantomNode & start_phantom);
void SetStartSegment(const PhantomNode & start_phantom, const bool source_traversed_in_reverse);
void SetEndSegment(const PhantomNode & start_phantom, const bool target_traversed_in_reverse);
void AppendEncodedPolylineString(
const bool return_encoded,
std::vector<std::string> & output
@@ -105,15 +105,17 @@ public:
/** starts at index 1 */
pathDescription[0].length = 0;
for(unsigned i = 1; i < pathDescription.size(); ++i)
for (unsigned i = 1; i < pathDescription.size(); ++i)
{
//move down names by one, q&d hack
pathDescription[i-1].name_id = pathDescription[i].name_id;
pathDescription[i].length = FixedPointCoordinate::ApproximateEuclideanDistance(pathDescription[i-1].location, pathDescription[i].location);
}
for (unsigned i = 0; i < pathDescription.size(); ++i)
{
const std::string name = facade->GetEscapedNameForNameID(pathDescription[0].name_id);
SimpleLogger().Write(logDEBUG) << "[" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location;
SimpleLogger().Write(logDEBUG) << "df [" << i << "] name: " << name << ", duration: " << pathDescription[i].duration << ", length: " << pathDescription[i].length << ", coordinate: " << pathDescription[i].location;
}
/*Simplify turn instructions
@@ -186,7 +188,7 @@ public:
target_phantom.name_id = (pathDescription.end()-2)->name_id;
}
} else {
pathDescription[segment_start_index].duration *= (1.-target_phantom.ratio);
// pathDescription[segment_start_index].duration *= (1.-target_phantom.ratio);
}
if(std::numeric_limits<double>::epsilon() > pathDescription[0].length) {
if(pathDescription.size() > 2) {
@@ -196,7 +198,7 @@ public:
start_phantom.name_id = pathDescription[0].name_id;
}
} else {
pathDescription[0].duration *= start_phantom.ratio;
// pathDescription[0].duration *= start_phantom.ratio;
}
//Generalize poly line
+86 -8
View File
@@ -99,7 +99,7 @@ public:
FixedPointCoordinate current_coordinate;
BOOST_FOREACH(const PathData & path_data, route_leg) {
current_coordinate = facade->GetCoordinateOfNode(path_data.node);
description_factory.AppendSegment(current_coordinate, path_data );
description_factory.AppendSegment(current_coordinate, path_data);
++added_element_count;
}
// description_factory.SetEndSegment( leg_phantoms.target_phantom );
@@ -120,7 +120,8 @@ public:
"{\"status\":"
);
if(INT_MAX == raw_route.lengthOfShortestPath) {
if (INVALID_EDGE_WEIGHT == raw_route.lengthOfShortestPath)
{
//We do not need to do much, if there is no route ;-)
reply.content.push_back(
"207,\"status_message\": \"Cannot find route between points\"}"
@@ -128,12 +129,87 @@ public:
return;
}
description_factory.SetStartSegment(phantom_nodes.source_phantom);
std::string name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id);
int fwd_weight = phantom_nodes.source_phantom.forward_weight;
int rev_weight = phantom_nodes.source_phantom.reverse_weight;
int fwd_offset = phantom_nodes.source_phantom.forward_offset;
int rev_offset = phantom_nodes.source_phantom.reverse_offset;
SimpleLogger().Write(logDEBUG) << "json source: " << name << ", location: " << phantom_nodes.source_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset;
name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id);
fwd_weight = phantom_nodes.target_phantom.forward_weight;
rev_weight = phantom_nodes.target_phantom.reverse_weight;
fwd_offset = phantom_nodes.target_phantom.forward_offset;
rev_offset = phantom_nodes.target_phantom.reverse_offset;
SimpleLogger().Write(logDEBUG) << "json target: " << name << ", location: " << phantom_nodes.target_phantom.location << ", fwd_weight: " << fwd_weight << ", fwd_offset: " << fwd_offset << ", rev_weight: " << rev_weight << ", rev_offset: " << rev_offset;
//TODO: replace the previous logic with this one.
//check if first segment is non-zero
std::string road_name;
int source_duration = phantom_nodes.source_phantom.GetForwardWeightPlusOffset();
SimpleLogger().Write(logDEBUG) << "-> source_traversed_in_reverse: " << (raw_route.source_traversed_in_reverse ? "y" : "n");
if (!raw_route.source_traversed_in_reverse)
{
source_duration = phantom_nodes.source_phantom.GetReverseWeightPlusOffset();
}
BOOST_ASSERT(source_duration >= 0);
road_name = facade->GetEscapedNameForNameID(phantom_nodes.source_phantom.name_id);
if (source_duration > 0)
{
SimpleLogger().Write(logDEBUG) << "adding source \"" << road_name << "\" at " << phantom_nodes.source_phantom.location << ", duration: " << source_duration;
}
else
{
SimpleLogger().Write(logDEBUG) << "ignoring source \"" << road_name << "\"";
}
// TODO, for each unpacked segment add the leg to the description
BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() );
for (unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i)
{
const std::vector<PathData> & leg_path = raw_route.unpacked_path_segments[i];
const PhantomNodes & leg_phantoms = raw_route.segmentEndCoordinates[i];
SimpleLogger().Write(logDEBUG) << " Describing leg from " << leg_phantoms.source_phantom.location << " and " << leg_phantoms.target_phantom.location;
FixedPointCoordinate current_coordinate;
BOOST_FOREACH(const PathData & path_data, leg_path)
{
current_coordinate = facade->GetCoordinateOfNode(path_data.node);
road_name = facade->GetEscapedNameForNameID(path_data.name_id);
SimpleLogger().Write(logDEBUG) << " adding way point for \"" << road_name << "\" at " << current_coordinate << ", duration: " << path_data.durationOfSegment;
}
}
//check if last segment is non-zero
road_name = facade->GetEscapedNameForNameID(phantom_nodes.target_phantom.name_id);
int target_duration = phantom_nodes.target_phantom.GetForwardWeightPlusOffset();
if (raw_route.target_traversed_in_reverse)
{
target_duration = phantom_nodes.target_phantom.GetReverseWeightPlusOffset();
}
BOOST_ASSERT(target_duration >= 0);
if (target_duration > 0)
{
SimpleLogger().Write(logDEBUG) << "adding target \"" << road_name << "\" at " << phantom_nodes.target_phantom.location << ", duration: " << target_duration;
}
else
{
SimpleLogger().Write(logDEBUG) << "ignoring target \"" << road_name << "\"";
}
SimpleLogger().Write(logDEBUG) << "-> target_traversed_in_reverse: " << (raw_route.target_traversed_in_reverse ? "y" : "n");
//END OF TODO
description_factory.SetStartSegment(phantom_nodes.source_phantom, raw_route.source_traversed_in_reverse);
reply.content.push_back("0,"
"\"status_message\": \"Found route between points\",");
BOOST_ASSERT( raw_route.unpacked_path_segments.size() == raw_route.segmentEndCoordinates.size() );
for( unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i ) {
for (unsigned i = 0; i < raw_route.unpacked_path_segments.size(); ++i)
{
const int added_segments = DescribeLeg(
raw_route.unpacked_path_segments[i],
raw_route.segmentEndCoordinates[i]
@@ -143,7 +219,7 @@ public:
added_segments + shortest_leg_end_indices.back()
);
}
description_factory.SetEndSegment(phantom_nodes.target_phantom);
description_factory.SetEndSegment(phantom_nodes.target_phantom, raw_route.target_traversed_in_reverse);
description_factory.Run(facade, config.zoom_level);
reply.content.push_back("\"route_geometry\": ");
@@ -195,14 +271,16 @@ public:
//only one alternative route is computed at this time, so this is hardcoded
if(raw_route.lengthOfAlternativePath != INT_MAX) {
alternate_descriptionFactory.SetStartSegment(phantom_nodes.source_phantom);
if(raw_route.lengthOfAlternativePath != INVALID_EDGE_WEIGHT)
{
alternate_descriptionFactory.SetStartSegment(phantom_nodes.source_phantom, raw_route.alt_source_traversed_in_reverse);
//Get all the coordinates for the computed route
BOOST_FOREACH(const PathData & path_data, raw_route.unpacked_alternative) {
current = facade->GetCoordinateOfNode(path_data.node);
alternate_descriptionFactory.AppendSegment(current, path_data );
}
alternate_descriptionFactory.SetEndSegment(phantom_nodes.target_phantom);
alternate_descriptionFactory.SetEndSegment(phantom_nodes.target_phantom, raw_route.alt_target_traversed_in_reverse);
}
alternate_descriptionFactory.Run(facade, config.zoom_level);