Skip to content

Commit

Permalink
Merge branch 'pedestrian_crossing' of https://github.com/abhi2039/val…
Browse files Browse the repository at this point in the history
…halla into pedestrian_crossing

* 'pedestrian_crossing' of https://github.com/abhi2039/valhalla:
  build: Bail with error if non-existant build-type specified (valhalla#2965)
  nit: Enables compiler warnings in part of mjolnir module (valhalla#2922)
  fix missing comma scripts/valhalla_build_config (valhalla#2963)
  Remove duplicate names being used across different gurka tests (valhalla#2962)
  Dont abort bidirectional a* search if only one direction is exhausted (valhalla#2936)
  penalize uturns at pencil points and short internal edges (valhalla#2944)
  Remove unused IsNextEdgeInternal function (valhalla#2958)
  restore compatibility with gcc 6.3.0, libprotobuf 3.0.0, boost v1.62.0 (valhalla#2953)
  Add ability to build Valhalla modules as STATIC libraries (valhalla#2957)
  Allow disabling Werror (valhalla#2937)
  Enhanced logic for IsTurnChannelManeuverCombinable (valhalla#2952)
  Allow config object to be passed-in to path algorithms (valhalla#2949)
  Floating-point precision fix in meili::Project() fixes map-match issue (valhalla#2946)
  Use kServiceRoad edges while reclassifying ferry connections (valhalla#2933)
  ci: Update cache key to trigger clearing it (valhalla#2947)
  • Loading branch information
aabhishek3983 committed Mar 30, 2021
2 parents caad5e3 + d9dde6f commit 7f6cd1c
Show file tree
Hide file tree
Showing 83 changed files with 2,003 additions and 451 deletions.
6 changes: 3 additions & 3 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
- task: Cache@2
displayName: "Cache build"
inputs:
key: 'build | "$(Build.SourceBranch)"'
key: '"msvc-v16.9.0" | build | "$(Build.SourceBranch)"'
path: "$(BUILD_DIR)"
restoreKeys: |
build | "$(Build.SourceBranch)"
build
"msvc-v16.9.0" | build | "$(Build.SourceBranch)"
"msvc-v16.9.0" | build
cacheHitVar: BUILD_CACHE_RESTORED

- task: UsePythonVersion@0
Expand Down
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ jobs:
-DENABLE_COMPILER_WARNINGS=On -DENABLE_WERROR=Off -DCMAKE_EXPORT_COMPILE_COMMANDS=On \
-DCMAKE_CXX_FLAGS="-fuse-ld=lld" \
-DENABLE_PYTHON_BINDINGS=On
- run: python3 ./scripts/valhalla_build_config
- run: make -C build -j3
- run: make -C build utrecht_tiles
- run: make -C build -j2 tests
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
* FIXED: Skip bindings if there's no Python development version [#2893](https://github.com/valhalla/valhalla/pull/2878)
* FIXED: Use CMakes built-in Python variables to configure installation [#2931](https://github.com/valhalla/valhalla/pull/2931)
* FIXED: Sometimes emitting zero-length route geometry when traffic splits edge twice [#2943](https://github.com/valhalla/valhalla/pull/2943)
* FIXED: Fix map-match segfault when gps-points project very near a node [#2946](https://github.com/valhalla/valhalla/pull/2946)
* FIXED: Use kServiceRoad edges while searching for ferry connection [#2933](https://github.com/valhalla/valhalla/pull/2933)
* FIXED: Enhanced logic for IsTurnChannelManeuverCombinable [#2952](https://github.com/valhalla/valhalla/pull/2952)
* FIXED: Restore compatibility with gcc 6.3.0, libprotobuf 3.0.0, boost v1.62.0 [#2953](https://github.com/valhalla/valhalla/pull/2953)
* FIXED: Dont abort bidirectional a-star search if only one direction is exhausted [#2936](https://github.com/valhalla/valhalla/pull/2936)
* FIXED: Fixed missing comma in the scripts/valhalla_build_config [#2963](https://github.com/valhalla/valhalla/pull/2963)

* **Enhancement**
* Pedestrian crossing should be a separate TripLeg_Use [#2950](https://github.com/valhalla/valhalla/pull/2950)
Expand Down Expand Up @@ -54,6 +60,11 @@
* ADDED: Status endpoint for future status info and health checking of running service [#2907](https://github.com/valhalla/valhalla/pull/2907)
* ADDED: Add min_level argument to valhalla_ways_to_edges [#2918](https://github.com/valhalla/valhalla/pull/2918)
* ADDED: Adding ability to store the roundabout_exit_turn_degree to the maneuver [#2941](https://github.com/valhalla/valhalla/pull/2941)
* ADDED: Penalize pencil point uturns and uturns at short internal edges. Note: `motorcycle` and `motor_scooter` models do not penalize on short internal edges. No new uturn penalty logic has been added to the pedestrian and bicycle costing models. [#2944](https://github.com/valhalla/valhalla/pull/2944)
* CHANGED: Allow config object to be passed-in to path algorithms [#2949](https://github.com/valhalla/valhalla/pull/2949)
* CHANGED: Allow disabling Werror
* ADDED: Add ability to build Valhalla modules as STATIC libraries. [#2957](https://github.com/valhalla/valhalla/pull/2957)
* NIT: Enables compiler warnings in part of mjolnir module [#2922](https://github.com/valhalla/valhalla/pull/2922)

## Release Date: 2021-01-25 Valhalla 3.1.0
* **Removed**
Expand Down
15 changes: 9 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ option(ENABLE_TESTS "Enable Valhalla tests" ON)
option(ENABLE_WERROR "Convert compiler warnings to errors. Requires ENABLE_COMPILER_WARNINGS=ON to take effect" OFF)
option(ENABLE_BENCHMARKS "Enable microbenchmarking" ON)
option(ENABLE_THREAD_SAFE_TILE_REF_COUNT "If ON tiles reference counters are thread safe" OFF)

option(ENABLE_SINGLE_FILES_WERROR "Convert compiler warnings to errors for single files" ON)
# useful to workaround issues likes this https://stackoverflow.com/questions/24078873/cmake-generated-xcode-project-wont-compile
option(ENABLE_STATIC_LIBRARY_MODULES "If ON builds Valhalla modules as STATIC library targets" OFF)

set(LOGGING_LEVEL "" CACHE STRING "Logging level, default is INFO")
set_property(CACHE LOGGING_LEVEL PROPERTY STRINGS "NONE;ALL;ERROR;WARN;INFO;DEBUG;TRACE")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand Down Expand Up @@ -68,16 +71,16 @@ if(NOT MSVC_IDE) # TODO: May need to be extended for Xcode, CLion, etc.
endif()
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
message(STATUS "Configuring in debug mode")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
message(STATUS "Configuring in release mode")
elseif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
message(STATUS "Configuring in release mode with debug flags")
elseif(CMAKE_BUILD_TYPE MATCHES MinRelSize)
elseif(CMAKE_BUILD_TYPE STREQUAL MinRelSize)
message(STATUS "Configuring in release mode with minimized size")
else()
message(STATUS "Unrecognized build type - will use cmake defaults")
message(FATAL_ERROR "Unrecognized build type. Use one of Debug, Release, RelWithDebInfo, MinRelSize")
endif()

function(create_source_groups prefix)
Expand Down
6 changes: 4 additions & 2 deletions scripts/valhalla_build_config
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ config = {
'service': {
'proxy': 'ipc:///tmp/thor'
},
'max_reserved_labels_count': 1000000
'max_reserved_labels_count': 1000000,
'extended_search': False
},
'odin': {
'logging': {
Expand Down Expand Up @@ -354,7 +355,8 @@ help_text = {
'service': {
'proxy': 'IPC linux domain socket file location'
},
'max_reserved_labels_count': 'Maximum capacity that allowed to keep reserved in path algorithm.'
'max_reserved_labels_count': 'Maximum capacity for edge labels reserved in path algorithm',
'extended_search': 'If True and 1 side of the bidirectional search is exhausted, causes the other side to continue if the starting location of that side began on a not_thru or closed edge'
},
'odin': {
'logging': {
Expand Down
16 changes: 12 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ function(valhalla_module)
cmake_parse_arguments(MODULE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set(library valhalla-${MODULE_NAME})
add_library(${library} OBJECT ${MODULE_SOURCES} ${MODULE_HEADERS})
if (ENABLE_STATIC_LIBRARY_MODULES)
add_library(${library} STATIC ${MODULE_SOURCES} ${MODULE_HEADERS})
else()
add_library(${library} OBJECT ${MODULE_SOURCES} ${MODULE_HEADERS})
endif()
add_library(valhalla::${MODULE_NAME} ALIAS ${library})
set_target_properties(${library} PROPERTIES FOLDER "Modules")

Expand Down Expand Up @@ -136,8 +140,12 @@ function(valhalla_module)
set(libvalhalla_compile_definitions "${libvalhalla_compile_definitions};$<TARGET_PROPERTY:${library},COMPILE_DEFINITIONS>" CACHE INTERNAL "")
set(libvalhalla_compile_options "${libvalhalla_compile_options};$<TARGET_PROPERTY:${library},COMPILE_OPTIONS>" CACHE INTERNAL "")
set(libvalhalla_include_directories "${libvalhalla_include_directories};$<TARGET_PROPERTY:${library},INCLUDE_DIRECTORIES>" CACHE INTERNAL "")
set(libvalhalla_link_objects "${libvalhalla_link_objects};$<TARGET_OBJECTS:${library}>" CACHE INTERNAL "")
set(libvalhalla_link_libraries "${libvalhalla_link_libraries};${external_module_depends}" CACHE INTERNAL "")
if (ENABLE_STATIC_LIBRARY_MODULES)
set(libvalhalla_link_libraries "${libvalhalla_link_libraries};${external_module_depends};${library}" CACHE INTERNAL "")
else()
set(libvalhalla_link_objects "${libvalhalla_link_objects};$<TARGET_OBJECTS:${library}>" CACHE INTERNAL "")
set(libvalhalla_link_libraries "${libvalhalla_link_libraries};${external_module_depends}" CACHE INTERNAL "")
endif()
endfunction()

add_subdirectory(${VALHALLA_SOURCE_DIR}/third_party/robin-hood-hashing ${CMAKE_BINARY_DIR}/third_party/robin-hood-hashing)
Expand Down Expand Up @@ -175,7 +183,7 @@ set(valhalla_src
${valhalla_hdrs}
${libvalhalla_link_objects})

if (UNIX)
if (UNIX AND ENABLE_SINGLE_FILES_WERROR)
# Enables stricter compiler checks on a file-by-file basis
# which allows us to migrate piecemeal
set_source_files_properties(proto_conversions.cc PROPERTIES COMPILE_FLAGS "-Wall -Werror")
Expand Down
2 changes: 1 addition & 1 deletion src/baldr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ list(APPEND sources
${CMAKE_CURRENT_BINARY_DIR}/date_time_windows_zones.h
tz_alt.cpp)

if (UNIX)
if (UNIX AND ENABLE_SINGLE_FILES_WERROR)
# Enables stricter compiler checks on a file-by-file basis
# which allows us to migrate piecemeal
set_source_files_properties(openlr.cc PROPERTIES COMPILE_FLAGS "-Werror")
Expand Down
2 changes: 1 addition & 1 deletion src/loki/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(sources
node_search.cc
polygon_search.cc)

if (UNIX AND NOT APPLE)
if (UNIX AND NOT APPLE AND ENABLE_SINGLE_FILES_WERROR)
# Enables stricter compiler checks on a file-by-file basis
# which allows us to migrate piecemeal
set_source_files_properties(
Expand Down
2 changes: 0 additions & 2 deletions src/loki/polygon_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ ring_bg_t PBFToRing(const valhalla::Options::Ring& ring_pbf) {
for (const auto& coord : ring_pbf.coords()) {
new_ring.push_back({coord.lng(), coord.lat()});
}
// corrects geometry and handedness as expected by bg for rings
bg::correct(new_ring);
return new_ring;
}

Expand Down
1 change: 1 addition & 0 deletions src/meili/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(sources
topk_search.cc
routing.cc
candidate_search.cc
geometry_helpers.cc
transition_cost_model.cc
map_matcher.cc
map_matcher_factory.cc
Expand Down
16 changes: 8 additions & 8 deletions src/meili/candidate_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ CandidateCollector::WithinSquaredDistance(const midgard::PointLL& location,

// Projection information
midgard::PointLL point;
float sq_distance = 0.f;
double sq_distance = 0.0;
size_t segment;
float offset;
double offset;

baldr::GraphId snapped_node;
baldr::PathLocation correlated(baldr::Location(location, stop_type));
Expand All @@ -81,10 +81,10 @@ CandidateCollector::WithinSquaredDistance(const midgard::PointLL& location,
std::tie(point, sq_distance, segment, offset) = helpers::Project(projector, shape);

if (sq_distance <= sq_search_radius) {
const float dist = edge->forward() ? offset : 1.f - offset;
if (dist == 1.f) {
const double dist = edge->forward() ? offset : 1.0 - offset;
if (dist == 1.0) {
snapped_node = edge->endnode();
} else if (dist == 0.f) {
} else if (dist == 0.0) {
snapped_node = opp_edge->endnode();
}
correlated.edges.emplace_back(edgeid, dist, point, sq_distance);
Expand All @@ -100,10 +100,10 @@ CandidateCollector::WithinSquaredDistance(const midgard::PointLL& location,
std::tie(point, sq_distance, segment, offset) = helpers::Project(projector, shape);
}
if (sq_distance <= sq_search_radius) {
const float dist = opp_edge->forward() ? offset : 1.f - offset;
if (dist == 1.f) {
const double dist = opp_edge->forward() ? offset : 1.0 - offset;
if (dist == 1.0) {
snapped_node = opp_edge->endnode();
} else if (dist == 0.f) {
} else if (dist == 0.0) {
snapped_node = edge->endnode();
}
correlated.edges.emplace_back(opp_edgeid, dist, point, sq_distance);
Expand Down
101 changes: 101 additions & 0 deletions src/meili/geometry_helpers.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "meili/geometry_helpers.h"

#include <valhalla/midgard/constants.h>
#include <valhalla/midgard/distanceapproximator.h>
#include <valhalla/midgard/encoded.h>
#include <valhalla/midgard/pointll.h>
#include <valhalla/midgard/util.h>

using namespace valhalla;
using namespace valhalla::meili;
using namespace valhalla::midgard;

namespace valhalla {
namespace meili {
namespace helpers {

// snapped point, squared distance, segment index, offset
std::tuple<PointLL, double, typename std::vector<PointLL>::size_type, double>
Project(const projector_t& p, Shape7Decoder<midgard::PointLL>& shape, double snap_distance) {
PointLL first_point(shape.pop());
auto closest_point = first_point;
auto closest_segment_point = first_point;
double closest_distance = std::numeric_limits<double>::max();
size_t closest_segment = 0;
double closest_partial_length = 0.0;
double total_length = 0.0;

// for each segment
auto u = first_point;
size_t i = 0;
for (; !shape.empty(); ++i) {
// project a onto b where b is the origin vector representing this segment
// and a is the origin vector to the point we are projecting, (a.b/b.b)*b
auto v = shape.pop();

auto projection = p(u, v);

// check if this point is better
const auto distance = p.approx.DistanceSquared(projection);
if (distance < closest_distance) {
closest_point = std::move(projection);
closest_distance = distance;
closest_segment = i;
closest_partial_length = total_length;
closest_segment_point = u;
}

// total edge length
total_length += u.Distance(v);
u = v;
}

// percent_along is a double between 0 and 1 representing the location of
// the closest point on LineString to the given Point, as a fraction
// of total 2d line length.
closest_partial_length += closest_segment_point.Distance(closest_point);
double percent_along =
total_length > 0.0 ? static_cast<double>(closest_partial_length / total_length) : 0.0;

// Not so much "snapping" as recognizing that floating-point has limited precision.
// For example:
// double k = 1e-18; // valid
// double r = 1.0 - k; // sure why not
// Result: r == 1.0 // exactly 1.0?! yep.
//
// Downstream logic looks at percentages along the edge and the opp-edge. We want to be
// sure that values very close to 0.0 snap to 0.0 since downstream math may flip this
// percentage_along to (1.0-percentage_along) if the the edge is not forward, making it
// exactly 1.0. This causes issues because the percentage_along the opp_edge is not
// exactly 0.0, which is not expected.
//
// double has ~16 decimal digits of precision. Hence, we will consider 1e-15 as our
// representative small figure, below which we snap to 0.0 and within that distance
// of 1.0 will snap to 1.0.
constexpr double double_precision_at_one = 1e-15;
constexpr double very_close_to_one = 1.0 - double_precision_at_one;
if (percent_along < double_precision_at_one) {
percent_along = 0.0;
} else if (percent_along > very_close_to_one) {
percent_along = 1.0;
}

// Snap to nearest node using snap_distance
if (total_length * percent_along <= snap_distance) {
closest_point = first_point;
closest_distance = p.approx.DistanceSquared(closest_point);
closest_segment = 0;
percent_along = 0.f;
} else if (total_length * (1.f - percent_along) <= snap_distance) {
closest_point = u;
closest_distance = p.approx.DistanceSquared(closest_point);
closest_segment = i - 1;
percent_along = 1.f;
}

return std::make_tuple(std::move(closest_point), closest_distance, closest_segment, percent_along);
}

} // namespace helpers
} // namespace meili
} // namespace valhalla
13 changes: 10 additions & 3 deletions src/meili/match_route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,22 @@ void cut_segments(const std::vector<MatchResult>& match_results,
if (!curr_match.is_break_point && curr_idx != last_idx) {
continue;
}

// Allow for some fp-fuzz in this gt comparison
bool prev_gt_curr = prev_match.distance_along > curr_match.distance_along + 1e-3;

// we want to handle to loop by locating the correct target edge by comparing the distance alone
bool loop = prev_match.edgeid == curr_match.edgeid &&
prev_match.distance_along > curr_match.distance_along;
bool loop = (prev_match.edgeid == curr_match.edgeid) && prev_gt_curr;

// if it is a loop, we start the search after the first edge
auto last_segment = std::find_if(first_segment + static_cast<size_t>(loop), segments.end(),
[&curr_match](const EdgeSegment& segment) {
return (segment.edgeid == curr_match.edgeid);
});
assert(last_segment != segments.cend());

if (last_segment == segments.cend()) {
throw std::logic_error("In meili::cutsegments(), unexpectedly unable to locate target edge.");
}

// we need to close the previous edge
size_t old_size = new_segments.size();
Expand Down
12 changes: 12 additions & 0 deletions src/mjolnir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/graph_lua_proc.h

file(GLOB headers ${VALHALLA_SOURCE_DIR}/valhalla/mjolnir/*.h)

if (UNIX)
# Enables stricter compiler checks on a file-by-file basis
# which allows us to migrate piecemeal
set_source_files_properties(
graphenhancer.cc
hierarchybuilder.cc
luatagtransform.cc
osmdata.cc
osmrestriction.cc
PROPERTIES COMPILE_FLAGS "-Werror -Wall")
endif (UNIX)

set(sources
${CMAKE_CURRENT_BINARY_DIR}/graph_lua_proc.h
${CMAKE_CURRENT_BINARY_DIR}/admin_lua_proc.h
Expand Down
2 changes: 1 addition & 1 deletion src/mjolnir/ferry_connections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ uint32_t ShortestPath(const uint32_t start_node_idx,

// Skip uses other than road / other (service?)
const OSMWay w = *ways[edge.wayindex_];
if (w.use() != baldr::Use::kOther &&
if (w.use() != baldr::Use::kOther && w.use() != baldr::Use::kServiceRoad &&
static_cast<int>(w.use()) > static_cast<int>(baldr::Use::kTurnChannel)) {
continue;
}
Expand Down
Loading

0 comments on commit 7f6cd1c

Please sign in to comment.