diff --git a/routing_common/bicycle_model.cpp b/routing_common/bicycle_model.cpp index 17ee98c27b..17c1f940a6 100644 --- a/routing_common/bicycle_model.cpp +++ b/routing_common/bicycle_model.cpp @@ -53,7 +53,7 @@ double constexpr kSpeedOffroadKMpH = 3.0; double constexpr kSpeedFerry = 3.0; // Default -VehicleModel::InitListT const g_bicycleLimitsDefault = +VehicleModel::LimitsInitList const g_bicycleLimitsDefault = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true /* passThroughAllowed */ }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -76,7 +76,7 @@ VehicleModel::InitListT const g_bicycleLimitsDefault = }; // All options available. -VehicleModel::InitListT const g_bicycleLimitsAll = +VehicleModel::LimitsInitList const g_bicycleLimitsAll = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -102,7 +102,7 @@ VehicleModel::InitListT const g_bicycleLimitsAll = }; // Same as defaults except trunk and trunk_link are not allowed -VehicleModel::InitListT const g_bicycleLimitsNoTrunk = +VehicleModel::LimitsInitList const g_bicycleLimitsNoTrunk = { { {"highway", "primary"}, kSpeedPrimaryKMpH, true }, { {"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true }, @@ -123,7 +123,7 @@ VehicleModel::InitListT const g_bicycleLimitsNoTrunk = }; // Same as defaults except pedestrian is allowed -VehicleModel::InitListT const g_bicycleLimitsPedestrianAllowed = +VehicleModel::LimitsInitList const g_bicycleLimitsPedestrianAllowed = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -147,7 +147,7 @@ VehicleModel::InitListT const g_bicycleLimitsPedestrianAllowed = }; // Same as defaults except bridleway is allowed -VehicleModel::InitListT const g_bicycleLimitsBridlewayAllowed = +VehicleModel::LimitsInitList const g_bicycleLimitsBridlewayAllowed = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -171,10 +171,10 @@ VehicleModel::InitListT const g_bicycleLimitsBridlewayAllowed = }; // Australia -VehicleModel::InitListT const g_bicycleLimitsAustralia = g_bicycleLimitsAll; +VehicleModel::LimitsInitList const g_bicycleLimitsAustralia = g_bicycleLimitsAll; // Austria -VehicleModel::InitListT const g_bicycleLimitsAustria = +VehicleModel::LimitsInitList const g_bicycleLimitsAustria = { // No trunk, trunk_link, path { {"highway", "primary"}, kSpeedPrimaryKMpH, true }, @@ -195,7 +195,7 @@ VehicleModel::InitListT const g_bicycleLimitsAustria = }; // Belarus -VehicleModel::InitListT const g_bicycleLimitsBelarus = +VehicleModel::LimitsInitList const g_bicycleLimitsBelarus = { // Footway and pedestrian are allowed { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, @@ -221,7 +221,7 @@ VehicleModel::InitListT const g_bicycleLimitsBelarus = }; // Belgium -VehicleModel::InitListT const g_bicycleLimitsBelgium = +VehicleModel::LimitsInitList const g_bicycleLimitsBelgium = { // No trunk, trunk_link // Pedestrian is allowed @@ -245,7 +245,7 @@ VehicleModel::InitListT const g_bicycleLimitsBelgium = }; // Brazil -VehicleModel::InitListT const g_bicycleLimitsBrazil = +VehicleModel::LimitsInitList const g_bicycleLimitsBrazil = { // Bridleway and fotway are allowed { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, @@ -271,10 +271,10 @@ VehicleModel::InitListT const g_bicycleLimitsBrazil = }; // Denmark -VehicleModel::InitListT const g_bicycleLimitsDenmark = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsDenmark = g_bicycleLimitsNoTrunk; // France -VehicleModel::InitListT const g_bicycleLimitsFrance = +VehicleModel::LimitsInitList const g_bicycleLimitsFrance = { // No trunk, trunk_link // Pedestrian is allowed @@ -298,34 +298,34 @@ VehicleModel::InitListT const g_bicycleLimitsFrance = }; // Finland -VehicleModel::InitListT const g_bicycleLimitsFinland = g_bicycleLimitsPedestrianAllowed; +VehicleModel::LimitsInitList const g_bicycleLimitsFinland = g_bicycleLimitsPedestrianAllowed; // Germany -VehicleModel::InitListT const g_bicycleLimitsGermany = g_bicycleLimitsDefault; +VehicleModel::LimitsInitList const g_bicycleLimitsGermany = g_bicycleLimitsDefault; // Hungary -VehicleModel::InitListT const g_bicycleLimitsHungary = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsHungary = g_bicycleLimitsNoTrunk; // Iceland -VehicleModel::InitListT const g_bicycleLimitsIceland = g_bicycleLimitsAll; +VehicleModel::LimitsInitList const g_bicycleLimitsIceland = g_bicycleLimitsAll; // Netherlands -VehicleModel::InitListT const g_bicycleLimitsNetherlands = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsNetherlands = g_bicycleLimitsNoTrunk; // Norway -VehicleModel::InitListT const g_bicycleLimitsNorway = g_bicycleLimitsAll; +VehicleModel::LimitsInitList const g_bicycleLimitsNorway = g_bicycleLimitsAll; // Oman -VehicleModel::InitListT const g_bicycleLimitsOman = g_bicycleLimitsBridlewayAllowed; +VehicleModel::LimitsInitList const g_bicycleLimitsOman = g_bicycleLimitsBridlewayAllowed; // Poland -VehicleModel::InitListT const g_bicycleLimitsPoland = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsPoland = g_bicycleLimitsNoTrunk; // Romania -VehicleModel::InitListT const g_bicycleLimitsRomania = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsRomania = g_bicycleLimitsNoTrunk; // Russian Federation -VehicleModel::InitListT const g_bicycleLimitsRussia = +VehicleModel::LimitsInitList const g_bicycleLimitsRussia = { // Footway and pedestrian are allowed // No pass through service and living_street @@ -352,19 +352,19 @@ VehicleModel::InitListT const g_bicycleLimitsRussia = }; // Slovakia -VehicleModel::InitListT const g_bicycleLimitsSlovakia = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsSlovakia = g_bicycleLimitsNoTrunk; // Spain -VehicleModel::InitListT const g_bicycleLimitsSpain = g_bicycleLimitsPedestrianAllowed; +VehicleModel::LimitsInitList const g_bicycleLimitsSpain = g_bicycleLimitsPedestrianAllowed; // Switzerland -VehicleModel::InitListT const g_bicycleLimitsSwitzerland = g_bicycleLimitsNoTrunk; +VehicleModel::LimitsInitList const g_bicycleLimitsSwitzerland = g_bicycleLimitsNoTrunk; // Turkey -VehicleModel::InitListT const g_bicycleLimitsTurkey = g_bicycleLimitsDefault; +VehicleModel::LimitsInitList const g_bicycleLimitsTurkey = g_bicycleLimitsDefault; // Ukraine -VehicleModel::InitListT const g_bicycleLimitsUkraine = +VehicleModel::LimitsInitList const g_bicycleLimitsUkraine = { // No trunk // Footway and perestrian are allowed @@ -390,10 +390,10 @@ VehicleModel::InitListT const g_bicycleLimitsUkraine = }; // United Kingdom -VehicleModel::InitListT const g_bicycleLimitsUK = g_bicycleLimitsBridlewayAllowed; +VehicleModel::LimitsInitList const g_bicycleLimitsUK = g_bicycleLimitsBridlewayAllowed; // United States of America -VehicleModel::InitListT const g_bicycleLimitsUS = +VehicleModel::LimitsInitList const g_bicycleLimitsUS = { // Bridleway and pedesprian are allowed { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, @@ -418,14 +418,23 @@ VehicleModel::InitListT const g_bicycleLimitsUS = { {"highway", "platform"}, kSpeedPlatformKMpH, true }, }; +VehicleModel::SurfaceInitList const g_bicycleSurface = { + {{"psurface", "paved_good"}, 1.0}, + {{"psurface", "paved_bad"}, 0.8}, + {{"psurface", "unpaved_good"}, 1.0}, + {{"psurface", "unpaved_bad"}, 0.6}, +}; } // namespace namespace routing { -BicycleModel::BicycleModel() : VehicleModel(classif(), g_bicycleLimitsDefault) { Init(); } +BicycleModel::BicycleModel() : VehicleModel(classif(), g_bicycleLimitsDefault, g_bicycleSurface) +{ + Init(); +} -BicycleModel::BicycleModel(VehicleModel::InitListT const & speedLimits) - : VehicleModel(classif(), speedLimits) +BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & speedLimits) + : VehicleModel(classif(), speedLimits, g_bicycleSurface) { Init(); } diff --git a/routing_common/bicycle_model.hpp b/routing_common/bicycle_model.hpp index be8bf532d5..8c3aab5b2a 100644 --- a/routing_common/bicycle_model.hpp +++ b/routing_common/bicycle_model.hpp @@ -9,7 +9,7 @@ class BicycleModel : public VehicleModel { public: BicycleModel(); - BicycleModel(VehicleModel::InitListT const & speedLimits); + BicycleModel(VehicleModel::LimitsInitList const & speedLimits); /// VehicleModelInterface overrides: bool IsOneWay(FeatureType const & f) const override; diff --git a/routing_common/car_model.cpp b/routing_common/car_model.cpp index 34e05c7d82..7017487667 100644 --- a/routing_common/car_model.cpp +++ b/routing_common/car_model.cpp @@ -40,7 +40,7 @@ double constexpr kSpeedShuttleTrainKMpH = 25.0; double constexpr kSpeedPierKMpH = 10.0; double constexpr kSpeedOffroadKMpH = 10.0; -VehicleModel::InitListT const g_carLimitsDefault = +VehicleModel::LimitsInitList const g_carLimitsDefault = { {{"highway", "motorway"}, kSpeedMotorwayKMpH, true /* passThroughAllowed */ }, {{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true}, @@ -66,7 +66,7 @@ VehicleModel::InitListT const g_carLimitsDefault = //{ {"highway", "construction"}, 40 }, }; -VehicleModel::InitListT const g_carLimitsNoPassThroughLivingStreet = +VehicleModel::LimitsInitList const g_carLimitsNoPassThroughLivingStreet = { {{"highway", "motorway"}, kSpeedMotorwayKMpH, true}, {{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true}, @@ -86,7 +86,7 @@ VehicleModel::InitListT const g_carLimitsNoPassThroughLivingStreet = {{"highway", "track"}, kSpeedTrackKMpH, true}, }; -VehicleModel::InitListT const g_carLimitsNoPassThroughLivingStreetAndService = +VehicleModel::LimitsInitList const g_carLimitsNoPassThroughLivingStreetAndService = { {{"highway", "motorway"}, kSpeedMotorwayKMpH, true}, {{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true}, @@ -106,17 +106,17 @@ VehicleModel::InitListT const g_carLimitsNoPassThroughLivingStreetAndService = {{"highway", "track"}, kSpeedTrackKMpH, true}, }; -VehicleModel::InitListT const g_carLimitsAustralia = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsAustralia = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsAustria = g_carLimitsNoPassThroughLivingStreet; +VehicleModel::LimitsInitList const g_carLimitsAustria = g_carLimitsNoPassThroughLivingStreet; -VehicleModel::InitListT const g_carLimitsBelarus = g_carLimitsNoPassThroughLivingStreet; +VehicleModel::LimitsInitList const g_carLimitsBelarus = g_carLimitsNoPassThroughLivingStreet; -VehicleModel::InitListT const g_carLimitsBelgium = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsBelgium = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsBrazil = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsBrazil = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsDenmark = +VehicleModel::LimitsInitList const g_carLimitsDenmark = { // No track {{"highway", "motorway"}, kSpeedMotorwayKMpH, true}, @@ -136,11 +136,11 @@ VehicleModel::InitListT const g_carLimitsDenmark = {{"highway", "road"}, kSpeedRoadKMpH, true}, }; -VehicleModel::InitListT const g_carLimitsFrance = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsFrance = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsFinland = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsFinland = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsGermany = +VehicleModel::LimitsInitList const g_carLimitsGermany = { // No pass through track {{"highway", "motorway"}, kSpeedMotorwayKMpH, true}, @@ -161,35 +161,35 @@ VehicleModel::InitListT const g_carLimitsGermany = {{"highway", "track"}, kSpeedTrackKMpH, false}, }; -VehicleModel::InitListT const g_carLimitsHungary = g_carLimitsNoPassThroughLivingStreet; +VehicleModel::LimitsInitList const g_carLimitsHungary = g_carLimitsNoPassThroughLivingStreet; -VehicleModel::InitListT const g_carLimitsIceland = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsIceland = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsNetherlands = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsNetherlands = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsNorway = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsNorway = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsOman = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsOman = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsPoland = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsPoland = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsRomania = g_carLimitsNoPassThroughLivingStreet; +VehicleModel::LimitsInitList const g_carLimitsRomania = g_carLimitsNoPassThroughLivingStreet; -VehicleModel::InitListT const g_carLimitsRussia = g_carLimitsNoPassThroughLivingStreetAndService; +VehicleModel::LimitsInitList const g_carLimitsRussia = g_carLimitsNoPassThroughLivingStreetAndService; -VehicleModel::InitListT const g_carLimitsSlovakia = g_carLimitsNoPassThroughLivingStreet; +VehicleModel::LimitsInitList const g_carLimitsSlovakia = g_carLimitsNoPassThroughLivingStreet; -VehicleModel::InitListT const g_carLimitsSpain = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsSpain = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsSwitzerland = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsSwitzerland = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsTurkey = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsTurkey = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsUkraine = g_carLimitsNoPassThroughLivingStreetAndService; +VehicleModel::LimitsInitList const g_carLimitsUkraine = g_carLimitsNoPassThroughLivingStreetAndService; -VehicleModel::InitListT const g_carLimitsUK = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsUK = g_carLimitsDefault; -VehicleModel::InitListT const g_carLimitsUS = g_carLimitsDefault; +VehicleModel::LimitsInitList const g_carLimitsUS = g_carLimitsDefault; vector const kAdditionalTags = { {{"route", "ferry", "motorcar"}, kSpeedFerryMotorcarKMpH}, @@ -200,19 +200,25 @@ vector const kAdditionalTags = { {{"man_made", "pier"}, kSpeedPierKMpH}, }; +VehicleModel::SurfaceInitList const g_carSurface = { + {{"psurface", "paved_good"}, 1.0}, + {{"psurface", "paved_bad"}, 0.6}, + {{"psurface", "unpaved_good"}, 0.8}, + {{"psurface", "unpaved_bad"}, 0.4}, +}; } // namespace namespace routing { CarModel::CarModel() - : VehicleModel(classif(), g_carLimitsDefault) + : VehicleModel(classif(), g_carLimitsDefault, g_carSurface) { InitAdditionalRoadTypes(); } -CarModel::CarModel(VehicleModel::InitListT const & roadLimits) - : VehicleModel(classif(), roadLimits) +CarModel::CarModel(VehicleModel::LimitsInitList const & roadLimits) + : VehicleModel(classif(), roadLimits, g_carSurface) { InitAdditionalRoadTypes(); } @@ -232,7 +238,7 @@ CarModel const & CarModel::AllLimitsInstance() } // static -routing::VehicleModel::InitListT const & CarModel::GetLimits() { return g_carLimitsDefault; } +routing::VehicleModel::LimitsInitList const & CarModel::GetLimits() { return g_carLimitsDefault; } // static vector const & CarModel::GetAdditionalTags() { diff --git a/routing_common/car_model.hpp b/routing_common/car_model.hpp index 4736fc889e..f845240f12 100644 --- a/routing_common/car_model.hpp +++ b/routing_common/car_model.hpp @@ -9,13 +9,13 @@ class CarModel : public VehicleModel { public: CarModel(); - CarModel(VehicleModel::InitListT const & roadLimits); + CarModel(VehicleModel::LimitsInitList const & roadLimits); // VehicleModelInterface overrides double GetOffroadSpeed() const override; static CarModel const & AllLimitsInstance(); - static InitListT const & GetLimits(); + static LimitsInitList const & GetLimits(); static std::vector const & GetAdditionalTags(); private: diff --git a/routing_common/pedestrian_model.cpp b/routing_common/pedestrian_model.cpp index a3f59725bd..12b7148195 100644 --- a/routing_common/pedestrian_model.cpp +++ b/routing_common/pedestrian_model.cpp @@ -53,7 +53,7 @@ double constexpr kSpeedOffroadKMpH = 3.0; double constexpr kSpeedFerry = 1.0; // Default -VehicleModel::InitListT const g_pedestrianLimitsDefault = +VehicleModel::LimitsInitList const g_pedestrianLimitsDefault = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true /* passThroughAllowed */ }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -77,7 +77,7 @@ VehicleModel::InitListT const g_pedestrianLimitsDefault = }; // All options available. -VehicleModel::InitListT const g_pedestrianLimitsAll = +VehicleModel::LimitsInitList const g_pedestrianLimitsAll = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -103,7 +103,7 @@ VehicleModel::InitListT const g_pedestrianLimitsAll = }; // Same as defaults except trunk and trunk link are not allowed. -VehicleModel::InitListT const g_pedestrianLimitsNoTrunk = +VehicleModel::LimitsInitList const g_pedestrianLimitsNoTrunk = { { {"highway", "primary"}, kSpeedPrimaryKMpH, true }, { {"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true }, @@ -126,7 +126,7 @@ VehicleModel::InitListT const g_pedestrianLimitsNoTrunk = }; // Same as defaults except cycleway is allowed. -VehicleModel::InitListT const g_pedestrianLimitsCyclewayAllowed = +VehicleModel::LimitsInitList const g_pedestrianLimitsCyclewayAllowed = { { {"highway", "trunk"}, kSpeedTrunkKMpH, true }, { {"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true }, @@ -151,7 +151,7 @@ VehicleModel::InitListT const g_pedestrianLimitsCyclewayAllowed = }; // Same as defaults except cycleway is allowed and trunk and trunk_link are not allowed. -VehicleModel::InitListT const g_pedestrianLimitsCyclewayAllowedNoTrunk = +VehicleModel::LimitsInitList const g_pedestrianLimitsCyclewayAllowedNoTrunk = { { {"highway", "primary"}, kSpeedPrimaryKMpH, true }, { {"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true }, @@ -174,16 +174,16 @@ VehicleModel::InitListT const g_pedestrianLimitsCyclewayAllowedNoTrunk = }; // Australia -VehicleModel::InitListT const g_pedestrianLimitsAustralia = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsAustralia = g_pedestrianLimitsAll; // Austria -VehicleModel::InitListT const g_pedestrianLimitsAustria = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsAustria = g_pedestrianLimitsNoTrunk; // Belarus -VehicleModel::InitListT const g_pedestrianLimitsBelarus = g_pedestrianLimitsCyclewayAllowed; +VehicleModel::LimitsInitList const g_pedestrianLimitsBelarus = g_pedestrianLimitsCyclewayAllowed; // Belgium -VehicleModel::InitListT const g_pedestrianLimitsBelgium = +VehicleModel::LimitsInitList const g_pedestrianLimitsBelgium = { // Trunk and trunk_link are not allowed // Bridleway and cycleway are allowed @@ -209,73 +209,83 @@ VehicleModel::InitListT const g_pedestrianLimitsBelgium = }; // Brazil -VehicleModel::InitListT const g_pedestrianLimitsBrazil = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsBrazil = g_pedestrianLimitsAll; // Denmark -VehicleModel::InitListT const g_pedestrianLimitsDenmark = g_pedestrianLimitsCyclewayAllowedNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsDenmark = g_pedestrianLimitsCyclewayAllowedNoTrunk; // France -VehicleModel::InitListT const g_pedestrianLimitsFrance = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsFrance = g_pedestrianLimitsNoTrunk; // Finland -VehicleModel::InitListT const g_pedestrianLimitsFinland = g_pedestrianLimitsCyclewayAllowed; +VehicleModel::LimitsInitList const g_pedestrianLimitsFinland = g_pedestrianLimitsCyclewayAllowed; // Germany -VehicleModel::InitListT const g_pedestrianLimitsGermany = g_pedestrianLimitsDefault; +VehicleModel::LimitsInitList const g_pedestrianLimitsGermany = g_pedestrianLimitsDefault; // Hungary -VehicleModel::InitListT const g_pedestrianLimitsHungary = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsHungary = g_pedestrianLimitsNoTrunk; // Iceland -VehicleModel::InitListT const g_pedestrianLimitsIceland = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsIceland = g_pedestrianLimitsAll; // Netherlands -VehicleModel::InitListT const g_pedestrianLimitsNetherlands = g_pedestrianLimitsCyclewayAllowedNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsNetherlands = g_pedestrianLimitsCyclewayAllowedNoTrunk; // Norway -VehicleModel::InitListT const g_pedestrianLimitsNorway = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsNorway = g_pedestrianLimitsAll; // Oman -VehicleModel::InitListT const g_pedestrianLimitsOman = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsOman = g_pedestrianLimitsAll; // Poland -VehicleModel::InitListT const g_pedestrianLimitsPoland = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsPoland = g_pedestrianLimitsNoTrunk; // Romania -VehicleModel::InitListT const g_pedestrianLimitsRomania = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsRomania = g_pedestrianLimitsNoTrunk; // Russian Federation -VehicleModel::InitListT const g_pedestrianLimitsRussia = g_pedestrianLimitsCyclewayAllowed; +VehicleModel::LimitsInitList const g_pedestrianLimitsRussia = g_pedestrianLimitsCyclewayAllowed; // Slovakia -VehicleModel::InitListT const g_pedestrianLimitsSlovakia = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsSlovakia = g_pedestrianLimitsNoTrunk; // Spain -VehicleModel::InitListT const g_pedestrianLimitsSpain = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsSpain = g_pedestrianLimitsNoTrunk; // Switzerland -VehicleModel::InitListT const g_pedestrianLimitsSwitzerland = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsSwitzerland = g_pedestrianLimitsNoTrunk; // Turkey -VehicleModel::InitListT const g_pedestrianLimitsTurkey = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsTurkey = g_pedestrianLimitsAll; // Ukraine -VehicleModel::InitListT const g_pedestrianLimitsUkraine = g_pedestrianLimitsNoTrunk; +VehicleModel::LimitsInitList const g_pedestrianLimitsUkraine = g_pedestrianLimitsNoTrunk; // United Kingdom -VehicleModel::InitListT const g_pedestrianLimitsUK = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsUK = g_pedestrianLimitsAll; // United States of America -VehicleModel::InitListT const g_pedestrianLimitsUS = g_pedestrianLimitsAll; +VehicleModel::LimitsInitList const g_pedestrianLimitsUS = g_pedestrianLimitsAll; +VehicleModel::SurfaceInitList const g_pedestrianSurface = { + {{"psurface", "paved_good"}, 1.0}, + {{"psurface", "paved_bad"}, 1.0}, + {{"psurface", "unpaved_good"}, 1.0}, + {{"psurface", "unpaved_bad"}, 0.8}, +}; } // namespace namespace routing { -PedestrianModel::PedestrianModel() : VehicleModel(classif(), g_pedestrianLimitsDefault) { Init(); } +PedestrianModel::PedestrianModel() + : VehicleModel(classif(), g_pedestrianLimitsDefault, g_pedestrianSurface) +{ + Init(); +} -PedestrianModel::PedestrianModel(VehicleModel::InitListT const & speedLimits) - : VehicleModel(classif(), speedLimits) +PedestrianModel::PedestrianModel(VehicleModel::LimitsInitList const & speedLimits) + : VehicleModel(classif(), speedLimits, g_pedestrianSurface) { Init(); } diff --git a/routing_common/pedestrian_model.hpp b/routing_common/pedestrian_model.hpp index cd6c5a3ceb..701247d16d 100644 --- a/routing_common/pedestrian_model.hpp +++ b/routing_common/pedestrian_model.hpp @@ -9,7 +9,7 @@ class PedestrianModel : public VehicleModel { public: PedestrianModel(); - PedestrianModel(VehicleModel::InitListT const & speedLimits); + PedestrianModel(VehicleModel::LimitsInitList const & speedLimits); /// VehicleModelInterface overrides: bool IsOneWay(FeatureType const &) const override { return false; } diff --git a/routing_common/routing_common_tests/vehicle_model_test.cpp b/routing_common/routing_common_tests/vehicle_model_test.cpp index 4f241d28b4..e98caaccc5 100644 --- a/routing_common/routing_common_tests/vehicle_model_test.cpp +++ b/routing_common/routing_common_tests/vehicle_model_test.cpp @@ -10,7 +10,7 @@ namespace { -routing::VehicleModel::InitListT const s_testLimits = { +routing::VehicleModel::LimitsInitList const s_testLimits = { {{"highway", "trunk"}, 150, true}, {{"highway", "primary"}, 120, true}, {{"highway", "secondary"}, 80, true}, diff --git a/routing_common/vehicle_model.cpp b/routing_common/vehicle_model.cpp index 60e5f473ea..4e52ff183c 100644 --- a/routing_common/vehicle_model.cpp +++ b/routing_common/vehicle_model.cpp @@ -24,16 +24,25 @@ VehicleModel::RoadLimits::RoadLimits(double speedKMpH, bool isPassThroughAllowed CHECK_GREATER(m_speedKMpH, 0.0, ()); } -VehicleModel::VehicleModel(Classificator const & c, InitListT const & featureTypeLimits) - : m_maxSpeedKMpH(0), - m_onewayType(c.GetTypeByPath({ "hwtag", "oneway" })) +VehicleModel::VehicleModel(Classificator const & c, LimitsInitList const & featureTypeLimits, + SurfaceInitList const & featureTypeSurface) + : m_maxSpeedKMpH(0), m_onewayType(c.GetTypeByPath({"hwtag", "oneway"})) { + CHECK_EQUAL(m_surfaceFactors.size(), 4, + ("If you want to change the size of the container please take into account that it's " + "used with algorithm find() with linear complexity.")); + CHECK_EQUAL(featureTypeSurface.size(), m_surfaceFactors.size(), ()); + for (auto const & v : featureTypeLimits) { m_maxSpeedKMpH = max(m_maxSpeedKMpH, v.m_speedKMpH); - m_types.emplace(c.GetTypeByPath(vector(v.m_types, v.m_types + 2)), - RoadLimits(v.m_speedKMpH, v.m_isPassThroughAllowed)); + m_highwayTypes.emplace(c.GetTypeByPath(vector(v.m_types, v.m_types + 2)), + RoadLimits(v.m_speedKMpH, v.m_isPassThroughAllowed)); } + + size_t i = 0; + for (auto const & v : featureTypeSurface) + m_surfaceFactors[i++] = {c.GetTypeByPath(vector(v.m_types, v.m_types + 2)), v.m_speedFactor}; } void VehicleModel::SetAdditionalRoadTypes(Classificator const & c, @@ -62,19 +71,27 @@ double VehicleModel::GetSpeed(FeatureType const & f) const double VehicleModel::GetMinTypeSpeed(feature::TypesHolder const & types) const { double speed = m_maxSpeedKMpH * 2; + // Decreasing speed factor based on road surface (cover). + double speedFactor = 1.0; for (uint32_t t : types) { uint32_t const type = ftypes::BaseChecker::PrepareToMatch(t, 2); - auto it = m_types.find(type); - if (it != m_types.end()) - speed = min(speed, it->second.GetSpeedKMpH()); + auto itHighway = m_highwayTypes.find(type); + if (itHighway != m_highwayTypes.end()) + speed = min(speed, itHighway->second.GetSpeedKMpH()); auto const addRoadInfoIter = FindRoadType(t); if (addRoadInfoIter != m_addRoadTypes.cend()) speed = min(speed, addRoadInfoIter->m_speedKMpH); + + auto const itFactor = find_if(m_surfaceFactors.cbegin(), m_surfaceFactors.cend(), + [t](TypeFactor const & v) { return v.m_type == t; }); + if (itFactor != m_surfaceFactors.cend()) + speedFactor = min(speedFactor, itFactor->m_factor); } - if (speed <= m_maxSpeedKMpH) - return speed; + + if (speed <= m_maxSpeedKMpH && speedFactor <= 1.0) + return speed * speedFactor; return 0.0 /* Speed */; } @@ -129,8 +146,8 @@ bool VehicleModel::HasPassThroughType(feature::TypesHolder const & types) const for (uint32_t t : types) { uint32_t const type = ftypes::BaseChecker::PrepareToMatch(t, 2); - auto it = m_types.find(type); - if (it != m_types.end() && it->second.IsPassThroughAllowed()) + auto it = m_highwayTypes.find(type); + if (it != m_highwayTypes.end() && it->second.IsPassThroughAllowed()) return true; } @@ -140,7 +157,7 @@ bool VehicleModel::HasPassThroughType(feature::TypesHolder const & types) const bool VehicleModel::IsRoadType(uint32_t type) const { return FindRoadType(type) != m_addRoadTypes.cend() || - m_types.find(ftypes::BaseChecker::PrepareToMatch(type, 2)) != m_types.end(); + m_highwayTypes.find(ftypes::BaseChecker::PrepareToMatch(type, 2)) != m_highwayTypes.end(); } VehicleModelInterface::RoadAvailability VehicleModel::GetRoadAvailability(feature::TypesHolder const & /* types */) const diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp index 8662605572..7ceba6a0c3 100644 --- a/routing_common/vehicle_model.hpp +++ b/routing_common/vehicle_model.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -26,7 +27,7 @@ public: Unknown, }; - virtual ~VehicleModelInterface() {} + virtual ~VehicleModelInterface() = default; /// @return Allowed speed in KMpH. /// 0 means that it's forbidden to move on this feature or it's not a road at all. @@ -56,7 +57,7 @@ public: class VehicleModelFactoryInterface { public: - virtual ~VehicleModelFactoryInterface() {} + virtual ~VehicleModelFactoryInterface() = default; /// @return Default vehicle model which corresponds for all countrines, /// but it may be non optimal for some countries virtual std::shared_ptr GetVehicleModel() const = 0; @@ -71,9 +72,18 @@ class VehicleModel : public VehicleModelInterface public: struct FeatureTypeLimits final { - char const * m_types[2]; /// 2-arity road type - double m_speedKMpH; /// max allowed speed on this road type - bool m_isPassThroughAllowed; /// pass through this road type is allowed + char const * m_types[2]; // 2-arity road type + double m_speedKMpH; // max allowed speed on this road type + bool m_isPassThroughAllowed; // pass through this road type is allowed + }; + + // Structure for keeping surface tags: psurface|paved_good, psurface|paved_bad, + // psurface|unpaved_good and psurface|unpaved_bad. + struct FeatureTypeSurface + { + char const * m_types[2]; // 2-arity road type + double m_speedFactor; // Factor (lowering) which reduces speed on feature in case of + // bad pavement. It should be from 0.0 to 1.0. }; struct AdditionalRoadTags final @@ -89,9 +99,11 @@ public: double m_speedKMpH = 0.0; }; - typedef std::initializer_list InitListT; + typedef std::initializer_list LimitsInitList; + typedef std::initializer_list SurfaceInitList; - VehicleModel(Classificator const & c, InitListT const & featureTypeLimits); + VehicleModel(Classificator const & c, LimitsInitList const & featureTypeLimits, + SurfaceInitList const & featureTypeSurface); /// VehicleModelInterface overrides: double GetSpeed(FeatureType const & f) const override; @@ -101,7 +113,7 @@ public: bool IsPassThroughAllowed(FeatureType const & f) const override; public: - /// @returns true if |m_types| or |m_addRoadTypes| contains |type| and false otherwise. + /// @returns true if |m_highwayTypes| or |m_addRoadTypes| contains |type| and false otherwise. bool IsRoadType(uint32_t type) const; template @@ -117,7 +129,7 @@ public: bool EqualsForTests(VehicleModel const & rhs) const { - return (m_types == rhs.m_types) && + return (m_highwayTypes == rhs.m_highwayTypes) && (m_addRoadTypes == rhs.m_addRoadTypes) && (m_onewayType == rhs.m_onewayType); } @@ -172,9 +184,19 @@ private: bool const m_isPassThroughAllowed; }; + struct TypeFactor + { + uint32_t m_type = 0; + double m_factor = 1.0; + }; + std::vector::const_iterator FindRoadType(uint32_t type) const; - std::unordered_map m_types; + std::unordered_map m_highwayTypes; + // Mapping surface types (psurface|paved_good, psurface|paved_bad, psurface|unpaved_good, + // psurface|unpaved_bad) to surface speed factors. + // Note. It's a vector (not map or unordered_map) because of perfomance reasons. + std::array m_surfaceFactors; std::vector m_addRoadTypes; uint32_t m_onewayType; @@ -196,7 +218,7 @@ public: std::string const & country) const override; protected: - VehicleModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn); + explicit VehicleModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn); std::string GetParent(std::string const & country) const; std::unordered_map> m_models;