Skip to content

Commit

Permalink
fix pull in / rebase errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Kobitzsch committed Oct 13, 2016
1 parent e15bfcc commit ed4839b
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 96 deletions.
14 changes: 14 additions & 0 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "extractor/profile_properties.hpp"
#include "extractor/query_node.hpp"
#include "extractor/restriction_map.hpp"
#include "extractor/turn_penalty.hpp"

#include "extractor/guidance/turn_analysis.hpp"
#include "extractor/guidance/turn_instruction.hpp"
Expand Down Expand Up @@ -180,6 +181,19 @@ class EdgeBasedGraphFactory
std::unordered_map<util::guidance::BearingClass, BearingClassID> bearing_class_hash;
std::vector<BearingClassID> bearing_class_by_node_based_node;
std::unordered_map<util::guidance::EntryClass, EntryClassID> entry_class_hash;

void ComputeTurnFunctionParameters(const NodeID from_node,
const EdgeID in_edge,
const NodeID intersection_node,
const EdgeID out_edge,
const NodeID to_node,
const double angle,
guidance::TurnInstruction instruction,
bool crosses_through_traffic,
TurnProperties &turn_properties,
IntersectionProperties &intersection_properties,
TurnSegment &approach_segment,
TurnSegment &exit_segment);
};
} // namespace extractor
} // namespace osrm
Expand Down
2 changes: 2 additions & 0 deletions include/extractor/turn_penalty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct TurnProperties
bool crossing_through_traffic;
// indicate if the turn needs to be announced or if it is a turn following the obvious road
bool requires_announcement;
// check if we are continuing on the normal road on an obvious turn
bool is_through_street;
};

// properties describing intersection related penalties
Expand Down
1 change: 1 addition & 0 deletions include/util/coordinate_calculation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <boost/optional.hpp>

#include <utility>
#include <vector>

namespace osrm
{
Expand Down
25 changes: 23 additions & 2 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,29 @@ function way_function (way, result)
result.is_startpoint = result.forward_mode == mode.driving or result.backward_mode == mode.driving
end

local function getTurningSpeed(turn_properties,intersection_properties,approach_segment, exit_segment)
-- should probably consider the turn angle, radius, ... as well
return math.min(approach_segment.speed_in_meters_per_second, exit_segment.speed_in_meters_per_second)
end

-- compute the time it takes to achieve a speed difference via an acceleration
local function getDeltaTime(speed_difference,acceleration)
local avg_deceleration = 1.9
local avg_acceleration = 2.78
-- assuming constant acceleration for simplicity
if speed_difference > 0 then
return speed_difference / avg_acceleration
else
return math.abs(speed_difference) / avg_deceleration
end
end

function turn_function(angle, turn_properties, intersection_properties, approach_segment, exit_segment)
local penalty = 0;
local turning_speed = getTurningSpeed(turn_properties,intersection_properties,approach_segment,exit_segment)

local penalty = getDeltaTime(approach_segment.speed_in_meters_per_second-turning_speed)
+ getDeltaTime(exit_segment.speed_in_meters_per_second-turning_speed)

if turn_properties.angle>=0 then
penalty = turn_penalty / (1 + 2.718 ^ - ((13 / turn_bias) * angle/180 - 6.5*turn_bias))
else
Expand All @@ -626,5 +647,5 @@ function turn_function(angle, turn_properties, intersection_properties, approach
penalty = penalty + crossing_through_traffic_penalty
end

return penalty;
return 10 * penalty;
end
160 changes: 88 additions & 72 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,72 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes()
<< " nodes in edge-expanded graph";
}

void EdgeBasedGraphFactory::ComputeTurnFunctionParameters(
const NodeID from_node,
const EdgeID in_edge,
const NodeID intersection_node,
const EdgeID out_edge,
const NodeID to_node,
const double angle,
const guidance::TurnInstruction instruction,
const bool crosses_through_traffic,
TurnProperties &turn_properties,
IntersectionProperties &intersection_properties,
TurnSegment &approach_segment,
TurnSegment &exit_segment)
{

bool is_silent = ((instruction.type == guidance::TurnType::Suppressed) ||
(instruction.type == guidance::TurnType::NewName) ||
(instruction.type == guidance::TurnType::Notification));

const auto is_through = [&]() {
if (!is_silent)
return false;
auto eid = m_node_based_graph->FindEdge(m_node_based_graph->GetTarget(out_edge),
intersection_node);
if (eid == SPECIAL_EDGEID)
return false;
return !m_node_based_graph->GetEdgeData(eid).reversed;
}();

const double radius = 0;
turn_properties = {180 - angle, radius, crosses_through_traffic, is_silent, is_through};

const bool crosses_traffic_light =
m_traffic_lights.find(intersection_node) != m_traffic_lights.end();

intersection_properties = {crosses_traffic_light, false, false};

const bool isTrivial = m_compressed_edge_container.IsTrivial(in_edge);

const auto &approach_coordinate =
isTrivial ? m_node_info_list[from_node]
: m_node_info_list[m_compressed_edge_container.GetLastEdgeSourceID(in_edge)];

const auto intersection_coordinate = m_node_info_list[intersection_node];

const auto &exit_coordinate = m_node_info_list[to_node];

const double approach_segment_length = util::coordinate_calculation::greatCircleDistance(
approach_coordinate, intersection_coordinate);
const double exit_segment_length =
util::coordinate_calculation::greatCircleDistance(intersection_coordinate, exit_coordinate);

const auto approach_road_segments = m_compressed_edge_container.GetBucketReference(in_edge);
const auto exit_road_segments = m_compressed_edge_container.GetBucketReference(out_edge);

// segment_length is in metres, weight is in deciseconds, this converts those
// to km/h
const double approach_speed =
approach_segment_length / (approach_road_segments.back().weight / 10) * 3.6; // km/h
const double exit_speed =
exit_segment_length / (exit_road_segments.front().weight / 10) * 3.6; // km/h

approach_segment = {approach_segment_length, approach_speed};
exit_segment = {exit_segment_length, exit_speed};
}

/// Actually it also generates OriginalEdgeData and serializes them...
void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
ScriptingEnvironment &scripting_environment,
Expand Down Expand Up @@ -419,13 +485,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
}(turn_classification.second);
bearing_class_by_node_based_node[node_v] = bearing_class_id;

const bool crosses_traffic_light =
m_traffic_lights.find(node_v) != m_traffic_lights.end();

bool crosses_through_traffic = false;
const EdgeData &edge_data_from_u = m_node_based_graph->GetEdgeData(edge_from_u);
const IntersectionProperties intersection_properties = {
crosses_traffic_light, false, false};
for (const auto turn : possible_turns)
{
// only add an edge if turn is not prohibited
Expand All @@ -439,85 +500,40 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// the following is the core of the loop.
unsigned distance = edge_data_from_u.distance;

if (crosses_traffic_light)
{
distance += profile_properties.traffic_signal_penalty;
}

distance += turn_penalty;

if (crosses_through_traffic)
distance += profile_properties.crossing_through_traffic_penalty;

// a through street is an obvious turn on which we can expect traffic coming onto
// our direction
const auto isThrough = [&](const guidance::TurnOperation &turn) {
if (!((turn.instruction.type == guidance::TurnType::Suppressed) ||
(turn.instruction.type == guidance::TurnType::NewName) ||
(turn.instruction.type == guidance::TurnType::Notification)))
return false;
auto eid = m_node_based_graph->FindEdge(m_node_based_graph->GetTarget(turn.eid),
node_v);
if (eid == SPECIAL_EDGEID)
return false;
return !m_node_based_graph->GetEdgeData(eid).reversed;
};

const bool requires_announcement = isThrough(turn);

const TurnProperties turn_properties = {
180. - turn.angle, turn.angle, crosses_through_traffic, requires_announcement};


const bool isTrivial = m_compressed_edge_container.IsTrivial(edge_from_u);

const auto &approach_node =
isTrivial
? m_node_info_list[node_u]
: m_node_info_list[m_compressed_edge_container.GetLastEdgeSourceID(
edge_from_u)];
const auto &intersection_node =
m_node_info_list[m_compressed_edge_container.GetLastEdgeTargetID(
edge_from_u)];

const auto &exit_node =
m_node_info_list[m_compressed_edge_container.GetFirstEdgeTargetID(
turn.eid)];

const double approach_segment_length =
util::coordinate_calculation::greatCircleDistance(approach_node, intersection_node);
const double exit_segment_length =
util::coordinate_calculation::greatCircleDistance(intersection_node, exit_node);

const auto approach_road_segments =
m_compressed_edge_container.GetBucketReference(edge_from_u);
const auto exit_road_segments =
m_compressed_edge_container.GetBucketReference(turn.eid);

// segment_length is in metres, weight is in deciseconds, this converts those
// to km/h
const double approach_speed = approach_segment_length / (approach_road_segments.back().weight/10) * 3.6; // km/h
const double exit_speed = exit_segment_length / (exit_road_segments.front().weight/10) * 3.6; // km/h

const TurnSegment approach_segment = {approach_segment_length,approach_speed};
const TurnSegment exit_segment = {exit_segment_length,exit_speed};

const auto turn_instruction = turn.instruction;

TurnProperties turn_properties;
IntersectionProperties intersection_properties;
TurnSegment approach_segment, exit_segment;
ComputeTurnFunctionParameters(node_u,
edge_from_u,
node_v,
turn.eid,
m_node_based_graph->GetTarget(turn.eid),
turn.angle,
turn.instruction,
crosses_through_traffic,
turn_properties,
intersection_properties,
approach_segment,
exit_segment);

const int32_t turn_penalty = scripting_environment.GetTurnPenalty(
turn_properties, intersection_properties, approach_segment, exit_segment);


if (turn_instruction.direction_modifier == guidance::DirectionModifier::UTurn)
{
distance += profile_properties.u_turn_penalty;
}

if (intersection_properties.traffic_light)
distance += profile_properties.traffic_signal_penalty;

distance += turn_penalty;

// if a turn is a through turn, all following turns are crossing through the
// opposite traffic
if (isThrough(turn))
if (turn_properties.is_through_street)
crosses_through_traffic = true;

const bool is_encoded_forwards =
Expand All @@ -535,11 +551,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
edge_from_u),
false};
original_edge_data_vector.emplace_back(geometry_id,
edge_data1.name_id,
edge_data_from_u.name_id,
turn.lane_data_id,
turn_instruction,
entry_class_id,
edge_data1.travel_mode);
edge_data_from_u.travel_mode);

++original_edges_counter;

Expand Down
24 changes: 12 additions & 12 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,11 @@ void LuaScriptingEnvironment::SetupSources()
}
}

std::int32_t LuaScriptingEnvironment::GetTurnPenalty(
const TurnProperties &turn_properties,
const IntersectionProperties &intersection_properties,
const TurnSegment &approach_segment,
const TurnSegment &exit_segment)
std::int32_t
LuaScriptingEnvironment::GetTurnPenalty(const TurnProperties &turn_properties,
const IntersectionProperties &intersection_properties,
const TurnSegment &approach_segment,
const TurnSegment &exit_segment)
{
auto &context = GetLuaContext();
if (context.has_turn_penalty_function)
Expand All @@ -388,13 +388,13 @@ std::int32_t LuaScriptingEnvironment::GetTurnPenalty(
{
// call lua profile to compute turn penalty
const double penalty =
10.0 * luabind::call_function<double>(context.state,
"turn_function",
turn_properties.angle,
boost::cref(turn_properties),
boost::cref(intersection_properties),
boost::cref(approach_segment),
boost::cref(exit_segment));
luabind::call_function<double>(context.state,
"turn_function",
turn_properties.angle,
boost::cref(turn_properties),
boost::cref(intersection_properties),
boost::cref(approach_segment),
boost::cref(exit_segment));
BOOST_ASSERT(penalty < std::numeric_limits<int32_t>::max());
BOOST_ASSERT(penalty > std::numeric_limits<int32_t>::min());
return boost::numeric_cast<int32_t>(penalty);
Expand Down
14 changes: 4 additions & 10 deletions src/util/coordinate_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ bool circleCenterTaubin(const std::vector<Coordinate> &coords,
std::pair<double, double> &center,
double &estimated_radius)
{
// guard against empty coordinates
if( coords.empty() )
return false;

// Compute mean and covariances with the two-pass algorithm
double meanX = 0., meanY = 0.;
for (const auto &c : coords)
Expand Down Expand Up @@ -281,16 +285,6 @@ double computeAngle(const Coordinate first, const Coordinate second, const Coord
return angle;
}

double circleRadius(const Coordinate C1, const Coordinate C2, const Coordinate C3)
{
// a circle by three points requires thee distinct points
auto center = circleCenter(C1, C2, C3);
if (center)
return haversineDistance(C1, *center);
else
return std::numeric_limits<double>::infinity();
}

boost::optional<Coordinate> circleCenter(const std::vector<Coordinate> &coords)
{
std::pair<double, double> center;
Expand Down

0 comments on commit ed4839b

Please sign in to comment.