Big Restructuring / Cleanup

This commit is contained in:
Patrick Niklaus
2016-03-01 22:30:31 +01:00
parent adb8d0e845
commit b08b360f38
40 changed files with 419 additions and 511 deletions
+5 -69
View File
@@ -1,6 +1,5 @@
#include "extractor/edge_based_edge.hpp"
#include "extractor/edge_based_graph_factory.hpp"
#include "extractor/turn_analysis.hpp"
#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/percent.hpp"
@@ -10,8 +9,7 @@
#include "util/timing_util.hpp"
#include "util/exception.hpp"
#include "engine/guidance/turn_classification.hpp"
#include "engine/guidance/guidance_toolkit.hpp"
#include "extractor/guidance/toolkit.hpp"
#include <boost/assert.hpp>
#include <boost/numeric/conversion/cast.hpp>
@@ -307,56 +305,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// Three nested loop look super-linear, but we are dealing with a (kind of)
// linear number of turns only.
util::Percent progress(m_node_based_graph->GetNumberOfNodes());
struct CompareTurnPossibilities
{
bool operator()(const std::vector<engine::guidance::TurnPossibility> &left,
const std::vector<engine::guidance::TurnPossibility> &right) const
{
if (left.size() < right.size())
return true;
if (left.size() > right.size())
return false;
for (std::size_t i = 0; i < left.size(); ++i)
{
if ((((int)left[i].angle + 16) % 256) / 32 <
(((int)right[i].angle + 16) % 256) / 32)
return true;
if ((((int)left[i].angle + 16) % 256) / 32 >
(((int)right[i].angle + 16) % 256) / 32)
return false;
}
return false;
}
};
// temporary switch to allow display of turn types
#define SHOW_TURN_TYPES 0
#if SHOW_TURN_TYPES
std::map<std::vector<engine::guidance::TurnPossibility>,
std::vector<util::FixedPointCoordinate>, CompareTurnPossibilities> turn_types;
#endif
for (const auto node_u : util::irange(0u, m_node_based_graph->GetNumberOfNodes()))
{
#if SHOW_TURN_TYPES
auto turn_possibilities = classifyIntersection(
node_u, *m_node_based_graph, m_compressed_edge_container, m_node_info_list);
if (turn_possibilities.empty())
continue;
auto set = turn_types.find(turn_possibilities);
if (set != turn_types.end())
{
if (set->second.size() < 5)
set->second.emplace_back(m_node_info_list[node_u].lat,
m_node_info_list[node_u].lon);
}
else
{
turn_types[turn_possibilities] = std::vector<util::FixedPointCoordinate>(
1, {m_node_info_list[node_u].lat, m_node_info_list[node_u].lon});
}
#endif
// progress.printStatus(node_u);
for (const EdgeID edge_from_u : m_node_based_graph->GetAdjacentEdgeRange(node_u))
{
@@ -366,8 +316,9 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
}
++node_based_edge_counter;
auto turn_candidates = turn_analysis::getTurns(node_u, edge_from_u, m_node_based_graph, m_node_info_list, m_restriction_map, m_barrier_nodes,
m_compressed_edge_container);
auto turn_candidates = guidance::getTurns(
node_u, edge_from_u, m_node_based_graph, m_node_info_list, m_restriction_map,
m_barrier_nodes, m_compressed_edge_container);
const NodeID node_v = m_node_based_graph->GetTarget(edge_from_u);
@@ -396,7 +347,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const int turn_penalty = GetTurnPenalty(turn_angle, lua_state);
const auto turn_instruction = turn.instruction;
if (isUturn(turn_instruction))
if (guidance::isUturn(turn_instruction))
{
distance += speed_profile.u_turn_penalty;
}
@@ -471,21 +422,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
}
}
}
#if SHOW_TURN_TYPES
std::cout << "[info] found " << turn_types.size() << " turn types." << std::endl;
for (const auto &tt : turn_types)
{
std::cout << tt.second.size();
for (auto coord : tt.second)
std::cout << " " << coord.lat << " " << coord.lon;
std::cout << " " << tt.first.size();
for (auto tte : tt.first)
std::cout << " " << (int)tte.angle;
std::cout << std::endl;
}
#endif
FlushVectorToStream(edge_data_file, original_edge_data_vector);
-1
View File
@@ -188,7 +188,6 @@ int Extractor::run()
local_state, "way_function",
boost::cref(static_cast<const osmium::Way &>(*entity)),
boost::ref(result_way));
result_way.road_classification_data.augment(static_cast<const osmium::Way &>(*entity));
resulting_ways.push_back(std::make_pair(x, result_way));
break;
case osmium::item_type::relation:
+11 -3
View File
@@ -128,6 +128,14 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
return;
}
// FIXME this need to be moved into the profiles
const char *data = input_way.get_value_by_key("highway");
guidance::RoadClassificationData road_classification;
if (data)
{
road_classification.road_class = guidance::functionalRoadClassFromTag(data);
}
// Get the unique identifier for the street name
const auto &string_map_iterator = string_map.find(parsed_way.name);
unsigned name_id = external_memory.name_lengths.size();
@@ -173,7 +181,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
name_id, backward_weight_data, true, false,
parsed_way.roundabout, parsed_way.is_access_restricted,
parsed_way.is_startpoint, parsed_way.backward_travel_mode,
false,parsed_way.road_classification_data));
false, road_classification));
});
external_memory.way_start_end_id_list.push_back(
@@ -193,7 +201,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
name_id, forward_weight_data, true, !forward_only,
parsed_way.roundabout, parsed_way.is_access_restricted,
parsed_way.is_startpoint, parsed_way.forward_travel_mode,
split_edge,parsed_way.road_classification_data));
split_edge, road_classification));
});
if (split_edge)
{
@@ -206,7 +214,7 @@ void ExtractorCallbacks::ProcessWay(const osmium::Way &input_way, const Extracti
OSMNodeID(first_node.ref()), OSMNodeID(last_node.ref()), name_id,
backward_weight_data, false, true, parsed_way.roundabout,
parsed_way.is_access_restricted, parsed_way.is_startpoint,
parsed_way.backward_travel_mode, true,parsed_way.road_classification_data));
parsed_way.backward_travel_mode, true, road_classification));
});
}
@@ -1,4 +1,4 @@
#include "extractor/turn_analysis.hpp"
#include "extractor/guidance/turn_analysis.hpp"
#include "util/simple_logger.hpp"
@@ -8,8 +8,7 @@ namespace osrm
{
namespace extractor
{
namespace turn_analysis
namespace guidance
{
// configuration of turn classification
const bool constexpr INVERT = true;
@@ -29,26 +28,6 @@ const unsigned constexpr INVALID_NAME_ID = 0;
using EdgeData = util::NodeBasedDynamicGraph::EdgeData;
using engine::guidance::TurnPossibility;
using engine::guidance::TurnInstruction;
using engine::guidance::DirectionModifier;
using engine::guidance::TurnType;
using engine::guidance::FunctionalRoadClass;
using engine::guidance::classifyIntersection;
using engine::guidance::isLowPriorityRoadClass;
using engine::guidance::angularDeviation;
using engine::guidance::getTurnDirection;
using engine::guidance::getRepresentativeCoordinate;
using engine::guidance::isBasic;
using engine::guidance::isRampClass;
using engine::guidance::isUturn;
using engine::guidance::isConflict;
using engine::guidance::isSlightTurn;
using engine::guidance::isSlightModifier;
using engine::guidance::mirrorDirectionModifier;
using engine::guidance::canBeSuppressed;
#define PRINT_DEBUG_CANDIDATES 0
std::vector<TurnCandidate>
getTurns(const NodeID from,
@@ -419,7 +398,8 @@ handleFromMotorway(const NodeID from,
if (candidate.valid)
{
BOOST_ASSERT(isRampClass(candidate.eid, node_based_graph));
candidate.instruction = TurnInstruction::SUPPRESSED(getTurnDirection(candidate.angle));
candidate.instruction =
TurnInstruction::SUPPRESSED(getTurnDirection(candidate.angle));
}
}
}
@@ -447,27 +427,26 @@ handleFromMotorway(const NodeID from,
if (candidate.angle == continue_angle)
{
if (continues)
candidate.instruction = TurnInstruction::SUPPRESSED(DirectionModifier::Straight);
candidate.instruction =
TurnInstruction::SUPPRESSED(DirectionModifier::Straight);
else // TODO handle turn direction correctly
candidate.instruction = {TurnType::Merge, DirectionModifier::Straight};
}
else if (candidate.angle < continue_angle)
{
BOOST_ASSERT(isRampClass(node_based_graph->GetEdgeData(candidate.eid)
.road_classification.road_class));
candidate.instruction = {TurnType::Ramp,
(candidate.angle < 145)
? DirectionModifier::Right
: DirectionModifier::SlightRight};
candidate.instruction = {
isRampClass(candidate.eid, node_based_graph) ? TurnType::Ramp
: TurnType::Turn,
(candidate.angle < 145) ? DirectionModifier::Right
: DirectionModifier::SlightRight};
}
else if (candidate.angle > continue_angle)
{
BOOST_ASSERT(isRampClass(node_based_graph->GetEdgeData(candidate.eid)
.road_classification.road_class));
candidate.instruction = {TurnType::Ramp,
(candidate.angle > 215)
? DirectionModifier::Left
: DirectionModifier::SlightLeft};
candidate.instruction = {
isRampClass(candidate.eid, node_based_graph) ? TurnType::Ramp
: TurnType::Turn,
(candidate.angle > 215) ? DirectionModifier::Left
: DirectionModifier::SlightLeft};
}
}
}
@@ -633,7 +612,8 @@ handleMotorwayJunction(const NodeID from,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph)
{
(void)from;
BOOST_ASSERT(!turn_candidates[0].valid);
// BOOST_ASSERT(!turn_candidates[0].valid); //This fails due to @themarex handling of dead end
// streets
const auto &in_data = node_based_graph->GetEdgeData(via_edge);
// coming from motorway
@@ -766,6 +746,7 @@ handleOneWayTurn(const NodeID from,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph)
{
BOOST_ASSERT(turn_candidates[0].angle < 0.001);
(void)from, (void)via_edge, (void)node_based_graph;
if (!turn_candidates[0].valid)
{
@@ -773,8 +754,6 @@ handleOneWayTurn(const NodeID from,
<< "Graph Broken. Dead end without exit found or missing reverse edge.";
}
BOOST_ASSERT(turn_candidates[0].instruction.type == TurnType::Turn &&
turn_candidates[0].instruction.direction_modifier == DirectionModifier::UTurn);
#if PRINT_DEBUG_CANDIDATES
std::cout << "Basic (one) Turn Candidates:\n";
for (auto tc : turn_candidates)
@@ -791,8 +770,7 @@ handleTwoWayTurn(const NodeID from,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph)
{
BOOST_ASSERT(turn_candidates[0].instruction.type == TurnType::Turn &&
turn_candidates[0].instruction.direction_modifier == DirectionModifier::UTurn);
BOOST_ASSERT(turn_candidates[0].angle < 0.001);
turn_candidates[1].instruction =
getInstructionForObvious(from, via_edge, turn_candidates[1], node_based_graph);
@@ -813,6 +791,7 @@ handleThreeWayTurn(const NodeID from,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph)
{
BOOST_ASSERT(turn_candidates[0].angle < 0.001);
const auto isObviousOfTwo = [](const TurnCandidate turn, const TurnCandidate other)
{
return (angularDeviation(turn.angle, STRAIGHT_ANGLE) < NARROW_TURN_ANGLE &&
@@ -971,7 +950,8 @@ handleThreeWayTurn(const NodeID from,
{
if (isObviousOfTwo(turn_candidates[1], turn_candidates[2]))
{
turn_candidates[1].instruction = TurnInstruction::SUPPRESSED(DirectionModifier::Straight);
turn_candidates[1].instruction =
TurnInstruction::SUPPRESSED(DirectionModifier::Straight);
}
else
{
@@ -988,7 +968,8 @@ handleThreeWayTurn(const NodeID from,
{
if (isObviousOfTwo(turn_candidates[2], turn_candidates[1]))
{
turn_candidates[2].instruction = TurnInstruction::SUPPRESSED(DirectionModifier::Straight);
turn_candidates[2].instruction =
TurnInstruction::SUPPRESSED(DirectionModifier::Straight);
}
else
{
@@ -1199,8 +1180,7 @@ optimizeCandidates(const EdgeID via_eid,
for (std::size_t turn_index = 0; turn_index < turn_candidates.size(); ++turn_index)
{
auto &turn = turn_candidates[turn_index];
if (!isBasic(turn.instruction.type) || isUturn(turn.instruction) ||
isOnRoundabout(turn.instruction))
if (!isBasic(turn.instruction.type) || isUturn(turn.instruction))
continue;
auto &left = turn_candidates[getLeft(turn_index)];
if (turn.angle == left.angle)
@@ -1393,8 +1373,7 @@ bool isObviousChoice(const EdgeID via_eid,
node_based_graph->GetEdgeData(candidate.eid).road_classification.road_class))
{
bool is_only_normal_road = true;
BOOST_ASSERT(turn_candidates[0].instruction.type == TurnType::Turn &&
turn_candidates[0].instruction.direction_modifier == DirectionModifier::UTurn);
// TODO find out why this can also be reached for non-u-turns
for (size_t i = 0; i < turn_candidates.size(); ++i)
{
if (i == turn_index || turn_candidates[i].angle == 0) // skip self and u-turn
@@ -1554,7 +1533,7 @@ suppressTurns(const EdgeID via_eid,
}
else
{
if (engine::guidance::canBeSuppressed(candidate.instruction.type))
if (canBeSuppressed(candidate.instruction.type))
candidate.instruction.type = TurnType::NewName;
}
}
@@ -1841,21 +1820,20 @@ handleConflicts(const NodeID from,
(void)from;
(void)via_edge;
(void)node_based_graph;
const auto isConflict = []( const TurnCandidate &left, const TurnCandidate &right )
const auto isConflict = [](const TurnCandidate &left, const TurnCandidate &right)
{
// most obvious, same instructions conflict
if( left.instruction == right.instruction )
return true;
if (left.instruction == right.instruction)
return true;
return left.instruction.direction_modifier != DirectionModifier::UTurn &&
left.instruction.direction_modifier == right.instruction.direction_modifier;
};
return turn_candidates;
}
} // anemspace detail
} // namespace turn_analysis
} // namespace guidance
} // namespace extractor
} // namespace osrm