forked from organicmaps/organicmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar_model.cpp
286 lines (241 loc) · 13.6 KB
/
car_model.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#include "routing_common/car_model.hpp"
#include "base/macros.hpp"
#include "indexer/classificator.hpp"
#include <vector>
using namespace std;
using namespace routing;
namespace
{
using InOutCitySpeedKMpH = VehicleModel::InOutCitySpeedKMpH;
using SpeedKMpH = VehicleModel::SpeedKMpH;
// See model specifics in different countries here:
// https://wiki.openstreetmap.org/wiki/OSM_tags_for_routing/Access-Restrictions
// See road types here:
// https://wiki.openstreetmap.org/wiki/Key:highway
// Speed of road features located inside and outside cities and towns polygons in km per hour.
// in city out city
InOutCitySpeedKMpH const kSpeedMotorwayKMpH(SpeedKMpH(115.37), SpeedKMpH(115.37));
InOutCitySpeedKMpH const kSpeedMotorwayLinkKMpH(SpeedKMpH(75.0), SpeedKMpH(75.0));
InOutCitySpeedKMpH const kSpeedTrunkKMpH(SpeedKMpH(70.0), SpeedKMpH(93.89));
InOutCitySpeedKMpH const kSpeedTrunkLinkKMpH(SpeedKMpH(50.0), SpeedKMpH(70.0));
InOutCitySpeedKMpH const kSpeedPrimaryKMpH(SpeedKMpH(65.0), SpeedKMpH(84.29));
InOutCitySpeedKMpH const kSpeedPrimaryLinkKMpH(SpeedKMpH(55.0), SpeedKMpH(60.0));
InOutCitySpeedKMpH const kSpeedSecondaryKMpH(SpeedKMpH(45.0), SpeedKMpH(72.23));
InOutCitySpeedKMpH const kSpeedSecondaryLinkKMpH(SpeedKMpH(40.0), SpeedKMpH(50.0));
InOutCitySpeedKMpH const kSpeedTertiaryKMpH(SpeedKMpH(40.0), SpeedKMpH(62.63));
InOutCitySpeedKMpH const kSpeedTertiaryLinkKMpH(SpeedKMpH(30.0), SpeedKMpH(30.0));
InOutCitySpeedKMpH const kSpeedResidentialKMpH(SpeedKMpH(25.0), SpeedKMpH(25.0));
InOutCitySpeedKMpH const kSpeedUnclassifiedKMpH(SpeedKMpH(25.0), SpeedKMpH(51.09));
InOutCitySpeedKMpH const kSpeedServiceKMpH(SpeedKMpH(15.0), SpeedKMpH(15.0));
InOutCitySpeedKMpH const kSpeedLivingStreetKMpH(SpeedKMpH(10.0), SpeedKMpH(10.0));
InOutCitySpeedKMpH const kSpeedRoadKMpH(SpeedKMpH(10.0), SpeedKMpH(10.0));
InOutCitySpeedKMpH const kSpeedTrackKMpH(SpeedKMpH(5.0), SpeedKMpH(5.0));
InOutCitySpeedKMpH const kSpeedFerryMotorcarKMpH(SpeedKMpH(15.0), SpeedKMpH(15.0));
InOutCitySpeedKMpH const kSpeedFerryMotorcarVehicleKMpH(SpeedKMpH(15.0), SpeedKMpH(15.0));
InOutCitySpeedKMpH const kSpeedRailMotorcarVehicleKMpH(SpeedKMpH(15.0), SpeedKMpH(15.0));
InOutCitySpeedKMpH const kSpeedShuttleTrainKMpH(SpeedKMpH(25.0), SpeedKMpH(25.0));
InOutCitySpeedKMpH const kSpeedPierKMpH(SpeedKMpH(10.0), SpeedKMpH(10.0));
double constexpr kSpeedOffroadKMpH = 10.0;
VehicleModel::LimitsInitList const g_carLimitsDefault =
{
// {{roadType, roadType} Speed km per hour passThroughAllowed}
{{"highway", "motorway"}, kSpeedMotorwayKMpH, true},
{{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true},
{{"highway", "trunk"}, kSpeedTrunkKMpH, true},
{{"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true},
{{"highway", "primary"}, kSpeedPrimaryKMpH, true},
{{"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true},
{{"highway", "secondary"}, kSpeedSecondaryKMpH, true},
{{"highway", "secondary_link"}, kSpeedSecondaryLinkKMpH, true},
{{"highway", "tertiary"}, kSpeedTertiaryKMpH, true},
{{"highway", "tertiary_link"}, kSpeedTertiaryLinkKMpH, true},
{{"highway", "residential"}, kSpeedResidentialKMpH, true},
{{"highway", "unclassified"}, kSpeedUnclassifiedKMpH, true},
{{"highway", "service"}, kSpeedServiceKMpH, true},
{{"highway", "living_street"}, kSpeedLivingStreetKMpH, true},
{{"highway", "road"}, kSpeedRoadKMpH, true},
{{"highway", "track"}, kSpeedTrackKMpH, true}
/// @todo: Add to classificator
//{ {"highway", "shuttle_train"}, 10 },
//{ {"highway", "ferry"}, 5 },
//{ {"highway", "default"}, 10 },
/// @todo: Check type
//{ {"highway", "construction"}, 40 },
};
VehicleModel::LimitsInitList const g_carLimitsNoPassThroughLivingStreet =
{
{{"highway", "motorway"}, kSpeedMotorwayKMpH, true},
{{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true},
{{"highway", "trunk"}, kSpeedTrunkKMpH, true},
{{"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true},
{{"highway", "primary"}, kSpeedPrimaryKMpH, true},
{{"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true},
{{"highway", "secondary"}, kSpeedSecondaryKMpH, true},
{{"highway", "secondary_link"}, kSpeedSecondaryLinkKMpH, true},
{{"highway", "tertiary"}, kSpeedTertiaryKMpH, true},
{{"highway", "tertiary_link"}, kSpeedTertiaryLinkKMpH, true},
{{"highway", "residential"}, kSpeedResidentialKMpH, true},
{{"highway", "unclassified"}, kSpeedUnclassifiedKMpH, true},
{{"highway", "service"}, kSpeedServiceKMpH, true},
{{"highway", "living_street"}, kSpeedLivingStreetKMpH, false},
{{"highway", "road"}, kSpeedRoadKMpH, true},
{{"highway", "track"}, kSpeedTrackKMpH, true}
};
VehicleModel::LimitsInitList const g_carLimitsNoPassThroughLivingStreetAndService =
{
{{"highway", "motorway"}, kSpeedMotorwayKMpH, true},
{{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true},
{{"highway", "trunk"}, kSpeedTrunkKMpH, true},
{{"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true},
{{"highway", "primary"}, kSpeedPrimaryKMpH, true},
{{"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true},
{{"highway", "secondary"}, kSpeedSecondaryKMpH, true},
{{"highway", "secondary_link"}, kSpeedSecondaryLinkKMpH, true},
{{"highway", "tertiary"}, kSpeedTertiaryKMpH, true},
{{"highway", "tertiary_link"}, kSpeedTertiaryLinkKMpH, true},
{{"highway", "residential"}, kSpeedResidentialKMpH, true},
{{"highway", "unclassified"}, kSpeedUnclassifiedKMpH, true},
{{"highway", "service"}, kSpeedServiceKMpH, false},
{{"highway", "living_street"}, kSpeedLivingStreetKMpH, false},
{{"highway", "road"}, kSpeedRoadKMpH, true},
{{"highway", "track"}, kSpeedTrackKMpH, true}
};
VehicleModel::LimitsInitList const g_carLimitsAustralia = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsAustria = g_carLimitsNoPassThroughLivingStreet;
VehicleModel::LimitsInitList const g_carLimitsBelarus = g_carLimitsNoPassThroughLivingStreet;
VehicleModel::LimitsInitList const g_carLimitsBelgium = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsBrazil = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsDenmark =
{
// No track
{{"highway", "motorway"}, kSpeedMotorwayKMpH, true},
{{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true},
{{"highway", "trunk"}, kSpeedTrunkKMpH, true},
{{"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true},
{{"highway", "primary"}, kSpeedPrimaryKMpH, true},
{{"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true},
{{"highway", "secondary"}, kSpeedSecondaryKMpH, true},
{{"highway", "secondary_link"}, kSpeedSecondaryLinkKMpH, true},
{{"highway", "tertiary"}, kSpeedTertiaryKMpH, true},
{{"highway", "tertiary_link"}, kSpeedTertiaryLinkKMpH, true},
{{"highway", "residential"}, kSpeedResidentialKMpH, true},
{{"highway", "unclassified"}, kSpeedUnclassifiedKMpH, true},
{{"highway", "service"}, kSpeedServiceKMpH, true},
{{"highway", "living_street"}, kSpeedLivingStreetKMpH, true},
{{"highway", "road"}, kSpeedRoadKMpH, true}
};
VehicleModel::LimitsInitList const g_carLimitsFrance = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsFinland = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsGermany =
{
// No pass through track
{{"highway", "motorway"}, kSpeedMotorwayKMpH, true},
{{"highway", "motorway_link"}, kSpeedMotorwayLinkKMpH, true},
{{"highway", "trunk"}, kSpeedTrunkKMpH, true},
{{"highway", "trunk_link"}, kSpeedTrunkLinkKMpH, true},
{{"highway", "primary"}, kSpeedPrimaryKMpH, true},
{{"highway", "primary_link"}, kSpeedPrimaryLinkKMpH, true},
{{"highway", "secondary"}, kSpeedSecondaryKMpH, true},
{{"highway", "secondary_link"}, kSpeedSecondaryLinkKMpH, true},
{{"highway", "tertiary"}, kSpeedTertiaryKMpH, true},
{{"highway", "tertiary_link"}, kSpeedTertiaryLinkKMpH, true},
{{"highway", "residential"}, kSpeedResidentialKMpH, true},
{{"highway", "unclassified"}, kSpeedUnclassifiedKMpH, true},
{{"highway", "service"}, kSpeedServiceKMpH, true},
{{"highway", "living_street"}, kSpeedLivingStreetKMpH, true},
{{"highway", "road"}, kSpeedRoadKMpH, true},
{{"highway", "track"}, kSpeedTrackKMpH, false}
};
VehicleModel::LimitsInitList const g_carLimitsHungary = g_carLimitsNoPassThroughLivingStreet;
VehicleModel::LimitsInitList const g_carLimitsIceland = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsNetherlands = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsNorway = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsOman = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsPoland = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsRomania = g_carLimitsNoPassThroughLivingStreet;
VehicleModel::LimitsInitList const g_carLimitsRussia = g_carLimitsNoPassThroughLivingStreetAndService;
VehicleModel::LimitsInitList const g_carLimitsSlovakia = g_carLimitsNoPassThroughLivingStreet;
VehicleModel::LimitsInitList const g_carLimitsSpain = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsSwitzerland = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsTurkey = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsUkraine = g_carLimitsNoPassThroughLivingStreetAndService;
VehicleModel::LimitsInitList const g_carLimitsUK = g_carLimitsDefault;
VehicleModel::LimitsInitList const g_carLimitsUS = g_carLimitsDefault;
vector<VehicleModel::AdditionalRoadTags> const kAdditionalTags = {
// {{highway tags}, {weightSpeed, etaSpeed}}
{{"route", "ferry", "motorcar"}, kSpeedFerryMotorcarKMpH},
{{"route", "ferry", "motor_vehicle"}, kSpeedFerryMotorcarVehicleKMpH},
{{"railway", "rail", "motor_vehicle"}, kSpeedRailMotorcarVehicleKMpH},
{{"route", "shuttle_train"}, kSpeedShuttleTrainKMpH},
{{"route", "ferry"}, kSpeedFerryMotorcarKMpH},
{{"man_made", "pier"}, kSpeedPierKMpH}
};
VehicleModel::SurfaceInitList const g_carSurface = {
// {{surfaceType, surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {0.5, 0.5}},
{{"psurface", "unpaved_good"}, {0.8, 0.8}},
{{"psurface", "unpaved_bad"}, {0.3, 0.3}}
};
} // namespace
namespace routing
{
CarModel::CarModel()
: VehicleModel(classif(), g_carLimitsDefault, g_carSurface)
{
InitAdditionalRoadTypes();
}
CarModel::CarModel(VehicleModel::LimitsInitList const & roadLimits)
: VehicleModel(classif(), roadLimits, g_carSurface)
{
InitAdditionalRoadTypes();
}
double CarModel::GetOffroadSpeed() const { return kSpeedOffroadKMpH; }
void CarModel::InitAdditionalRoadTypes()
{
SetAdditionalRoadTypes(classif(), kAdditionalTags);
}
// static
CarModel const & CarModel::AllLimitsInstance()
{
static CarModel const instance;
return instance;
}
// static
routing::VehicleModel::LimitsInitList const & CarModel::GetLimits() { return g_carLimitsDefault; }
// static
vector<routing::VehicleModel::AdditionalRoadTags> const & CarModel::GetAdditionalTags()
{
return kAdditionalTags;
}
CarModelFactory::CarModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn)
: VehicleModelFactory(countryParentNameGetterFn)
{
// Names must be the same with country names from countries.txt
m_models[""] = make_shared<CarModel>(g_carLimitsDefault);
m_models["Australia"] = make_shared<CarModel>(g_carLimitsAustralia);
m_models["Austria"] = make_shared<CarModel>(g_carLimitsAustria);
m_models["Belarus"] = make_shared<CarModel>(g_carLimitsBelarus);
m_models["Belgium"] = make_shared<CarModel>(g_carLimitsBelgium);
m_models["Brazil"] = make_shared<CarModel>(g_carLimitsBrazil);
m_models["Denmark"] = make_shared<CarModel>(g_carLimitsDenmark);
m_models["France"] = make_shared<CarModel>(g_carLimitsFrance);
m_models["Finland"] = make_shared<CarModel>(g_carLimitsFinland);
m_models["Germany"] = make_shared<CarModel>(g_carLimitsGermany);
m_models["Hungary"] = make_shared<CarModel>(g_carLimitsHungary);
m_models["Iceland"] = make_shared<CarModel>(g_carLimitsIceland);
m_models["Netherlands"] = make_shared<CarModel>(g_carLimitsNetherlands);
m_models["Norway"] = make_shared<CarModel>(g_carLimitsNorway);
m_models["Oman"] = make_shared<CarModel>(g_carLimitsOman);
m_models["Poland"] = make_shared<CarModel>(g_carLimitsPoland);
m_models["Romania"] = make_shared<CarModel>(g_carLimitsRomania);
m_models["Russian Federation"] = make_shared<CarModel>(g_carLimitsRussia);
m_models["Slovakia"] = make_shared<CarModel>(g_carLimitsSlovakia);
m_models["Spain"] = make_shared<CarModel>(g_carLimitsSpain);
m_models["Switzerland"] = make_shared<CarModel>(g_carLimitsSwitzerland);
m_models["Turkey"] = make_shared<CarModel>(g_carLimitsTurkey);
m_models["Ukraine"] = make_shared<CarModel>(g_carLimitsUkraine);
m_models["United Kingdom"] = make_shared<CarModel>(g_carLimitsUK);
m_models["United States of America"] = make_shared<CarModel>(g_carLimitsUS);
}
} // namespace routing