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

"soft" ignore restrictions #4606

Merged
merged 20 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -38,6 +38,7 @@
* FIXED: Aggregation updates: update opposing local idx after aggregating the edges, added classification check for aggregation, and shortcut length changes [#4570](https://github.com/valhalla/valhalla/pull/4570)
* FIXED: Use helper function for only parsing out names from DirectedEdge when populating intersecting edges [#4604](https://github.com/valhalla/valhalla/pull/4604)
* FIXED: Osmnode size reduction: Fixed excessive disk space for planet build [#4605](https://github.com/valhalla/valhalla/pull/4605)
* FIXED: Conflict with signinfo's temporary linguistic node sequence file caused test failures. [#4625](https://github.com/valhalla/valhalla/pull/4625)
* **Enhancement**
* UPDATED: French translations, thanks to @xlqian [#4159](https://github.com/valhalla/valhalla/pull/4159)
* CHANGED: -j flag for multithreaded executables to override mjolnir.concurrency [#4168](https://github.com/valhalla/valhalla/pull/4168)
Expand Down Expand Up @@ -96,7 +97,7 @@
* FIXED: Fixed roundoff issue in Tiles Row and Col methods [#4585](https://github.com/valhalla/valhalla/pull/4585)
* ADDED: isochrone proper polygon support & pbf output for isochrone [#4575](https://github.com/valhalla/valhalla/pull/4575)
* ADDED: return isotile grid as geotiff [#4594](https://github.com/valhalla/valhalla/pull/4594)
* FIXED: Conflict with signinfo's temporary linguistic node sequence file caused test failures. [#4625](https://github.com/valhalla/valhalla/pull/4625)
* ADDED: `ignore_non_vehicular_restrictions` parameter for truck costing [#4606](https://github.com/valhalla/valhalla/pull/4606)

## Release Date: 2023-05-11 Valhalla 3.4.0
* **Removed**
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/api/turn-by-turn/api-reference.md
Expand Up @@ -121,6 +121,10 @@ These options are available for `auto`, `bus`, and `truck` costing methods.
| `fixed_speed` | Fixed speed the vehicle can go. Used to override the calculated speed. Can be useful if speed of vehicle is known. `fixed_speed` must be between 1 and 252 KPH. The default value is 0 KPH which disables fixed speed and falls back to the standard calculated speed based on the road attribution. |
| `ignore_closures` | If set to `true`, ignores all closures, marked due to live traffic closures, during routing. **Note:** This option cannot be set if `location.search_filter.exclude_closures` is also specified in the request and will return an error if it is |
| `closure_factor` | A factor that penalizes the cost when traversing a closed edge (eg: if `search_filter.exclude_closures` is `false` for origin and/or destination location and the route starts/ends on closed edges). Its value can range from `1.0` - don't penalize closed edges, to `10.0` - apply high cost penalty to closed edges. Default value is `9.0`. **Note:** This factor is applicable only for motorized modes of transport, i.e `auto`, `motorcycle`, `motor_scooter`, `bus`, `truck` & `taxi`. |
| `ignore_restrictions` | If set to `true`, ignores any restrictions (e.g. turn/dimensional/conditional restrictions). Especially useful for matching GPS traces to the road network regardless of restrictions. Default is `false`. |
| `ignore_non_vehicular_restrictions` | Similar to `ignore_restrictions`, but will respect restrictions that impact vehicle safety, such as weight and size restrictions. |
| `ignore_access` | Will ignore mode-specific access tags. Especially useful for matching GPS traces to the road network regardless of restrictions. Default is `false`. |
| `ignore_closures` | Will ignore traffic closures. Default is `false`. |

###### Other costing options
The following options are available for `auto`, `bus`, `taxi`, and `truck` costing methods.
Expand Down
1 change: 1 addition & 0 deletions proto/options.proto
Expand Up @@ -312,6 +312,7 @@ message Costing {
uint32 axle_count = 81;
float use_lit = 82;
bool disable_hierarchy_pruning = 83;
bool ignore_non_vehicular_restrictions = 84;
}

oneof has_options {
Expand Down
8 changes: 4 additions & 4 deletions src/sif/autocost.cc
Expand Up @@ -421,7 +421,7 @@ bool AutoCost::Allowed(const baldr::DirectedEdge* edge,
// a not thru region and a heading selected an edge entering the
// region.
if (!IsAccessible(edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_restrictions_) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_turn_restrictions_) ||
edge->surface() == Surface::kImpassable || IsUserAvoidEdge(edgeid) ||
(!allow_destination_only_ && !pred.destonly() && edge->destonly()) ||
(pred.closure_pruning() && IsClosed(edge, tile)) ||
Expand All @@ -446,7 +446,7 @@ bool AutoCost::AllowedReverse(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(opp_edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_restrictions_) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_turn_restrictions_) ||
opp_edge->surface() == Surface::kImpassable || IsUserAvoidEdge(opp_edgeid) ||
(!allow_destination_only_ && !pred.destonly() && opp_edge->destonly()) ||
(pred.closure_pruning() && IsClosed(opp_edge, tile)) ||
Expand Down Expand Up @@ -808,7 +808,7 @@ bool BusCost::AllowedReverse(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(opp_edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_restrictions_) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_turn_restrictions_) ||
opp_edge->surface() == Surface::kImpassable || IsUserAvoidEdge(opp_edgeid) ||
(!allow_destination_only_ && !pred.destonly() && opp_edge->destonly()) ||
(pred.closure_pruning() && IsClosed(opp_edge, tile)) ||
Expand Down Expand Up @@ -987,7 +987,7 @@ bool TaxiCost::AllowedReverse(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(opp_edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_restrictions_) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_turn_restrictions_) ||
opp_edge->surface() == Surface::kImpassable || IsUserAvoidEdge(opp_edgeid) ||
(!allow_destination_only_ && !pred.destonly() && opp_edge->destonly()) ||
(pred.closure_pruning() && IsClosed(opp_edge, tile)) ||
Expand Down
4 changes: 2 additions & 2 deletions src/sif/bicyclecost.cc
Expand Up @@ -545,7 +545,7 @@ bool BicycleCost::Allowed(const baldr::DirectedEdge* edge,
if (!IsAccessible(edge) || edge->is_shortcut() ||
(!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx() &&
pred.mode() == TravelMode::kBicycle) ||
(!ignore_restrictions_ && (pred.restrictions() & (1 << edge->localedgeidx()))) ||
(!ignore_turn_restrictions_ && (pred.restrictions() & (1 << edge->localedgeidx()))) ||
IsUserAvoidEdge(edgeid)) {
return false;
}
Expand Down Expand Up @@ -582,7 +582,7 @@ bool BicycleCost::AllowedReverse(const baldr::DirectedEdge* edge,
opp_edge->use() == Use::kPlatformConnection ||
(!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx() &&
pred.mode() == TravelMode::kBicycle) ||
(!ignore_restrictions_ && (opp_edge->restrictions() & (1 << pred.opp_local_idx()))) ||
(!ignore_turn_restrictions_ && (opp_edge->restrictions() & (1 << pred.opp_local_idx()))) ||
IsUserAvoidEdge(opp_edgeid)) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/sif/dynamiccost.cc
Expand Up @@ -151,6 +151,9 @@ DynamicCost::DynamicCost(const Costing& costing,
closure_factor_(kDefaultClosureFactor), flow_mask_(kDefaultFlowMask),
shortest_(costing.options().shortest()),
ignore_restrictions_(costing.options().ignore_restrictions()),
ignore_non_vehicular_restrictions_(costing.options().ignore_non_vehicular_restrictions()),
ignore_turn_restrictions_(costing.options().ignore_restrictions() ||
costing.options().ignore_non_vehicular_restrictions()),
ignore_oneways_(costing.options().ignore_oneways()),
ignore_access_(costing.options().ignore_access()),
ignore_closures_(costing.options().ignore_closures()),
Expand Down Expand Up @@ -389,6 +392,8 @@ void ParseBaseCostOptions(const rapidjson::Value& json,
JSON_PBF_DEFAULT(co, false, json, "/ignore_oneways", ignore_oneways);
JSON_PBF_DEFAULT(co, false, json, "/ignore_access", ignore_access);
JSON_PBF_DEFAULT(co, false, json, "/ignore_closures", ignore_closures);
JSON_PBF_DEFAULT_V2(co, false, json, "/ignore_non_vehicular_restrictions",
ignore_non_vehicular_restrictions);

// shortest
JSON_PBF_DEFAULT(co, false, json, "/shortest", shortest);
Expand Down
4 changes: 2 additions & 2 deletions src/sif/motorcyclecost.cc
Expand Up @@ -355,7 +355,7 @@ bool MotorcycleCost::Allowed(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_restrictions_) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_turn_restrictions_) ||
(edge->surface() > kMinimumMotorcycleSurface) || IsUserAvoidEdge(edgeid) ||
(!allow_destination_only_ && !pred.destonly() && edge->destonly()) ||
(pred.closure_pruning() && IsClosed(edge, tile))) {
Expand All @@ -379,7 +379,7 @@ bool MotorcycleCost::AllowedReverse(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(opp_edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_restrictions_) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_turn_restrictions_) ||
(opp_edge->surface() > kMinimumMotorcycleSurface) || IsUserAvoidEdge(opp_edgeid) ||
(!allow_destination_only_ && !pred.destonly() && opp_edge->destonly()) ||
(pred.closure_pruning() && IsClosed(opp_edge, tile))) {
Expand Down
4 changes: 2 additions & 2 deletions src/sif/motorscootercost.cc
Expand Up @@ -376,7 +376,7 @@ bool MotorScooterCost::Allowed(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_restrictions_) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_turn_restrictions_) ||
(edge->surface() > kMinimumScooterSurface) || IsUserAvoidEdge(edgeid) ||
(!allow_destination_only_ && !pred.destonly() && edge->destonly()) ||
(pred.closure_pruning() && IsClosed(edge, tile))) {
Expand All @@ -400,7 +400,7 @@ bool MotorScooterCost::AllowedReverse(const baldr::DirectedEdge* edge,
// Check access, U-turn, and simple turn restriction.
// Allow U-turns at dead-end nodes.
if (!IsAccessible(opp_edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_restrictions_) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_turn_restrictions_) ||
(opp_edge->surface() > kMinimumScooterSurface) || IsUserAvoidEdge(opp_edgeid) ||
(!allow_destination_only_ && !pred.destonly() && opp_edge->destonly()) ||
(pred.closure_pruning() && IsClosed(opp_edge, tile))) {
Expand Down
4 changes: 2 additions & 2 deletions src/sif/truckcost.cc
Expand Up @@ -439,7 +439,7 @@ inline bool TruckCost::Allowed(const baldr::DirectedEdge* edge,
uint8_t& restriction_idx) const {
// Check access, U-turn, and simple turn restriction.
if (!IsAccessible(edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && !ignore_restrictions_) ||
((pred.restrictions() & (1 << edge->localedgeidx())) && (!ignore_turn_restrictions_)) ||
edge->surface() == Surface::kImpassable || IsUserAvoidEdge(edgeid) ||
(!allow_destination_only_ && !pred.destonly() && edge->destonly_hgv()) ||
(pred.closure_pruning() && IsClosed(edge, tile)) ||
Expand All @@ -463,7 +463,7 @@ bool TruckCost::AllowedReverse(const baldr::DirectedEdge* edge,
uint8_t& restriction_idx) const {
// Check access, U-turn, and simple turn restriction.
if (!IsAccessible(opp_edge) || (!pred.deadend() && pred.opp_local_idx() == edge->localedgeidx()) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_restrictions_) ||
((opp_edge->restrictions() & (1 << pred.opp_local_idx())) && !ignore_turn_restrictions_) ||
opp_edge->surface() == Surface::kImpassable || IsUserAvoidEdge(opp_edgeid) ||
(!allow_destination_only_ && !pred.destonly() && opp_edge->destonly_hgv()) ||
(pred.closure_pruning() && IsClosed(opp_edge, tile)) ||
Expand Down
2 changes: 2 additions & 0 deletions test/gurka/test_closure_penalty.cc
@@ -1,3 +1,5 @@
#include <boost/format.hpp>

#include "gurka.h"
#include "test.h"

Expand Down
5 changes: 3 additions & 2 deletions test/gurka/test_conditional_restrictions.cc
Expand Up @@ -97,8 +97,9 @@ class ConditionalRestrictions : public ::testing::Test {
};

const auto layout = gurka::detail::map_to_coordinates(ascii_map, grid_size_meters);
map = gurka::buildtiles(layout, ways, {}, {}, "test/data/conditional_restrictions",
{{"mjolnir.timezone", {"test/data/tz.sqlite"}}});
map = gurka::buildtiles(layout, ways, {}, {},
VALHALLA_BUILD_DIR "test/data/conditional_restrictions",
{{"mjolnir.timezone", {VALHALLA_BUILD_DIR "test/data/tz.sqlite"}}});
}
};

Expand Down