diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2018-11-13 14:59:52 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-11-23 17:58:49 +0300 |
commit | 2cf9833de77b39106c494cf999da328dba948142 (patch) | |
tree | ef2ccddbf371cc734913cb532ae709d1f79b50d3 /routing_common | |
parent | 63c78b71dbaa3a519d27f8a1bff10174f556cbf7 (diff) |
[routing] Using maxspeed tag value for building routes.
Diffstat (limited to 'routing_common')
-rw-r--r-- | routing_common/bicycle_model.cpp | 2 | ||||
-rw-r--r-- | routing_common/maxspeed_conversion.cpp | 38 | ||||
-rw-r--r-- | routing_common/maxspeed_conversion.hpp | 25 | ||||
-rw-r--r-- | routing_common/pedestrian_model.cpp | 2 | ||||
-rw-r--r-- | routing_common/vehicle_model.cpp | 26 | ||||
-rw-r--r-- | routing_common/vehicle_model.hpp | 4 |
6 files changed, 80 insertions, 17 deletions
diff --git a/routing_common/bicycle_model.cpp b/routing_common/bicycle_model.cpp index 96d7813650..e54b19149b 100644 --- a/routing_common/bicycle_model.cpp +++ b/routing_common/bicycle_model.cpp @@ -456,7 +456,7 @@ void BicycleModel::Init() m_bidirBicycleType = classif().GetTypeByPath({"hwtag", "bidir_bicycle"}); vector<AdditionalRoadTags> const additionalTags = { - {hwtagYesBicycle, m_maxSpeed}, + {hwtagYesBicycle, m_modelMaxSpeed}, {{"route", "ferry"}, kSpeedFerryKMpH}, {{"man_made", "pier"}, kSpeedPierKMpH} }; diff --git a/routing_common/maxspeed_conversion.cpp b/routing_common/maxspeed_conversion.cpp index 0677fbbf11..e504aa54c1 100644 --- a/routing_common/maxspeed_conversion.cpp +++ b/routing_common/maxspeed_conversion.cpp @@ -21,7 +21,38 @@ bool SpeedInUnits::operator<(SpeedInUnits const & rhs) const bool SpeedInUnits::IsNumeric() const { - return m_speed != kNoneMaxSpeed && m_speed != kWalkMaxSpeed && m_speed != kInvalidSpeed; + return routing::IsNumeric(m_speed); +} + +// Maxspeed ---------------------------------------------------------------------------------------- +bool Maxspeed::operator==(Maxspeed const & rhs) const +{ + return m_units == rhs.m_units && m_forward == rhs.m_forward && m_backward == rhs.m_backward; +} + +uint16_t Maxspeed::GetSpeedInUnits(bool forward) const +{ + return (forward || !IsBidirectional()) ? m_forward : m_backward; +} + +uint16_t Maxspeed::GetSpeedKmPH(bool forward) const +{ + auto speedInUnits = GetSpeedInUnits(forward); + if (speedInUnits == kInvalidSpeed) + return kInvalidSpeed; // That means IsValid() returns false. + + if (IsNumeric(speedInUnits)) + return ToSpeedKmPH(speedInUnits, m_units); + + // A feature is marked as a feature without any speed limits. (maxspeed=="none"). + if (kNoneMaxSpeed) + return 1000; // km per hour + + // A feature is marked the a driver should drive with walking speed on it. (maxspeed=="walk"). + if (kWalkMaxSpeed) + return 6; // km per hour + + CHECK(false, ("Method IsNumeric() returns something wrong.")); } // FeatureMaxspeed --------------------------------------------------------------------------------- @@ -243,6 +274,11 @@ bool HaveSameUnits(SpeedInUnits const & lhs, SpeedInUnits const & rhs) return lhs.m_units == rhs.m_units || !lhs.IsNumeric() || !rhs.IsNumeric(); } +bool IsNumeric(uint16_t speed) +{ + return speed != kNoneMaxSpeed && speed != kWalkMaxSpeed && speed != kInvalidSpeed; +} + std::string DebugPrint(Maxspeed maxspeed) { std::ostringstream oss; diff --git a/routing_common/maxspeed_conversion.hpp b/routing_common/maxspeed_conversion.hpp index f855096600..0883b057b8 100644 --- a/routing_common/maxspeed_conversion.hpp +++ b/routing_common/maxspeed_conversion.hpp @@ -183,16 +183,26 @@ struct Maxspeed measurement_utils::Units m_units = measurement_utils::Units::Metric; // Speed in km per hour or mile per hour depends on |m_units|. uint16_t m_forward = kInvalidSpeed; - // Speed in km per hour or mile per hour depends on |m_units|. + // Speed in km per hour or mile per hour depends on |m_units|. If |m_backward| == kInvalidSpeed + // |m_forward| speed should be used for the both directions. uint16_t m_backward = kInvalidSpeed; - bool operator==(Maxspeed const & rhs) const - { - return m_units == rhs.m_units && m_forward == rhs.m_forward && m_backward == rhs.m_backward; - } + bool operator==(Maxspeed const & rhs) const; bool IsValid() const { return m_forward != kInvalidSpeed; } + /// \returns true if Maxspeed is considered as Bidirectional(). It means different + /// speed is set for forward and backward direction. Otherwise returns false. It means + /// |m_forward| speed should be used for the both directions. bool IsBidirectional() const { return IsValid() && m_backward != kInvalidSpeed; } + + /// \brief returns speed according to |m_units|. |kInvalidSpeed|, |kNoneMaxSpeed| or + /// |kWalkMaxSpeed| may be returned. + uint16_t GetSpeedInUnits(bool forward) const; + + /// \brief returns speed in km per hour. If it's not valid |kInvalidSpeed| is + /// returned. Otherwise forward or backward speed in km per hour is returned. |kNoneMaxSpeed| and + /// |kWalkMaxSpeed| are converted to some numbers. + uint16_t GetSpeedKmPH(bool forward) const; }; /// \brief Feature id and corresponding maxspeed tag value. |m_forward| and |m_backward| fields @@ -246,6 +256,11 @@ private: MaxspeedConverter const & GetMaxspeedConverter(); bool HaveSameUnits(SpeedInUnits const & lhs, SpeedInUnits const & rhs); +/// \returns false if |speed| is equal to |kInvalidSpeed|, |kNoneMaxSpeed| or +/// |kWalkMaxSpeed|. +/// \param speed in km per hour or mile per hour. +bool IsNumeric(uint16_t speed); + std::string DebugPrint(Maxspeed maxspeed); std::string DebugPrint(SpeedMacro maxspeed); std::string DebugPrint(SpeedInUnits const & speed); diff --git a/routing_common/pedestrian_model.cpp b/routing_common/pedestrian_model.cpp index c8fa6a3ebe..f9f652b637 100644 --- a/routing_common/pedestrian_model.cpp +++ b/routing_common/pedestrian_model.cpp @@ -308,7 +308,7 @@ void PedestrianModel::Init() m_yesFootType = classif().GetTypeByPath(hwtagYesFoot); vector<AdditionalRoadTags> const additionalTags = { - {hwtagYesFoot, m_maxSpeed}, + {hwtagYesFoot, m_modelMaxSpeed}, {{"route", "ferry"}, kSpeedFerryKMpH}, {{"man_made", "pier"}, kSpeedPierKMpH} }; diff --git a/routing_common/vehicle_model.cpp b/routing_common/vehicle_model.cpp index 9dc4292a76..3008499b6d 100644 --- a/routing_common/vehicle_model.cpp +++ b/routing_common/vehicle_model.cpp @@ -49,7 +49,7 @@ VehicleModel::RoadLimits::RoadLimits(VehicleModel::InOutCitySpeedKMpH const & sp VehicleModel::VehicleModel(Classificator const & c, LimitsInitList const & featureTypeLimits, SurfaceInitList const & featureTypeSurface) - : m_maxSpeed({}, {}), m_onewayType(c.GetTypeByPath({"hwtag", "oneway"})) + : m_modelMaxSpeed({}, {}), 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 " @@ -58,7 +58,7 @@ VehicleModel::VehicleModel(Classificator const & c, LimitsInitList const & featu for (auto const & v : featureTypeLimits) { - m_maxSpeed = Max(m_maxSpeed, v.m_speed); + m_modelMaxSpeed = Max(m_modelMaxSpeed, v.m_speed); m_highwayTypes.emplace(c.GetTypeByPath(v.m_types), RoadLimits(v.m_speed, v.m_isPassThroughAllowed)); } @@ -83,7 +83,7 @@ void VehicleModel::SetAdditionalRoadTypes(Classificator const & c, for (auto const & tag : additionalTags) { m_addRoadTypes.emplace_back(c, tag); - m_maxSpeed = Max(m_maxSpeed, tag.m_speed); + m_modelMaxSpeed = Max(m_modelMaxSpeed, tag.m_speed); } } @@ -94,22 +94,32 @@ VehicleModel::SpeedKMpH VehicleModel::GetSpeed(FeatureType & f, SpeedParams cons RoadAvailability const restriction = GetRoadAvailability(types); // @TODO(bykoianko) Consider using speed on feature |f| instead of using max speed below. if (restriction == RoadAvailability::Available) - return speedParams.m_inCity ? m_maxSpeed.m_inCity : m_maxSpeed.m_outCity; + return speedParams.m_inCity ? m_modelMaxSpeed.m_inCity : m_modelMaxSpeed.m_outCity; + if (restriction != RoadAvailability::NotAvailable && HasRoadType(types)) - return GetMinTypeSpeed(types, speedParams.m_inCity); + { + uint16_t const speedKmPH = speedParams.m_maxspeed.GetSpeedKmPH(speedParams.m_forward); + // Note. It's the first rough attept using maxspeed tag value for speed calculation. + // It's used as a feature speed if it's valid and less then some value. + // @TODO maxspeed tag value should be used more sophisticated. + if (!speedParams.m_maxspeed.IsValid() || speedKmPH > 200) + return GetMinTypeSpeed(types, speedParams.m_inCity); + + return {static_cast<double>(speedKmPH), static_cast<double>(speedKmPH)}; + } return {}; } double VehicleModel::GetMaxWeightSpeed() const { - return max(m_maxSpeed.m_inCity.m_weight, m_maxSpeed.m_outCity.m_weight); + return max(m_modelMaxSpeed.m_inCity.m_weight, m_modelMaxSpeed.m_outCity.m_weight); } VehicleModel::SpeedKMpH VehicleModel::GetMinTypeSpeed(feature::TypesHolder const & types, bool inCity) const { - double const maxSpeedWeight = inCity ? m_maxSpeed.m_inCity.m_weight : m_maxSpeed.m_outCity.m_weight; - double const maxEtaWeight = inCity ? m_maxSpeed.m_inCity.m_eta : m_maxSpeed.m_outCity.m_eta; + double const maxSpeedWeight = inCity ? m_modelMaxSpeed.m_inCity.m_weight : m_modelMaxSpeed.m_outCity.m_weight; + double const maxEtaWeight = inCity ? m_modelMaxSpeed.m_inCity.m_eta : m_modelMaxSpeed.m_outCity.m_eta; VehicleModel::SpeedKMpH speed{maxSpeedWeight * 2.0, maxEtaWeight * 2.0}; // Decreasing speed factor based on road surface (cover). VehicleModel::SpeedFactor factor; diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp index 30fa221daf..1995b7ba83 100644 --- a/routing_common/vehicle_model.hpp +++ b/routing_common/vehicle_model.hpp @@ -218,7 +218,9 @@ protected: SpeedKMpH GetMinTypeSpeed(feature::TypesHolder const & types, bool inCity) const; - InOutCitySpeedKMpH m_maxSpeed; + /// \brief maximum within all the speed limits set in a model (car model, bicycle modle and so on). + /// It shouldn't be mixed with maxspeed value tag which defines maximum legal speed on a feature. + InOutCitySpeedKMpH m_modelMaxSpeed; private: struct AdditionalRoadType final |