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

access psv #3107

Merged
merged 10 commits into from
May 28, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* **Removed**
* **Bug Fix**
* FIXED: Fix heading on small edge [#3114](https://github.com/valhalla/valhalla/pull/3114)
* FIXED: Added support for `access=psv`, which disables routing on these nodes and edges unless the mode is taxi or bus [#3107](https://github.com/valhalla/valhalla/pull/3107)

* **Enhancement**

Expand Down
32 changes: 29 additions & 3 deletions lua/graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ access = {
["public"] = "true",
["restricted"] = "true",
["allowed"] = "true",
["emergency"] = "false"
["emergency"] = "false",
["psv"] = "false"
}

private = {
Expand Down Expand Up @@ -895,6 +896,14 @@ function filter_tags_generic(kv)
end
end

if kv["access"] == "psv" then
kv["taxi_forward"] = "true"
kv["taxi_tag"] = "true"

kv["bus_forward"] = "true"
kv["bus_tag"] = "true"
end

if kv["motorroad"] == "yes" then
kv["motorroad_tag"] = "true"
end
Expand Down Expand Up @@ -972,6 +981,14 @@ function filter_tags_generic(kv)
end
end

if kv["access"] == "psv" then
kv["taxi_forward"] = "true"
kv["taxi_tag"] = "true"

kv["bus_forward"] = "true"
kv["bus_tag"] = "true"
end

if kv["motorroad"] == "yes" then
kv["motorroad_tag"] = "true"
end
Expand Down Expand Up @@ -1685,7 +1702,17 @@ function nodes_proc (kv, nokeys)
if auto_tag == nil then
auto_tag = motor_vehicle_tag
end
local bus_tag = bus_node[kv["bus"]]
local bus_tag
local taxi_tag

if (kv["access"] == "psv") then
bus_tag = 64
taxi_tag = 32
else
bus_tag = bus_node[kv["bus"]]
taxi_tag = taxi_node[kv["taxi"]]
end

if bus_tag == nil then
bus_tag = psv_bus_node[kv["psv"]]
end
Expand All @@ -1704,7 +1731,6 @@ function nodes_proc (kv, nokeys)
hov_tag = 128
end

local taxi_tag = taxi_node[kv["taxi"]]
if taxi_tag == nil then
taxi_tag = psv_taxi_node[kv["psv"]]
end
Expand Down
9 changes: 9 additions & 0 deletions taginfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@
],
"description": "Overrides access flags for emergency vehicles. Emergency Routing is allowed."
},
{
"key": "access",
"value": "psv",
"object_types": [
"node",
"way"
],
"description": "Sets access to false for all modes except for taxis and buses"
},
{
"key": "admin_level",
"value": "2",
Expand Down
99 changes: 99 additions & 0 deletions test/gurka/test_access_psv.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "gurka.h"
#include <gtest/gtest.h>

#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif

using namespace valhalla;

const std::unordered_map<std::string, std::string> build_config{
{"mjolnir.admin", {VALHALLA_SOURCE_DIR "test/data/netherlands_admin.sqlite"}}};

const std::vector<std::string>& costing = {"auto", "hov", "taxi",
"bus", "truck", "bicycle",
"motor_scooter", "motorcycle", "pedestrian"};

TEST(Standalone, AccessPsvWay) {
constexpr double gridsize_metres = 10;

const std::string ascii_map = R"(

A---B---C---D---E
| |
F-------G
|
H
)";

const gurka::ways ways = {
{"AB", {{"highway", "primary"}}},
{"BC", {{"highway", "primary"}}},
{"CD", {{"highway", "primary"}}},
{"DE", {{"highway", "primary"}}},
{"EG", {{"highway", "primary"}}},
{"FG", {{"highway", "primary"}}},
{"CF",
{
{"highway", "primary"},
{"access", "psv"}, // access key wins over bus or taxi tag
{"bike", "no"},
{"bus", "no"},
}},
{"FH", {{"highway", "primary"}}},

};

const auto layout =
gurka::detail::map_to_coordinates(ascii_map, gridsize_metres, {5.1079374, 52.0887174});
auto map = gurka::buildtiles(layout, ways, {}, {}, "test/data/gurka_access_psv_way", build_config);
for (auto& c : costing) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "H"}, c);

if (c == "bus" || c == "taxi")
gurka::assert::raw::expect_path(result, {"AB", "BC", "CF", "FH"});
else
gurka::assert::raw::expect_path(result, {"AB", "BC", "CD", "DE", "EG", "FG", "FH"});
}
}

TEST(Standalone, AccessPsvNode) {
constexpr double gridsize_metres = 10;

const std::string ascii_map = R"(

A---B---C---D---E
| |
F |
| |
H-------G
)";

const gurka::ways ways = {
{"AB", {{"highway", "primary"}}}, {"BC", {{"highway", "primary"}}},
{"CD", {{"highway", "primary"}}}, {"DE", {{"highway", "primary"}}},
{"EG", {{"highway", "primary"}}}, {"HG", {{"highway", "primary"}}},
{"CF", {{"highway", "primary"}}}, {"FH", {{"highway", "primary"}}},

};

const gurka::nodes nodes = {{"F",
{
{"access", "psv"}, // access tag wins over bus or taxi tag
{"taxi", "no"},
{"bus", "no"},
}}};

const auto layout =
gurka::detail::map_to_coordinates(ascii_map, gridsize_metres, {5.1079374, 52.0887174});
auto map =
gurka::buildtiles(layout, ways, nodes, {}, "test/data/gurka_access_psv_way", build_config);
for (auto& c : costing) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "H"}, c);

if (c == "bus" || c == "taxi")
gurka::assert::raw::expect_path(result, {"AB", "BC", "CF", "FH"});
else
gurka::assert::raw::expect_path(result, {"AB", "BC", "CD", "DE", "EG", "HG"});
}
}