Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes in guidance #4929

Merged
merged 6 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
- Bugfixes:
- fix deduplication of route steps when waypoints are used [#4909](https://github.com/Project-OSRM/osrm-backend/issues/4909)
- FIXED #4920: Use smaller range for U-turn angles in map-matching [#4920](https://github.com/Project-OSRM/osrm-backend/pull/4920)
- Profile:
- CHANGED #4929: Handle oneways in get_forward_backward_by_key [#4929](https://github.com/Project-OSRM/osrm-backend/pull/4929)
- Guidance:
- CHANGED #4929: Don't use obviousness for links bifurcations [#4929](https://github.com/Project-OSRM/osrm-backend/pull/4929)
- FIXED #4929: Adjust Straight direction modifiers of side roads in driveway handler [#4929](https://github.com/Project-OSRM/osrm-backend/pull/4929)
- Tools:
- `osrm-routed` accepts a new property `--memory_file` to store memory in a file on disk.
- NodeJS:
Expand Down
20 changes: 20 additions & 0 deletions features/guidance/driveway.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,23 @@ Feature: Driveways intersections
When I route I should get
| waypoints | route | turns | locations |
| a,d | ,second | depart,arrive | a,d |


Scenario: Road with a turn to service road
Given the node map
"""
/-----------------e
a---b------------------c
`-----------------d
"""

And the ways
| nodes | highway | name | oneway |
| abc | trunk | road | yes |
| bd | service | serv | yes |
| be | service | serv | yes |

When I route I should get
| waypoints | route | turns | locations |
| a,d | road,serv,serv | depart,turn slight right,arrive | a,b,d |
| a,e | road,serv,serv | depart,turn slight left,arrive | a,b,e |
4 changes: 2 additions & 2 deletions features/guidance/motorway.feature
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Feature: Motorway Guidance
| a,e | abcde,abcde | depart,arrive |
| f,e | fgc,abcde,abcde | depart,merge slight left,arrive |
| a,i | abcde,chi,chi | depart,off ramp slight right,arrive |
| f,i | fgc,chi,chi | depart,off ramp right,arrive |
| f,i | fgc,chi,chi | depart,off ramp slight right,arrive |

Scenario: On And Off Ramp Left
Given the node map
Expand All @@ -221,7 +221,7 @@ Feature: Motorway Guidance
| a,e | abcde,abcde | depart,arrive |
| f,e | fgc,abcde,abcde | depart,merge slight right,arrive |
| a,i | abcde,chi,chi | depart,off ramp slight left,arrive |
| f,i | fgc,chi,chi | depart,off ramp left,arrive |
| f,i | fgc,chi,chi | depart,off ramp slight left,arrive |

Scenario: Merging Motorways
Given the node map
Expand Down
15 changes: 0 additions & 15 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@
#include "extractor/restriction_index.hpp"
#include "extractor/turn_lane_types.hpp"
#include "extractor/way_restriction_map.hpp"
#include "guidance/turn_analysis.hpp"
#include "guidance/turn_instruction.hpp"

#include "util/concurrent_id_map.hpp"
#include "util/deallocating_vector.hpp"
#include "util/guidance/bearing_class.hpp"
#include "util/guidance/entry_class.hpp"
#include "util/name_table.hpp"
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp"
Expand Down Expand Up @@ -99,17 +95,6 @@ class EdgeBasedGraphFactory

std::uint64_t GetNumberOfEdgeBasedNodes() const;

// Basic analysis of a turn (u --(e1)-- v --(e2)-- w)
// with known angle.
// Handles special cases like u-turns and roundabouts
// For basic turns, the turn based on the angle-classification is returned
guidance::TurnInstruction AnalyzeTurn(const NodeID u,
const EdgeID e1,
const NodeID v,
const EdgeID e2,
const NodeID w,
const double angle) const;

private:
using EdgeData = util::NodeBasedDynamicGraph::EdgeData;

Expand Down
11 changes: 8 additions & 3 deletions include/extractor/intersection/intersection_edge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ struct IntersectionEdge

using IntersectionEdges = std::vector<IntersectionEdge>;

// The extracted geometry of an intersection edge only knows about edge IDs and bearings
// Bearing is the direction in clockwise angle from true north after taking the turn:
// 0 = heading north, 90 = east, 180 = south, 270 = west
// `initial_bearing` is the original OSM edge bearing
// `perceived_bearing` is the edge bearing after line fitting and edges merging
struct IntersectionEdgeGeometry
{
EdgeID edge;
EdgeID eid;
double initial_bearing;
double perceived_bearing;
double length;
double segment_length;

bool operator<(const IntersectionEdgeGeometry &other) const { return edge < other.edge; }
bool operator<(const IntersectionEdgeGeometry &other) const { return eid < other.eid; }
};

using IntersectionEdgeGeometries = std::vector<IntersectionEdgeGeometry>;
Expand Down
57 changes: 22 additions & 35 deletions include/extractor/intersection/intersection_view.hpp
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
#ifndef OSRM_EXTRACTOR_INTERSECTION_INTERSECTION_VIEW_HPP_
#define OSRM_EXTRACTOR_INTERSECTION_INTERSECTION_VIEW_HPP_

#include <algorithm>
#include <functional>
#include <limits>
#include <string>
#include <type_traits>
#include <vector>
#include "extractor/intersection/intersection_edge.hpp"

#include "guidance/turn_instruction.hpp"

#include "util/bearing.hpp"
#include "util/log.hpp"
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp" // EdgeID

#include "guidance/turn_instruction.hpp"

#include <boost/range/algorithm/count_if.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/algorithm/min_element.hpp>

#include <algorithm>
#include <functional>
#include <limits>
#include <string>
#include <type_traits>
#include <vector>

namespace osrm
{
namespace extractor
{
namespace intersection
{

// the shape of an intersection only knows about edge IDs and bearings
// `bearing` is the direction in clockwise angle from true north after taking the turn:
// 0 = heading north, 90 = east, 180 = south, 270 = west
struct IntersectionShapeData
{
EdgeID eid;
double bearing;
double segment_length;
};

inline auto makeCompareShapeDataByBearing(const double base_bearing)
{
return [base_bearing](const auto &lhs, const auto &rhs) {
return util::angularDeviation(lhs.bearing, base_bearing) <
util::angularDeviation(rhs.bearing, base_bearing);
};
}

inline auto makeCompareAngularDeviation(const double angle)
{
return [angle](const auto &lhs, const auto &rhs) {
Expand All @@ -60,12 +44,12 @@ inline auto makeExtractLanesForRoad(const util::NodeBasedDynamicGraph &node_base

// When viewing an intersection from an incoming edge, we can transform a shape into a view which
// gives additional information on angles and whether a turn is allowed
struct IntersectionViewData : IntersectionShapeData
struct IntersectionViewData : IntersectionEdgeGeometry
{
IntersectionViewData(const IntersectionShapeData &shape,
IntersectionViewData(const IntersectionEdgeGeometry &geometry,
const bool entry_allowed,
const double angle)
: IntersectionShapeData(shape), entry_allowed(entry_allowed), angle(angle)
: IntersectionEdgeGeometry(geometry), entry_allowed(entry_allowed), angle(angle)
{
}

Expand All @@ -80,10 +64,13 @@ struct IntersectionViewData : IntersectionShapeData
template <typename Self> struct EnableShapeOps
{
// same as closest turn, but for bearings
auto FindClosestBearing(double bearing) const
auto FindClosestBearing(double base_bearing) const
{
auto comp = makeCompareShapeDataByBearing(bearing);
return std::min_element(self()->begin(), self()->end(), comp);
return std::min_element(
self()->begin(), self()->end(), [base_bearing](const auto &lhs, const auto &rhs) {
return util::angularDeviation(lhs.perceived_bearing, base_bearing) <
util::angularDeviation(rhs.perceived_bearing, base_bearing);
});
}

// search a given eid in the intersection
Expand Down Expand Up @@ -119,10 +106,10 @@ template <typename Self> struct EnableShapeOps
auto self() const { return static_cast<const Self *>(this); }
};

struct IntersectionShape final : std::vector<IntersectionShapeData>, //
EnableShapeOps<IntersectionShape> //
struct IntersectionShape final : std::vector<IntersectionEdgeGeometry>, //
EnableShapeOps<IntersectionShape> //
{
using Base = std::vector<IntersectionShapeData>;
using Base = std::vector<IntersectionEdgeGeometry>;
};

// Common operations shared among IntersectionView and Intersections.
Expand Down
2 changes: 1 addition & 1 deletion include/extractor/intersection/mergable_road_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MergableRoadDetector
{
public:
// in case we have to change the mode we are operating on
using MergableRoadData = IntersectionShapeData;
using MergableRoadData = IntersectionEdgeGeometry;

MergableRoadDetector(const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container,
Expand Down
2 changes: 1 addition & 1 deletion include/guidance/intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ inline std::string toString(const ConnectedRoad &road)
result += " angle: ";
result += std::to_string(road.angle);
result += " bearing: ";
result += std::to_string(road.bearing);
result += std::to_string(road.perceived_bearing);
result += " instruction: ";
result += std::to_string(static_cast<std::int32_t>(road.instruction.type)) + " " +
std::to_string(static_cast<std::int32_t>(road.instruction.direction_modifier)) + " " +
Expand Down
2 changes: 1 addition & 1 deletion include/guidance/intersection_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge,
const auto turns_onto_through_street = [&](const auto &road) {
// find edge opposite to the one we are checking (in-road)
const auto in_through_candidate =
intersection.FindClosestBearing(util::bearing::reverse(road.bearing));
intersection.FindClosestBearing(util::bearing::reverse(road.perceived_bearing));

const auto &in_edge = node_based_graph.GetEdgeData(in_through_candidate->eid);
const auto &out_edge = node_based_graph.GetEdgeData(road.eid);
Expand Down
9 changes: 5 additions & 4 deletions include/util/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace guidance
inline std::ostream &operator<<(std::ostream &out, const ConnectedRoad &road)
{
out << "ConnectedRoad {" << road.eid << " allows entry: " << road.entry_allowed
<< " angle: " << road.angle << " bearing: " << road.bearing
<< " angle: " << road.angle << " bearing: " << road.perceived_bearing
<< " instruction: " << static_cast<std::int32_t>(road.instruction.type) << " "
<< static_cast<std::int32_t>(road.instruction.direction_modifier) << " "
<< static_cast<std::int32_t>(road.lane_data_id) << "}";
Expand All @@ -80,16 +80,17 @@ namespace extractor
{
namespace intersection
{
inline std::ostream &operator<<(std::ostream &out, const IntersectionShapeData &shape)
inline std::ostream &operator<<(std::ostream &out, const IntersectionEdgeGeometry &shape)
{
out << "IntersectionShapeData { " << shape.eid << " bearing: " << shape.bearing << "}";
out << "IntersectionEdgeGeometry { " << shape.eid << " bearing: " << shape.perceived_bearing
<< "}";
return out;
}

inline std::ostream &operator<<(std::ostream &out, const IntersectionViewData &view)
{
out << "IntersectionViewData {" << view.eid << " allows entry: " << view.entry_allowed
<< " angle: " << view.angle << " bearing: " << view.bearing << "}";
<< " angle: " << view.angle << " bearing: " << view.perceived_bearing << "}";
return out;
}
}
Expand Down
10 changes: 5 additions & 5 deletions include/util/to_osm_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "util/coordinate.hpp"

#include <iomanip>
#include <string>

namespace osrm
Expand All @@ -12,17 +13,16 @@ namespace util
inline std::string toOSMLink(const util::FloatCoordinate &c)
{
std::stringstream link;
link << "http://www.openstreetmap.org/?mlat=" << c.lat << "&mlon=" << c.lon << "#map=19/"
<< c.lat << "/" << c.lon;
link << "http://www.openstreetmap.org/?zoom=18&mlat=" << std::setprecision(10) << c.lat
<< "&mlon=" << c.lon;
return link.str();
}

inline std::string toOSMLink(const util::Coordinate &c)
{
std::stringstream link;
link << "http://www.openstreetmap.org/?mlat=" << toFloating(c.lat)
<< "&mlon=" << toFloating(c.lon) << "#map=19/" << toFloating(c.lat) << "/"
<< toFloating(c.lon);
link << "http://www.openstreetmap.org/?zoom=18&mlat=" << std::setprecision(10)
<< toFloating(c.lat) << "&mlon=" << toFloating(c.lon);
return link.str();
}
}
Expand Down
20 changes: 15 additions & 5 deletions profiles/lib/tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ function Tags.get_forward_backward_by_key(way,data,key)
local forward = way:get_value_by_key(key .. ':forward')
local backward = way:get_value_by_key(key .. ':backward')

if forward and backward then
return forward, backward
if not forward or not backward then
local common = way:get_value_by_key(key)

if (data.oneway) then
if data.is_forward_oneway then
forward = forward or common
end
if data.is_reverse_oneway then
backward = backward or common
end
else
forward = forward or common
backward = backward or common
end
end

local common = way:get_value_by_key(key)
return forward or common,
backward or common
return forward, backward
end

-- return [forward,backward] values, searching a
Expand Down
9 changes: 4 additions & 5 deletions src/extractor/intersection/coordinate_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate(
*/
const bool first_coordinate_is_far_away = [&first_distance, considered_lanes]() {
const auto required_distance =
considered_lanes * 0.5 * ASSUMED_LANE_WIDTH + LOOKAHEAD_DISTANCE_WITHOUT_LANES;
considered_lanes * ASSUMED_LANE_WIDTH + LOOKAHEAD_DISTANCE_WITHOUT_LANES;
return first_distance > required_distance;
}();

Expand All @@ -196,8 +196,7 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate(
}

// now, after the simple checks have succeeded make our further computations simpler
const auto lookahead_distance =
FAR_LOOKAHEAD_DISTANCE + considered_lanes * ASSUMED_LANE_WIDTH * 0.5;
const auto lookahead_distance = FAR_LOOKAHEAD_DISTANCE + considered_lanes * ASSUMED_LANE_WIDTH;

/*
* The coordinates along the road are in different distances from the source. If only very few
Expand Down Expand Up @@ -286,7 +285,7 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate(

const bool starts_of_without_turn = [&]() {
return straight_distance >=
considered_lanes * 0.5 * ASSUMED_LANE_WIDTH + LOOKAHEAD_DISTANCE_WITHOUT_LANES;
considered_lanes * ASSUMED_LANE_WIDTH + LOOKAHEAD_DISTANCE_WITHOUT_LANES;
}();

if (starts_of_without_turn)
Expand Down Expand Up @@ -355,7 +354,7 @@ util::Coordinate CoordinateExtractor::ExtractRepresentativeCoordinate(
if (IsCurve(coordinates,
segment_distances,
total_distance,
considered_lanes * 0.5 * ASSUMED_LANE_WIDTH,
considered_lanes * ASSUMED_LANE_WIDTH,
turn_edge_data))
{
if (total_distance <= skipping_inaccuracies_distance)
Expand Down
8 changes: 4 additions & 4 deletions src/extractor/intersection/intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ bool IntersectionViewData::CompareByAngle(const IntersectionViewData &other) con
return angle < other.angle;
}

std::string toString(const IntersectionShapeData &shape)
std::string toString(const IntersectionEdgeGeometry &shape)
{
std::string result =
"[shape] " + std::to_string(shape.eid) + " bearing: " + std::to_string(shape.bearing);
std::string result = "[shape] " + std::to_string(shape.eid) + " bearing: " +
std::to_string(shape.perceived_bearing);
return result;
}

Expand All @@ -35,7 +35,7 @@ std::string toString(const IntersectionViewData &view)
result += " angle: ";
result += std::to_string(view.angle);
result += " bearing: ";
result += std::to_string(view.bearing);
result += std::to_string(view.perceived_bearing);
return result;
}

Expand Down
Loading