diff --git a/base/small_map.hpp b/base/small_map.hpp index 12f8068cfe..2b396a8f6e 100644 --- a/base/small_map.hpp +++ b/base/small_map.hpp @@ -83,6 +83,19 @@ public: return nullptr; } + void Replace(Key const & k, Value v) + { + auto & theMap = this->m_map; + auto it = std::lower_bound(theMap.begin(), theMap.end(), k, + [](ValueType const & l, Key const & r) + { + return l.first < r; + }); + + ASSERT(it != theMap.end() && it->first == k, ()); + it->second = std::move(v); + } + Value const & Get(Key const & k) const { Value const * v = Find(k); diff --git a/routing_common/bicycle_model.cpp b/routing_common/bicycle_model.cpp index effcf6b225..13ba14d022 100644 --- a/routing_common/bicycle_model.cpp +++ b/routing_common/bicycle_model.cpp @@ -209,6 +209,25 @@ VehicleModel::LimitsInitList const kBicycleOptionsAustria = { // Belarus VehicleModel::LimitsInitList const kBicycleOptionsBelarus = kBicycleOptionsPedestrianFootwayAllowed; +HighwayBasedSpeeds PreferFootwaysToRoads() +{ + HighwayBasedSpeeds res = kDefaultSpeeds; + + // Decrease secondary/tertiary weight speed (-20% from default). + InOutCitySpeedKMpH roadSpeed = InOutCitySpeedKMpH(SpeedKMpH(12.0, 18.0), SpeedKMpH(16.0, 18.0)); + res.Replace(HighwayType::HighwaySecondary, roadSpeed); + res.Replace(HighwayType::HighwaySecondaryLink, roadSpeed); + res.Replace(HighwayType::HighwayTertiary, roadSpeed); + res.Replace(HighwayType::HighwayTertiaryLink, roadSpeed); + + // Increase footway speed to make bigger than other roads (+20% from default roads). + InOutCitySpeedKMpH footSpeed = InOutCitySpeedKMpH(SpeedKMpH(18.0, 18.0), SpeedKMpH(20.0, 18.0)); + res.Replace(HighwayType::HighwayPedestrian, footSpeed); + res.Replace(HighwayType::HighwayFootway, footSpeed); + + return res; +} + // Belgium VehicleModel::LimitsInitList const kBicycleOptionsBelgium = { // No trunk, trunk_link @@ -385,19 +404,17 @@ VehicleModel::SurfaceInitList const kBicycleSurface = { namespace routing { BicycleModel::BicycleModel() - : VehicleModel(classif(), bicycle_model::kBicycleOptionsDefault, bicycle_model::kBicycleSurface, - {bicycle_model::kDefaultSpeeds, bicycle_model::kDefaultFactors}) + : BicycleModel(bicycle_model::kBicycleOptionsDefault) { - Init(); } -BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & speedLimits) - : VehicleModel(classif(), speedLimits, bicycle_model::kBicycleSurface, {bicycle_model::kDefaultSpeeds, bicycle_model::kDefaultFactors}) +BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & limits) + : BicycleModel(limits, bicycle_model::kDefaultSpeeds) { - Init(); } -void BicycleModel::Init() +BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & limits, HighwayBasedSpeeds const & speeds) + : VehicleModel(classif(), limits, bicycle_model::kBicycleSurface, {speeds, bicycle_model::kDefaultFactors}) { std::vector hwtagYesBicycle = {"hwtag", "yesbicycle"}; @@ -488,7 +505,10 @@ BicycleModelFactory::BicycleModelFactory( m_models[""] = make_shared(kBicycleOptionsDefault); m_models["Australia"] = make_shared(kBicycleOptionsAustralia); m_models["Austria"] = make_shared(kBicycleOptionsAustria); - m_models["Belarus"] = make_shared(kBicycleOptionsBelarus); + + // Belarus law demands to use footways for bicycles where possible. + m_models["Belarus"] = make_shared(kBicycleOptionsBelarus, PreferFootwaysToRoads()); + m_models["Belgium"] = make_shared(kBicycleOptionsBelgium); m_models["Brazil"] = make_shared(kBicycleOptionsBrazil); m_models["Denmark"] = make_shared(kBicycleOptionsDenmark); diff --git a/routing_common/bicycle_model.hpp b/routing_common/bicycle_model.hpp index db08b03853..1110f2029c 100644 --- a/routing_common/bicycle_model.hpp +++ b/routing_common/bicycle_model.hpp @@ -9,7 +9,8 @@ class BicycleModel : public VehicleModel { public: BicycleModel(); - BicycleModel(VehicleModel::LimitsInitList const & speedLimits); + explicit BicycleModel(VehicleModel::LimitsInitList const & limits); + BicycleModel(VehicleModel::LimitsInitList const & limits, HighwayBasedSpeeds const & speeds); /// VehicleModelInterface overrides: SpeedKMpH GetSpeed(FeatureType & f, SpeedParams const & speedParams) const override; @@ -23,8 +24,6 @@ protected: RoadAvailability GetRoadAvailability(feature::TypesHolder const & types) const override; private: - void Init(); - /// @return true if it is allowed to ride a bicycle in both directions. bool IsBicycleBidir(feature::TypesHolder const & types) const; // Returns true if the road is explicitly set oneway for bicycles. diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp index 6c067d78ba..b4f1d96cda 100644 --- a/routing_common/vehicle_model.hpp +++ b/routing_common/vehicle_model.hpp @@ -194,7 +194,7 @@ struct HighwayBasedInfo { } - HighwayBasedSpeeds const & m_speeds; + HighwayBasedSpeeds m_speeds; HighwayBasedFactors const & m_factors; };