Implement re-enabling of PhantomNode directions after bearing filtering

This commit is contained in:
Patrick Niklaus
2016-03-28 17:06:51 +02:00
parent 5829bbe22d
commit fda4656630
16 changed files with 302 additions and 280 deletions
+10 -10
View File
@@ -56,10 +56,10 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
candidates.begin(), candidates.end(),
[](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs)
{
return lhs.phantom_node.forward_node_id < rhs.phantom_node.forward_node_id ||
(lhs.phantom_node.forward_node_id == rhs.phantom_node.forward_node_id &&
(lhs.phantom_node.reverse_node_id < rhs.phantom_node.reverse_node_id ||
(lhs.phantom_node.reverse_node_id == rhs.phantom_node.reverse_node_id &&
return lhs.phantom_node.forward_segment_id.id < rhs.phantom_node.forward_segment_id.id ||
(lhs.phantom_node.forward_segment_id.id == rhs.phantom_node.forward_segment_id.id &&
(lhs.phantom_node.reverse_segment_id.id < rhs.phantom_node.reverse_segment_id.id ||
(lhs.phantom_node.reverse_segment_id.id == rhs.phantom_node.reverse_segment_id.id &&
lhs.distance < rhs.distance)));
});
@@ -67,8 +67,8 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
candidates.begin(), candidates.end(),
[](const PhantomNodeWithDistance &lhs, const PhantomNodeWithDistance &rhs)
{
return lhs.phantom_node.forward_node_id == rhs.phantom_node.forward_node_id &&
lhs.phantom_node.reverse_node_id == rhs.phantom_node.reverse_node_id;
return lhs.phantom_node.forward_segment_id.id == rhs.phantom_node.forward_segment_id.id &&
lhs.phantom_node.reverse_segment_id.id == rhs.phantom_node.reverse_segment_id.id;
});
candidates.resize(new_end - candidates.begin());
@@ -78,15 +78,15 @@ void filterCandidates(const std::vector<util::Coordinate> &coordinates,
for (const auto i : util::irange<std::size_t>(0, compact_size))
{
// Split edge if it is bidirectional and append reverse direction to end of list
if (candidates[i].phantom_node.forward_node_id != SPECIAL_NODEID &&
candidates[i].phantom_node.reverse_node_id != SPECIAL_NODEID)
if (candidates[i].phantom_node.forward_segment_id.enabled &&
candidates[i].phantom_node.reverse_segment_id.enabled)
{
PhantomNode reverse_node(candidates[i].phantom_node);
reverse_node.forward_node_id = SPECIAL_NODEID;
reverse_node.forward_segment_id.enabled = false;
candidates.push_back(
PhantomNodeWithDistance{reverse_node, candidates[i].distance});
candidates[i].phantom_node.reverse_node_id = SPECIAL_NODEID;
candidates[i].phantom_node.reverse_segment_id.enabled = false;
}
}
}
+2 -2
View File
@@ -364,7 +364,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
};
// If this is a valid forward edge, go ahead and add it to the tile
if (forward_weight != 0 && edge.forward_edge_based_node_id != SPECIAL_NODEID)
if (forward_weight != 0 && edge.forward_segment_id.enabled)
{
std::int32_t start_x = 0;
std::int32_t start_y = 0;
@@ -383,7 +383,7 @@ Status TilePlugin::HandleRequest(const api::TileParameters &parameters, std::str
// Repeat the above for the coordinates reversed and using the `reverse`
// properties
if (reverse_weight != 0 && edge.reverse_edge_based_node_id != SPECIAL_NODEID)
if (reverse_weight != 0 && edge.reverse_segment_id.enabled)
{
std::int32_t start_x = 0;
std::int32_t start_y = 0;
+18 -5
View File
@@ -50,20 +50,33 @@ Status ViaRoutePlugin::HandleRequest(const api::RouteParameters &route_parameter
auto phantom_node_pairs = GetPhantomNodes(route_parameters);
if (phantom_node_pairs.size() != route_parameters.coordinates.size())
{
return Error("NoSegment",
std::string("Could not find a matching segment for coordinate ") +
std::to_string(phantom_node_pairs.size()),
return Error("NoSegment", std::string("Could not find a matching segment for coordinate ") +
std::to_string(phantom_node_pairs.size()),
json_result);
}
BOOST_ASSERT(phantom_node_pairs.size() == route_parameters.coordinates.size());
auto snapped_phantoms = SnapPhantomNodes(phantom_node_pairs);
const bool allow_u_turn_at_via =
route_parameters.uturns ? *route_parameters.uturns : facade.GetUTurnsDefault();
InternalRouteResult raw_route;
auto build_phantom_pairs = [&raw_route](const PhantomNode &first_node,
const PhantomNode &second_node)
auto build_phantom_pairs = [&raw_route, allow_u_turn_at_via](const PhantomNode &first_node,
const PhantomNode &second_node)
{
raw_route.segment_end_coordinates.push_back(PhantomNodes{first_node, second_node});
auto &last_inserted = raw_route.segment_end_coordinates.back();
// enable forward direction if possible
if (last_inserted.source_phantom.forward_segment_id.id != SPECIAL_SEGMENTID)
{
last_inserted.source_phantom.forward_segment_id.enabled |= allow_u_turn_at_via;
}
// enable reverse direction if possible
if (last_inserted.source_phantom.reverse_segment_id.id != SPECIAL_SEGMENTID)
{
last_inserted.source_phantom.reverse_segment_id.enabled |= allow_u_turn_at_via;
}
};
util::for_each_pair(snapped_phantoms, build_phantom_pairs);
+20 -6
View File
@@ -122,18 +122,30 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const NodeI
NodeID current_edge_source_coordinate_id = node_u;
const auto edge_id_to_segment_id = [](const NodeID edge_based_node_id)
{
if (edge_based_node_id == SPECIAL_NODEID)
{
return SegmentID{SPECIAL_SEGMENTID, false};
}
return SegmentID{edge_based_node_id, true};
};
// traverse arrays from start and end respectively
for (const auto i : util::irange(std::size_t{ 0 }, geometry_size))
{
BOOST_ASSERT(current_edge_source_coordinate_id ==
m_compressed_edge_container.GetBucketReference(
edge_id_2)[geometry_size - 1 - i].node_id);
BOOST_ASSERT(
current_edge_source_coordinate_id ==
m_compressed_edge_container.GetBucketReference(edge_id_2)[geometry_size - 1 - i]
.node_id);
const NodeID current_edge_target_coordinate_id = forward_geometry[i].node_id;
BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id);
// build edges
m_edge_based_node_list.emplace_back(
forward_data.edge_id, reverse_data.edge_id, current_edge_source_coordinate_id,
edge_id_to_segment_id(forward_data.edge_id),
edge_id_to_segment_id(reverse_data.edge_id), current_edge_source_coordinate_id,
current_edge_target_coordinate_id, forward_data.name_id,
m_compressed_edge_container.GetPositionForID(edge_id_1),
m_compressed_edge_container.GetPositionForID(edge_id_2), false, INVALID_COMPONENTID, i,
@@ -208,7 +220,8 @@ unsigned EdgeBasedGraphFactory::RenumberEdges()
// oneway streets always require this self-loop. Other streets only if a u-turn plus
// traversal
// of the street takes longer than the loop
m_edge_based_node_weights.push_back(edge_data.distance + profile_properties.u_turn_penalty);
m_edge_based_node_weights.push_back(edge_data.distance +
profile_properties.u_turn_penalty);
BOOST_ASSERT(numbered_edges_count < m_node_based_graph->GetNumberOfEdges());
edge_data.edge_id = numbered_edges_count;
@@ -344,7 +357,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
distance += profile_properties.traffic_signal_penalty;
}
const int turn_penalty = use_turn_function ? GetTurnPenalty(turn_angle, lua_state) : 0;
const int turn_penalty =
use_turn_function ? GetTurnPenalty(turn_angle, lua_state) : 0;
const auto turn_instruction = turn.instruction;
if (guidance::isUturn(turn_instruction))
+17 -17
View File
@@ -108,7 +108,7 @@ int Extractor::run()
util::SimpleLogger().Write() << "Parsing in progress..";
TIMER_START(parsing);
auto& main_context = scripting_environment.GetContex();
auto &main_context = scripting_environment.GetContex();
// setup raster sources
if (util::luaFunctionExists(main_context.state, "source_function"))
@@ -163,7 +163,7 @@ int Extractor::run()
{
ExtractionNode result_node;
ExtractionWay result_way;
auto& local_context = scripting_environment.GetContex();
auto &local_context = scripting_environment.GetContex();
for (auto x = range.begin(), end = range.end(); x != end; ++x)
{
@@ -258,7 +258,7 @@ int Extractor::run()
// movement (e.g. turn from A->B, and B->A) becomes an edge
//
auto& main_context = scripting_environment.GetContex();
auto &main_context = scripting_environment.GetContex();
util::SimpleLogger().Write() << "Generating edge-expanded graph representation";
@@ -269,8 +269,7 @@ int Extractor::run()
std::vector<bool> node_is_startpoint;
std::vector<EdgeWeight> edge_based_node_weights;
std::vector<QueryNode> internal_to_external_node_map;
auto graph_size = BuildEdgeExpandedGraph(main_context.state,
main_context.properties,
auto graph_size = BuildEdgeExpandedGraph(main_context.state, main_context.properties,
internal_to_external_node_map,
edge_based_node_list, node_is_startpoint,
edge_based_node_weights, edge_based_edge_list);
@@ -317,7 +316,8 @@ int Extractor::run()
return 0;
}
void Extractor::WriteProfileProperties(const std::string& output_path, const ProfileProperties& properties) const
void Extractor::WriteProfileProperties(const std::string &output_path,
const ProfileProperties &properties) const
{
boost::filesystem::ofstream out_stream(output_path);
if (!out_stream)
@@ -325,7 +325,7 @@ void Extractor::WriteProfileProperties(const std::string& output_path, const Pro
throw util::exception("Could not open " + output_path + " for writing.");
}
out_stream.write(reinterpret_cast<const char*>(&properties), sizeof(properties));
out_stream.write(reinterpret_cast<const char *>(&properties), sizeof(properties));
}
void Extractor::FindComponents(unsigned max_edge_id,
@@ -375,12 +375,12 @@ void Extractor::FindComponents(unsigned max_edge_id,
// connect forward and backward nodes of each edge
for (const auto &node : input_nodes)
{
if (node.reverse_edge_based_node_id != SPECIAL_NODEID)
if (node.reverse_segment_id.enabled)
{
BOOST_ASSERT(node.forward_edge_based_node_id <= max_edge_id);
BOOST_ASSERT(node.reverse_edge_based_node_id <= max_edge_id);
edges.push_back({node.forward_edge_based_node_id, node.reverse_edge_based_node_id, {}});
edges.push_back({node.reverse_edge_based_node_id, node.forward_edge_based_node_id, {}});
BOOST_ASSERT(node.forward_segment_id.id <= max_edge_id);
BOOST_ASSERT(node.reverse_segment_id.id <= max_edge_id);
edges.push_back({node.forward_segment_id.id, node.reverse_segment_id.id, {}});
edges.push_back({node.reverse_segment_id.id, node.forward_segment_id.id, {}});
}
}
@@ -396,10 +396,10 @@ void Extractor::FindComponents(unsigned max_edge_id,
for (auto &node : input_nodes)
{
auto forward_component = component_search.get_component_id(node.forward_edge_based_node_id);
BOOST_ASSERT(node.reverse_edge_based_node_id == SPECIAL_EDGEID ||
auto forward_component = component_search.get_component_id(node.forward_segment_id.id);
BOOST_ASSERT(!node.reverse_segment_id.enabled ||
forward_component ==
component_search.get_component_id(node.reverse_edge_based_node_id));
component_search.get_component_id(node.reverse_segment_id.id));
const unsigned component_size = component_search.get_component_size(forward_component);
node.component.is_tiny = component_size < config.small_component_size;
@@ -468,8 +468,8 @@ Extractor::LoadNodeBasedGraph(std::unordered_set<NodeID> &barrier_nodes,
\brief Building an edge-expanded graph from node-based input and turn restrictions
*/
std::pair<std::size_t, std::size_t>
Extractor::BuildEdgeExpandedGraph(lua_State* lua_state,
const ProfileProperties& profile_properties,
Extractor::BuildEdgeExpandedGraph(lua_State *lua_state,
const ProfileProperties &profile_properties,
std::vector<QueryNode> &internal_to_external_node_map,
std::vector<EdgeBasedNode> &node_based_edge_list,
std::vector<bool> &node_is_startpoint,