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
|
#include "routing/edge_estimator.hpp"
#include "std/algorithm.hpp"
namespace routing
{
double constexpr kKMPH2MPS = 1000.0 / (60 * 60);
inline double TimeBetweenSec(m2::PointD const & from, m2::PointD const & to, double speedMPS)
{
ASSERT_GREATER(speedMPS, 0.0, ());
double const distanceM = MercatorBounds::DistanceOnEarth(from, to);
return distanceM / speedMPS;
}
class CarEdgeEstimator : public EdgeEstimator
{
public:
CarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel);
// EdgeEstimator overrides:
double CalcEdgesWeight(RoadGeometry const & road, uint32_t pointFrom,
uint32_t pointTo) const override;
double CalcHeuristic(m2::PointD const & from, m2::PointD const & to) const override;
private:
double const m_maxSpeedMPS;
};
CarEdgeEstimator::CarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel)
: m_maxSpeedMPS(vehicleModel->GetMaxSpeed() * kKMPH2MPS)
{
}
double CarEdgeEstimator::CalcEdgesWeight(RoadGeometry const & road, uint32_t pointFrom,
uint32_t pointTo) const
{
uint32_t const start = min(pointFrom, pointTo);
uint32_t const finish = max(pointFrom, pointTo);
ASSERT_LESS(finish, road.GetPointsCount(), ());
double result = 0.0;
double const speedMPS = road.GetSpeed() * kKMPH2MPS;
for (uint32_t i = start; i < finish; ++i)
result += TimeBetweenSec(road.GetPoint(i), road.GetPoint(i + 1), speedMPS);
return result;
}
double CarEdgeEstimator::CalcHeuristic(m2::PointD const & from, m2::PointD const & to) const
{
return TimeBetweenSec(from, to, m_maxSpeedMPS);
}
} // namespace
namespace routing
{
shared_ptr<EdgeEstimator> CreateCarEdgeEstimator(shared_ptr<IVehicleModel> vehicleModel)
{
return make_shared<CarEdgeEstimator>(vehicleModel);
}
} // namespace routing
|