minor code refactoring, wip

This commit is contained in:
Dennis Luxen 2014-05-18 22:44:19 +02:00
parent a122a1e8c7
commit 75a2d4d00a
12 changed files with 315 additions and 324 deletions

View File

@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "PolylineCompressor.h" #include "PolylineCompressor.h"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
//TODO: return vector of start indices for each leg
void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std::string &output) void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std::string &output)
const const
{ {

View File

@ -339,14 +339,17 @@ class TarjanSCC
<< " many components, marking small components"; << " many components, marking small components";
// TODO/C++11: prime candidate for lambda function // TODO/C++11: prime candidate for lambda function
unsigned size_one_counter = 0; // unsigned size_one_counter = 0;
for (unsigned i = 0, end = component_size_vector.size(); i < end; ++i) // for (unsigned i = 0, end = component_size_vector.size(); i < end; ++i)
{ // {
if (1 == component_size_vector[i]) // if (1 == component_size_vector[i])
{ // {
++size_one_counter; // ++size_one_counter;
} // }
} // }
unsigned size_one_counter = std::count_if(component_size_vector.begin(),
component_size_vector.end(),
[] (unsigned value) { return 1 == value;});
SimpleLogger().Write() << "identified " << size_one_counter << " SCCs of size 1"; SimpleLogger().Write() << "identified " << size_one_counter << " SCCs of size 1";

View File

@ -29,8 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
DescriptionFactory::DescriptionFactory() : entireLength(0) {} DescriptionFactory::DescriptionFactory() : entireLength(0) {}
DescriptionFactory::~DescriptionFactory() {}
void DescriptionFactory::SetStartSegment(const PhantomNode &source) void DescriptionFactory::SetStartSegment(const PhantomNode &source)
{ {
start_phantom = source; start_phantom = source;
@ -50,15 +48,14 @@ void DescriptionFactory::AppendSegment(const FixedPointCoordinate &coordinate,
if ((1 == path_description.size()) && (path_description.back().location == coordinate)) if ((1 == path_description.size()) && (path_description.back().location == coordinate))
{ {
path_description.back().name_id = path_point.name_id; path_description.back().name_id = path_point.name_id;
return;
} }
else
{ path_description.emplace_back(coordinate,
path_description.emplace_back(coordinate, path_point.name_id,
path_point.name_id, path_point.segment_duration,
path_point.segment_duration, 0,
0, path_point.turn_instruction);
path_point.turn_instruction);
}
} }
JSON::Value DescriptionFactory::AppendEncodedPolylineString(const bool return_encoded) JSON::Value DescriptionFactory::AppendEncodedPolylineString(const bool return_encoded)

View File

@ -76,7 +76,6 @@ class DescriptionFactory
// I know, declaring this public is considered bad. I'm lazy // I know, declaring this public is considered bad. I'm lazy
std::vector<SegmentInformation> path_description; std::vector<SegmentInformation> path_description;
DescriptionFactory(); DescriptionFactory();
virtual ~DescriptionFactory();
JSON::Value AppendUnencodedPolylineString() const; JSON::Value AppendUnencodedPolylineString() const;
void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &data); void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &data);
void BuildRouteSummary(const double distance, const unsigned time); void BuildRouteSummary(const double distance, const unsigned time);
@ -176,14 +175,14 @@ class DescriptionFactory
target_phantom.name_id = (path_description.end() - 2)->name_id; target_phantom.name_id = (path_description.end() - 2)->name_id;
} }
} }
if (std::numeric_limits<double>::epsilon() > path_description[0].length) if (std::numeric_limits<double>::epsilon() > path_description.front().length)
{ {
if (path_description.size() > 2) if (path_description.size() > 2)
{ {
path_description.erase(path_description.begin()); path_description.erase(path_description.begin());
path_description[0].turn_instruction = TurnInstruction::HeadOn; path_description.front().turn_instruction = TurnInstruction::HeadOn;
path_description[0].necessary = true; path_description.front().necessary = true;
start_phantom.name_id = path_description[0].name_id; start_phantom.name_id = path_description.front().name_id;
} }
} }

View File

@ -217,14 +217,15 @@ void ExtractionContainers::PrepareData(const std::string &output_file_name,
restrictions_out_stream.open(restrictions_file_name.c_str(), std::ios::binary); restrictions_out_stream.open(restrictions_file_name.c_str(), std::ios::binary);
restrictions_out_stream.write((char *)&uuid, sizeof(UUID)); restrictions_out_stream.write((char *)&uuid, sizeof(UUID));
restrictions_out_stream.write((char *)&number_of_useable_restrictions, sizeof(unsigned)); restrictions_out_stream.write((char *)&number_of_useable_restrictions, sizeof(unsigned));
for (restrictions_iterator = restrictions_list.begin(); // for (restrictions_iterator = restrictions_list.begin();
restrictions_iterator != restrictions_list.end(); // restrictions_iterator != restrictions_list.end();
++restrictions_iterator) // ++restrictions_iterator)
for(const auto & restriction_container : restrictions_list)
{ {
if (std::numeric_limits<unsigned>::max() != restrictions_iterator->restriction.fromNode && if (std::numeric_limits<unsigned>::max() != restriction_container.restriction.fromNode &&
std::numeric_limits<unsigned>::max() != restrictions_iterator->restriction.toNode) std::numeric_limits<unsigned>::max() != restriction_container.restriction.toNode)
{ {
restrictions_out_stream.write((char *)&(restrictions_iterator->restriction), restrictions_out_stream.write((char *)&(restriction_container.restriction),
sizeof(TurnRestriction)); sizeof(TurnRestriction));
} }
} }

View File

@ -63,102 +63,104 @@ bool ExtractorCallbacks::ProcessRestriction(const InputRestrictionContainer &res
/** warning: caller needs to take care of synchronization! */ /** warning: caller needs to take care of synchronization! */
void ExtractorCallbacks::ProcessWay(ExtractionWay &parsed_way) void ExtractorCallbacks::ProcessWay(ExtractionWay &parsed_way)
{ {
if ((0 < parsed_way.speed) || (0 < parsed_way.duration)) if ((0 >= parsed_way.speed) && (0 >= parsed_way.duration))
{ // Only true if the way is specified by the speed profile { // Only true if the way is specified by the speed profile
if (std::numeric_limits<unsigned>::max() == parsed_way.id) return;
{ }
SimpleLogger().Write(logDEBUG) << "found bogus way with id: " << parsed_way.id
<< " of size " << parsed_way.path.size();
return;
}
if (0 < parsed_way.duration) if (std::numeric_limits<unsigned>::max() == parsed_way.id)
{ {
// TODO: iterate all way segments and set duration corresponding to the length of each SimpleLogger().Write(logDEBUG) << "found bogus way with id: " << parsed_way.id
// segment << " of size " << parsed_way.path.size();
parsed_way.speed = parsed_way.duration / (parsed_way.path.size() - 1); return;
} }
if (std::numeric_limits<double>::epsilon() >= std::abs(-1. - parsed_way.speed)) if (0 < parsed_way.duration)
{ {
SimpleLogger().Write(logDEBUG) << "found way with bogus speed, id: " << parsed_way.id; // TODO: iterate all way segments and set duration corresponding to the length of each
return; // segment
} parsed_way.speed = parsed_way.duration / (parsed_way.path.size() - 1);
}
// Get the unique identifier for the street name if (std::numeric_limits<double>::epsilon() >= std::abs(-1. - parsed_way.speed))
const auto &string_map_iterator = string_map.find(parsed_way.name); {
if (string_map.end() == string_map_iterator) SimpleLogger().Write(logDEBUG) << "found way with bogus speed, id: " << parsed_way.id;
{ return;
parsed_way.nameID = external_memory.name_list.size(); }
external_memory.name_list.push_back(parsed_way.name);
string_map.insert(std::make_pair(parsed_way.name, parsed_way.nameID));
}
else
{
parsed_way.nameID = string_map_iterator->second;
}
if (ExtractionWay::opposite == parsed_way.direction) // Get the unique identifier for the street name
const auto &string_map_iterator = string_map.find(parsed_way.name);
if (string_map.end() == string_map_iterator)
{
parsed_way.nameID = external_memory.name_list.size();
external_memory.name_list.push_back(parsed_way.name);
string_map.insert(std::make_pair(parsed_way.name, parsed_way.nameID));
}
else
{
parsed_way.nameID = string_map_iterator->second;
}
if (ExtractionWay::opposite == parsed_way.direction)
{
std::reverse(parsed_way.path.begin(), parsed_way.path.end());
parsed_way.direction = ExtractionWay::oneway;
}
const bool split_bidirectional_edge =
(parsed_way.backward_speed > 0) && (parsed_way.speed != parsed_way.backward_speed);
for (unsigned n = 0; n < parsed_way.path.size() - 1; ++n)
{
external_memory.all_edges_list.push_back(InternalExtractorEdge(
parsed_way.path[n],
parsed_way.path[n + 1],
parsed_way.type,
(split_bidirectional_edge ? ExtractionWay::oneway : parsed_way.direction),
parsed_way.speed,
parsed_way.nameID,
parsed_way.roundabout,
parsed_way.ignoreInGrid,
(0 < parsed_way.duration),
parsed_way.isAccessRestricted,
false,
split_bidirectional_edge));
external_memory.used_node_id_list.push_back(parsed_way.path[n]);
}
external_memory.used_node_id_list.push_back(parsed_way.path.back());
// The following information is needed to identify start and end segments of restrictions
external_memory.way_start_end_id_list.push_back(
WayIDStartAndEndEdge(parsed_way.id,
parsed_way.path[0],
parsed_way.path[1],
parsed_way.path[parsed_way.path.size() - 2],
parsed_way.path.back()));
if (split_bidirectional_edge)
{ // Only true if the way should be split
std::reverse(parsed_way.path.begin(), parsed_way.path.end());
for (std::vector<NodeID>::size_type n = 0; n < parsed_way.path.size() - 1; ++n)
{ {
std::reverse(parsed_way.path.begin(), parsed_way.path.end()); external_memory.all_edges_list.push_back(
parsed_way.direction = ExtractionWay::oneway; InternalExtractorEdge(parsed_way.path[n],
parsed_way.path[n + 1],
parsed_way.type,
ExtractionWay::oneway,
parsed_way.backward_speed,
parsed_way.nameID,
parsed_way.roundabout,
parsed_way.ignoreInGrid,
(0 < parsed_way.duration),
parsed_way.isAccessRestricted,
(ExtractionWay::oneway == parsed_way.direction),
split_bidirectional_edge));
} }
const bool split_bidirectional_edge =
(parsed_way.backward_speed > 0) && (parsed_way.speed != parsed_way.backward_speed);
for (unsigned n = 0; n < parsed_way.path.size() - 1; ++n)
{
external_memory.all_edges_list.push_back(InternalExtractorEdge(
parsed_way.path[n],
parsed_way.path[n + 1],
parsed_way.type,
(split_bidirectional_edge ? ExtractionWay::oneway : parsed_way.direction),
parsed_way.speed,
parsed_way.nameID,
parsed_way.roundabout,
parsed_way.ignoreInGrid,
(0 < parsed_way.duration),
parsed_way.isAccessRestricted,
false,
split_bidirectional_edge));
external_memory.used_node_id_list.push_back(parsed_way.path[n]);
}
external_memory.used_node_id_list.push_back(parsed_way.path.back());
// The following information is needed to identify start and end segments of restrictions
external_memory.way_start_end_id_list.push_back( external_memory.way_start_end_id_list.push_back(
WayIDStartAndEndEdge(parsed_way.id, WayIDStartAndEndEdge(parsed_way.id,
parsed_way.path[0], parsed_way.path[0],
parsed_way.path[1], parsed_way.path[1],
parsed_way.path[parsed_way.path.size() - 2], parsed_way.path[parsed_way.path.size() - 2],
parsed_way.path.back())); parsed_way.path.back()));
if (split_bidirectional_edge)
{ // Only true if the way should be split
std::reverse(parsed_way.path.begin(), parsed_way.path.end());
for (std::vector<NodeID>::size_type n = 0; n < parsed_way.path.size() - 1; ++n)
{
external_memory.all_edges_list.push_back(
InternalExtractorEdge(parsed_way.path[n],
parsed_way.path[n + 1],
parsed_way.type,
ExtractionWay::oneway,
parsed_way.backward_speed,
parsed_way.nameID,
parsed_way.roundabout,
parsed_way.ignoreInGrid,
(0 < parsed_way.duration),
parsed_way.isAccessRestricted,
(ExtractionWay::oneway == parsed_way.direction),
split_bidirectional_edge));
}
external_memory.way_start_end_id_list.push_back(
WayIDStartAndEndEdge(parsed_way.id,
parsed_way.path[0],
parsed_way.path[1],
parsed_way.path[parsed_way.path.size() - 2],
parsed_way.path.back()));
}
} }
} }

View File

@ -44,13 +44,8 @@ template <class DataFacadeT> class LocatePlugin : public BasePlugin
void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply) void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply)
{ {
// check number of parameters // check number of parameters
if (route_parameters.coordinates.empty()) if (route_parameters.coordinates.empty() ||
{ !route_parameters.coordinates.front().isValid())
reply = http::Reply::StockReply(http::Reply::badRequest);
return;
}
// check if queried location is sane
if (!route_parameters.coordinates.front().isValid())
{ {
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;

View File

@ -51,13 +51,8 @@ template <class DataFacadeT> class NearestPlugin : public BasePlugin
void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply) void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply)
{ {
// check number of parameters // check number of parameters
if (route_parameters.coordinates.empty()) if (route_parameters.coordinates.empty() ||
{ !route_parameters.coordinates.front().isValid())
reply = http::Reply::StockReply(http::Reply::badRequest);
return;
}
// check if queried location is sane
if (!route_parameters.coordinates.front().isValid())
{ {
reply = http::Reply::StockReply(http::Reply::badRequest); reply = http::Reply::StockReply(http::Reply::badRequest);
return; return;

View File

@ -72,16 +72,8 @@ template <class DataFacadeT> class ViaRoutePlugin : public BasePlugin
void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply) void HandleRequest(const RouteParameters &route_parameters, http::Reply &reply)
{ {
// check number of parameters // check number of parameters
if (2 > route_parameters.coordinates.size()) if (2 > route_parameters.coordinates.size() ||
{ std::any_of(begin(route_parameters.coordinates),
reply = http::Reply::StockReply(http::Reply::badRequest);
return;
}
RawRouteData raw_route;
raw_route.check_sum = facade->GetCheckSum();
if (std::any_of(begin(route_parameters.coordinates),
end(route_parameters.coordinates), end(route_parameters.coordinates),
[&](FixedPointCoordinate coordinate) [&](FixedPointCoordinate coordinate)
{ return !coordinate.isValid(); })) { return !coordinate.isValid(); }))
@ -90,6 +82,8 @@ template <class DataFacadeT> class ViaRoutePlugin : public BasePlugin
return; return;
} }
RawRouteData raw_route;
raw_route.check_sum = facade->GetCheckSum();
for (const FixedPointCoordinate &coordinate : route_parameters.coordinates) for (const FixedPointCoordinate &coordinate : route_parameters.coordinates)
{ {
raw_route.raw_via_node_coordinates.emplace_back(coordinate); raw_route.raw_via_node_coordinates.emplace_back(coordinate);

View File

@ -51,14 +51,15 @@ template <class DataFacadeT> class ShortestPathRouting : public BasicRoutingInte
void operator()(const std::vector<PhantomNodes> &phantom_nodes_vector, void operator()(const std::vector<PhantomNodes> &phantom_nodes_vector,
RawRouteData &raw_route_data) const RawRouteData &raw_route_data) const
{ {
for (const PhantomNodes &phantom_node_pair : phantom_nodes_vector) if(std::any_of(begin(phantom_nodes_vector),
end(phantom_nodes_vector),
[](PhantomNodes phantom_node_pair)
{ return phantom_node_pair.AtLeastOnePhantomNodeIsInvalid(); }))
{ {
if (phantom_node_pair.AtLeastOnePhantomNodeIsInvalid()) BOOST_ASSERT(false);
{ return;
BOOST_ASSERT(false);
return;
}
} }
int distance1 = 0; int distance1 = 0;
int distance2 = 0; int distance2 = 0;
bool search_from_1st_node = true; bool search_from_1st_node = true;

View File

@ -262,10 +262,10 @@ RequestParser::consume(Request &req, char input, http::CompressionType *compress
return boost::indeterminate; return boost::indeterminate;
} }
return false; return false;
case expecting_newline_3: default: // expecting_newline_3:
return (input == '\n'); return (input == '\n');
default: // default:
return false; // return false;
} }
} }

View File

@ -438,6 +438,7 @@ int main(int argc, char *argv[])
// every target needs to be valid // every target needs to be valid
BOOST_ASSERT(current_edge.target < max_used_node_id); BOOST_ASSERT(current_edge.target < max_used_node_id);
#ifndef NDEBUG
if (current_edge.data.distance <= 0) if (current_edge.data.distance <= 0)
{ {
SimpleLogger().Write(logWARNING) SimpleLogger().Write(logWARNING)
@ -450,6 +451,7 @@ int main(int argc, char *argv[])
<< node_array.size() - 1; << node_array.size() - 1;
return 1; return 1;
} }
#endif
hsgr_output_stream.write((char *)&current_edge, hsgr_output_stream.write((char *)&current_edge,
sizeof(StaticGraph<EdgeData>::EdgeArrayEntry)); sizeof(StaticGraph<EdgeData>::EdgeArrayEntry));
++number_of_used_edges; ++number_of_used_edges;