Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2018-09-19 16:06:14 +0300
committerVlad Mihaylenko <vxmihaylenko@gmail.com>2018-09-20 18:05:43 +0300
commitfba751f28286f9611256f6c7b2d2c017fba26e45 (patch)
treea8546227cbf5a98e691777cec8c9990778d87791 /routing_common
parent484b73c857fea71f9291c502503c02bd66125bcb (diff)
Keeping max speed for roads in city and for roads outside.
Diffstat (limited to 'routing_common')
-rw-r--r--routing_common/bicycle_model.cpp2
-rw-r--r--routing_common/pedestrian_model.cpp2
-rw-r--r--routing_common/routing_common_tests/vehicle_model_test.cpp30
-rw-r--r--routing_common/vehicle_model.cpp48
-rw-r--r--routing_common/vehicle_model.hpp16
5 files changed, 67 insertions, 31 deletions
diff --git a/routing_common/bicycle_model.cpp b/routing_common/bicycle_model.cpp
index 725445f837..96d7813650 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, InOutCitySpeedKMpH(m_maxSpeed, m_maxSpeed)},
+ {hwtagYesBicycle, m_maxSpeed},
{{"route", "ferry"}, kSpeedFerryKMpH},
{{"man_made", "pier"}, kSpeedPierKMpH}
};
diff --git a/routing_common/pedestrian_model.cpp b/routing_common/pedestrian_model.cpp
index cc186c80dd..63c70697d7 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, InOutCitySpeedKMpH(m_maxSpeed, m_maxSpeed)},
+ {hwtagYesFoot, m_maxSpeed},
{{"route", "ferry"}, kSpeedFerryKMpH},
{{"man_made", "pier"}, kSpeedPierKMpH}
};
diff --git a/routing_common/routing_common_tests/vehicle_model_test.cpp b/routing_common/routing_common_tests/vehicle_model_test.cpp
index 9a1916e6df..e897cf0dae 100644
--- a/routing_common/routing_common_tests/vehicle_model_test.cpp
+++ b/routing_common/routing_common_tests/vehicle_model_test.cpp
@@ -15,12 +15,12 @@ namespace
using SpeedKMpH = routing::VehicleModel::SpeedKMpH;
routing::VehicleModel::LimitsInitList const s_testLimits = {
- // Out of city weight and eta speeds. In city weight and eta speeds.
- {{"highway", "trunk"}, {SpeedKMpH(150.0, 150.0), SpeedKMpH(100.0, 100.0)}, true},
- {{"highway", "primary"}, {SpeedKMpH(120.0, 120.0), SpeedKMpH(90.0, 90.0)}, true},
+ // In city weight and eta speeds. Out of city weight and eta speeds.
+ {{"highway", "trunk"}, {SpeedKMpH(100.0, 100.0), SpeedKMpH(150.0, 150.0)}, true},
+ {{"highway", "primary"}, {SpeedKMpH(90.0, 90.0), SpeedKMpH(120.0, 120.0)}, true},
{{"highway", "secondary"}, {SpeedKMpH(80.0, 70.0), SpeedKMpH(80.0, 70.0)}, true},
- {{"highway", "residential"}, {SpeedKMpH(50.0, 60.0), SpeedKMpH(45.0, 55.0)}, true},
- {{"highway", "service"}, {SpeedKMpH(50.0, 40.0), SpeedKMpH(47.0, 36.0)}, false}};
+ {{"highway", "residential"}, {SpeedKMpH(45.0, 55.0), SpeedKMpH(50.0, 60.0)}, true},
+ {{"highway", "service"}, {SpeedKMpH(47.0, 36.0), SpeedKMpH(50.0, 40.0)}, false}};
routing::VehicleModel::SurfaceInitList const g_carSurface = {
{{"psurface", "paved_good"}, {0.8 /* weightFactor */, 0.9 /* etaFactor */}},
@@ -94,8 +94,10 @@ void CheckPassThroughAllowed(initializer_list<uint32_t> const & types, bool expe
UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_MaxSpeed)
{
TestVehicleModel vehicleModel;
- TEST_EQUAL(vehicleModel.GetMaxSpeed().m_weight, 150, ());
- TEST_EQUAL(vehicleModel.GetMaxSpeed().m_eta, 150, ());
+ TEST_EQUAL(vehicleModel.GetMaxSpeed().m_inCity.m_weight, 100, ());
+ TEST_EQUAL(vehicleModel.GetMaxSpeed().m_inCity.m_eta, 100, ());
+ TEST_EQUAL(vehicleModel.GetMaxSpeed().m_outCity.m_weight, 150, ());
+ TEST_EQUAL(vehicleModel.GetMaxSpeed().m_outCity.m_eta, 150, ());
}
UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_Speed)
@@ -104,9 +106,9 @@ UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_Speed)
CheckSpeed({GetType("highway", "secondary", "tunnel")}, {80.0, 70.0});
CheckSpeed({GetType("highway", "secondary")}, {80.0, 70.0});
- CheckSpeed({GetType("highway", "trunk")}, {100.0, 100.0});
- CheckSpeed({GetType("highway", "primary")}, {90.0, 90.0});
- CheckSpeed({GetType("highway", "residential")}, {45.0, 55.0});
+ CheckSpeed({GetType("highway", "trunk")}, {150.0, 150.0});
+ CheckSpeed({GetType("highway", "primary")}, {120.0, 120.0});
+ CheckSpeed({GetType("highway", "residential")}, {50.0, 60.0});
}
UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_Speed_MultiTypes)
@@ -167,8 +169,8 @@ UNIT_CLASS_TEST(VehicleModelTest, VehicleModel_SpeedFactor)
CheckSpeed({secondary, unpavedGood}, {48.0, 56.0});
CheckSpeed({secondary, unpavedBad}, {16.0, 14.0});
- CheckSpeed({residential, pavedGood}, {36.0, 49.5});
- CheckSpeed({residential, pavedBad}, {18.0, 27.5});
- CheckSpeed({residential, unpavedGood}, {27.0, 44.0});
- CheckSpeed({residential, unpavedBad}, {9.0, 11.0});
+ CheckSpeed({residential, pavedGood}, {40.0, 54.0});
+ CheckSpeed({residential, pavedBad}, {20.0, 30.0});
+ CheckSpeed({residential, unpavedGood}, {30.0, 48.0});
+ CheckSpeed({residential, unpavedBad}, {10.0, 12.0});
}
diff --git a/routing_common/vehicle_model.cpp b/routing_common/vehicle_model.cpp
index 905f6ee309..2a0d80fef3 100644
--- a/routing_common/vehicle_model.cpp
+++ b/routing_common/vehicle_model.cpp
@@ -10,6 +10,7 @@
#include <algorithm>
#include <sstream>
+using namespace routing;
using namespace std;
namespace
@@ -19,6 +20,12 @@ WeightAndETA Pick(WeightAndETA const & lhs, WeightAndETA const & rhs)
{
return {F(lhs.m_weight, rhs.m_weight), F(lhs.m_eta, rhs.m_eta)};
};
+
+VehicleModel::InOutCitySpeedKMpH Max(VehicleModel::InOutCitySpeedKMpH const & lhs,
+ VehicleModel::InOutCitySpeedKMpH const & rhs)
+{
+ return {Pick<max>(lhs.m_inCity, rhs.m_inCity), Pick<max>(lhs.m_outCity, rhs.m_outCity)};
+}
} // namespace
namespace routing
@@ -42,7 +49,7 @@ VehicleModel::RoadLimits::RoadLimits(VehicleModel::InOutCitySpeedKMpH const & sp
VehicleModel::VehicleModel(Classificator const & c, LimitsInitList const & featureTypeLimits,
SurfaceInitList const & featureTypeSurface)
- : m_onewayType(c.GetTypeByPath({"hwtag", "oneway"}))
+ : m_maxSpeed({}, {}), 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 "
@@ -51,7 +58,7 @@ VehicleModel::VehicleModel(Classificator const & c, LimitsInitList const & featu
for (auto const & v : featureTypeLimits)
{
- m_maxSpeed = Pick<max>(m_maxSpeed, Pick<max>(v.m_speed.m_outCity, v.m_speed.m_inCity));
+ m_maxSpeed = Max(m_maxSpeed, v.m_speed);
m_highwayTypes.emplace(c.GetTypeByPath(v.m_types),
RoadLimits(v.m_speed, v.m_isPassThroughAllowed));
}
@@ -78,7 +85,7 @@ void VehicleModel::SetAdditionalRoadTypes(Classificator const & c,
for (auto const & tag : additionalTags)
{
m_addRoadTypes.emplace_back(c, tag);
- m_maxSpeed = Pick<max>(m_maxSpeed, Pick<max>(tag.m_speed.m_outCity, tag.m_speed.m_inCity));
+ m_maxSpeed = Max(m_maxSpeed, tag.m_speed);
}
}
@@ -90,7 +97,7 @@ VehicleModel::SpeedKMpH VehicleModel::GetSpeed(FeatureType & f) const
// TODO(bykoianko) If a road is available, a speed according to city status (CityRoads)
// should be returned.
if (restriction == RoadAvailability::Available)
- return GetMaxSpeed();
+ return GetMaxSpeed().m_outCity;
if (restriction != RoadAvailability::NotAvailable && HasRoadType(types))
return GetMinTypeSpeed(types);
@@ -99,7 +106,8 @@ VehicleModel::SpeedKMpH VehicleModel::GetSpeed(FeatureType & f) const
VehicleModel::SpeedKMpH VehicleModel::GetMinTypeSpeed(feature::TypesHolder const & types) const
{
- VehicleModel::SpeedKMpH speed{m_maxSpeed.m_weight * 2.0, m_maxSpeed.m_eta * 2.0};
+ // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed.
+ VehicleModel::SpeedKMpH speed{m_maxSpeed.m_outCity.m_weight * 2.0, m_maxSpeed.m_outCity.m_eta * 2.0};
// Decreasing speed factor based on road surface (cover).
VehicleModel::SpeedFactor factor;
for (uint32_t t : types)
@@ -127,10 +135,12 @@ VehicleModel::SpeedKMpH VehicleModel::GetMinTypeSpeed(feature::TypesHolder const
CHECK_GREATER_OR_EQUAL(factor.m_eta, 0.0, ());
VehicleModel::SpeedKMpH ret;
- if (speed.m_weight <= m_maxSpeed.m_weight)
+ // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed.
+ if (speed.m_weight <= m_maxSpeed.m_outCity.m_weight)
ret.m_weight = speed.m_weight * factor.m_weight;
- if (speed.m_eta <= m_maxSpeed.m_eta)
+ // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed.
+ if (speed.m_eta <= m_maxSpeed.m_outCity.m_eta)
ret.m_eta = speed.m_eta * factor.m_eta;
return ret;
@@ -252,6 +262,21 @@ string VehicleModelFactory::GetParent(string const & country) const
return m_countryParentNameGetterFn(country);
}
+double GetMaxWeight(VehicleModel::InOutCitySpeedKMpH const & speed)
+{
+ return max(speed.m_inCity.m_weight, speed.m_outCity.m_weight);
+}
+
+double GetMaxEta(VehicleModel::InOutCitySpeedKMpH const & speed)
+{
+ return max(speed.m_inCity.m_eta, speed.m_outCity.m_eta);
+}
+
+VehicleModel::SpeedKMpH GetMax(VehicleModel::InOutCitySpeedKMpH const & speed)
+{
+ return {GetMaxWeight(speed), GetMaxEta(speed)};
+}
+
string DebugPrint(VehicleModelInterface::RoadAvailability const l)
{
switch (l)
@@ -274,4 +299,13 @@ std::string DebugPrint(VehicleModelInterface::SpeedKMpH const & speed)
oss << "eta:" << speed.m_eta << " ]";
return oss.str();
}
+
+std::string DebugPrint(VehicleModelInterface::InOutCitySpeedKMpH const & speed)
+{
+ ostringstream oss;
+ oss << "InOutCitySpeedKMpH [ ";
+ oss << "inCity:" << DebugPrint(speed.m_inCity) << ", ";
+ oss << "outCity:" << DebugPrint(speed.m_outCity) << " ]";
+ return oss.str();
+}
} // namespace routing
diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp
index 3b262f59e5..969d89d463 100644
--- a/routing_common/vehicle_model.hpp
+++ b/routing_common/vehicle_model.hpp
@@ -71,12 +71,10 @@ public:
/// @return Allowed weight and ETA speed in KMpH.
/// 0 means that it's forbidden to move on this feature or it's not a road at all.
+ // @TODO(bykoianko) A param if feature in city or not should be added.
virtual SpeedKMpH GetSpeed(FeatureType & f) const = 0;
- // @TODO(bykoianko) Method for getting speed in city and outside should be added.
-
- /// @returns Max weight and ETA speed in KMpH for this model
- virtual SpeedKMpH GetMaxSpeed() const = 0;
+ virtual InOutCitySpeedKMpH GetMaxSpeed() const = 0;
/// @return Offroad speed in KMpH for vehicle. This speed should be used for non-feature routing
/// e.g. to connect start point to nearest feature.
@@ -161,7 +159,7 @@ public:
/// VehicleModelInterface overrides:
SpeedKMpH GetSpeed(FeatureType & f) const override;
- SpeedKMpH GetMaxSpeed() const override { return m_maxSpeed; }
+ InOutCitySpeedKMpH GetMaxSpeed() const override { return m_maxSpeed; }
bool IsOneWay(FeatureType & f) const override;
bool IsRoad(FeatureType & f) const override;
bool IsPassThroughAllowed(FeatureType & f) const override;
@@ -206,9 +204,7 @@ protected:
SpeedKMpH GetMinTypeSpeed(feature::TypesHolder const & types) const;
- // @TODO(bykoianko) |m_maxSpeed| should be kept for in city and out city roads.
- // Use InOutCitySpeedKMpH structure.
- SpeedKMpH m_maxSpeed;
+ InOutCitySpeedKMpH m_maxSpeed;
private:
struct AdditionalRoadType final
@@ -280,6 +276,10 @@ protected:
CountryParentNameGetterFn m_countryParentNameGetterFn;
};
+VehicleModel::SpeedKMpH GetMax(VehicleModel::InOutCitySpeedKMpH const & speed);
+double GetMaxWeight(VehicleModel::InOutCitySpeedKMpH const & speed);
+
std::string DebugPrint(VehicleModelInterface::RoadAvailability const l);
std::string DebugPrint(VehicleModelInterface::SpeedKMpH const & speed);
+std::string DebugPrint(VehicleModelInterface::InOutCitySpeedKMpH const & speed);
} // namespace routing