Skip to content

Commit

Permalink
remove TurnData from generate_edge function
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshkaj committed Nov 10, 2017
1 parent d0fd450 commit d72c8e1
Showing 1 changed file with 21 additions and 109 deletions.
130 changes: 21 additions & 109 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const auto node_based_edge_from,
const auto node_at_center_of_intersection,
const auto node_based_edge_to,
const auto &intersection,
const auto &turn,
const auto entry_class_id) {
const auto &turn) {

const auto node_restricted = isRestricted(node_along_road_entering,
node_at_center_of_intersection,
Expand All @@ -589,13 +587,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
BOOST_ASSERT(!edge_data1.reversed);
BOOST_ASSERT(!edge_data2.reversed);

// the following is the core of the loop.
TurnData turn_data = {turn.instruction,
turn.lane_data_id,
entry_class_id,
util::guidance::TurnBearing(intersection[0].bearing),
util::guidance::TurnBearing(turn.bearing)};

// compute weight and duration penalties
auto is_traffic_light = m_traffic_lights.count(node_at_center_of_intersection);
ExtractionTurn extracted_turn(
Expand Down Expand Up @@ -657,7 +648,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// insert data into the designated buffer
return std::make_tuple(
EdgeWithData{edge_based_edge, turn_index_block, weight_penalty, duration_penalty},
turn_data,
conditional);
};

Expand Down Expand Up @@ -736,9 +726,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const auto turn_classification = classifyIntersection(
intersection, m_coordinates[node_at_center_of_intersection]);

const auto entry_class_id =
entry_class_hash.ConcurrentFindOrAdd(turn_classification.first);

const auto bearing_class_id =
bearing_class_hash.ConcurrentFindOrAdd(turn_classification.second);

Expand Down Expand Up @@ -793,16 +780,14 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
incoming_edge,
node_at_center_of_intersection,
turn.eid,
intersection,
turn,
entry_class_id);
turn);

buffer.continuous_data.push_back(
std::get<0>(edge_with_data_and_condition));
if (std::get<2>(edge_with_data_and_condition))
if (std::get<1>(edge_with_data_and_condition))
{
buffer.conditionals.push_back(
*std::get<2>(edge_with_data_and_condition));
*std::get<1>(edge_with_data_and_condition));
}
}

Expand Down Expand Up @@ -846,17 +831,15 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
incoming_edge,
node_at_center_of_intersection,
turn.eid,
intersection,
turn,
entry_class_id);
turn);

buffer.delayed_data.push_back(
std::get<0>(edge_with_data_and_condition));

if (std::get<2>(edge_with_data_and_condition))
if (std::get<1>(edge_with_data_and_condition))
{
buffer.conditionals.push_back(
*std::get<2>(edge_with_data_and_condition));
*std::get<1>(edge_with_data_and_condition));
}

// also add the conditions for the way
Expand All @@ -880,17 +863,15 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
incoming_edge,
node_at_center_of_intersection,
turn.eid,
intersection,
turn,
entry_class_id);
turn);

buffer.delayed_data.push_back(
std::get<0>(edge_with_data_and_condition));

if (std::get<2>(edge_with_data_and_condition))
if (std::get<1>(edge_with_data_and_condition))
{
buffer.conditionals.push_back(
*std::get<2>(edge_with_data_and_condition));
*std::get<1>(edge_with_data_and_condition));
}
}
}
Expand Down Expand Up @@ -999,53 +980,13 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
if (!turn.entry_allowed)
continue;

// In case a way restriction starts at a given location, add a turn onto
// every artificial node eminating here.
//
// e - f
// |
// a - b
// |
// c - d
//
// ab via bc to cd
// ab via be to ef
//
// has two artifical nodes (be/bc) with restrictions starting at `ab`.
// Since every restriction group (abc | abe) refers to the same
// artificial node, we simply have to find a single representative for
// the turn. Here we check whether the turn in question is the start of
// a via way restriction. If that should be the case, we switch
// the id of the edge-based-node for the target to the ID of the
// duplicated node associated with the turn. (e.g. ab via bc switches bc
// to bc_dup)
auto const target_id = way_restriction_map.RemapIfRestricted(
nbe_to_ebn_mapping[turn.eid],
node_along_road_entering,
node_at_center_of_intersection,
m_node_based_graph.GetTarget(turn.eid),
m_number_of_edge_based_nodes);
buffer.continuous_turn_data.push_back(TurnData{turn.instruction,
turn.lane_data_id,
entry_class_id,
util::guidance::TurnBearing(intersection[0].bearing),
util::guidance::TurnBearing(turn.bearing)});

{ // scope to forget edge_with_data after
const auto edge_with_data_and_condition =
generate_edge(nbe_to_ebn_mapping[incoming_edge],
target_id,
node_along_road_entering,
incoming_edge,
node_at_center_of_intersection,
turn.eid,
intersection,
turn,
entry_class_id);

buffer.continuous_turn_data.push_back(
std::get<1>(edge_with_data_and_condition));
}

// when turning off a a via-way turn restriction, we need to not only
// handle the normal edges for the way, but also add turns for every
// duplicated node. This process is integrated here to avoid doing the
// turn analysis multiple times.
// generate turn instructions for the artificial nodes created for via ways
if (turning_off_via_way)
{
const auto duplicated_nodes = way_restriction_map.DuplicatedNodeIDs(
Expand All @@ -1056,10 +997,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// here when turning off a via-way
for (auto duplicated_node_id : duplicated_nodes)
{
const auto from_id = m_number_of_edge_based_nodes -
way_restriction_map.NumberOfDuplicatedNodes() +
duplicated_node_id;

auto const node_at_end_of_turn =
m_node_based_graph.GetTarget(turn.eid);

Expand All @@ -1073,38 +1010,13 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(

if (restriction.condition.empty())
continue;

// add into delayed data
auto edge_with_data_and_condition =
generate_edge(NodeID(from_id),
nbe_to_ebn_mapping[turn.eid],
node_along_road_entering,
incoming_edge,
node_at_center_of_intersection,
turn.eid,
intersection,
turn,
entry_class_id);

buffer.delayed_turn_data.push_back(
std::get<1>(edge_with_data_and_condition));
}
else
{
auto edge_with_data_and_condition =
generate_edge(NodeID(from_id),
nbe_to_ebn_mapping[turn.eid],
node_along_road_entering,
incoming_edge,
node_at_center_of_intersection,
turn.eid,
intersection,
turn,
entry_class_id);

buffer.delayed_turn_data.push_back(
std::get<1>(edge_with_data_and_condition));
}
buffer.delayed_turn_data.push_back(TurnData{turn.instruction,
turn.lane_data_id,
entry_class_id,
util::guidance::TurnBearing(intersection[0].bearing),
util::guidance::TurnBearing(turn.bearing)});
}
}
}
Expand Down

0 comments on commit d72c8e1

Please sign in to comment.