[routing] Use CarModel in routing algorithms

This commit is contained in:
Denis Koronchik 2014-07-14 12:15:33 +02:00 committed by Alex Zolotarev
parent cc9bc8894e
commit a50246e174
4 changed files with 48 additions and 15 deletions

View file

@ -1,5 +1,6 @@
#include "features_road_graph.hpp"
#include "route.hpp"
#include "vehicle_model.hpp"
#include "../indexer/index.hpp"
#include "../indexer/classificator.hpp"
@ -19,7 +20,7 @@ double const DEFAULT_SPEED_MS = 15.0;
FeaturesRoadGraph::FeaturesRoadGraph(Index const * pIndex, size_t mwmID)
: m_pIndex(pIndex), m_mwmID(mwmID)
: m_pIndex(pIndex), m_mwmID(mwmID), m_vehicleModel(new CarModel())
{
}
@ -60,7 +61,7 @@ public:
ft.ParseGeometry(FeatureType::BEST_GEOMETRY);
bool const isOneWay = m_graph.IsOneway(types);
bool const isOneWay = m_graph.IsOneWay(ft);
size_t const count = ft.GetPointsCount();
PossibleTurn t;
@ -114,9 +115,14 @@ void FeaturesRoadGraph::GetPossibleTurns(RoadPos const & pos, vector<PossibleTur
FeatureType ft;
LoadFeature(ftId, ft);
double const speed = GetSpeed(ft);
if (speed <= 0.0)
return;
int const count = static_cast<int>(ft.GetPointsCount());
bool const isForward = pos.IsForward();
bool const isOneWay = IsOneway(ft);
bool const isOneWay = IsOneWay(ft);
int const inc = isForward ? -1 : 1;
int startID = pos.GetPointId();
@ -137,7 +143,7 @@ void FeaturesRoadGraph::GetPossibleTurns(RoadPos const & pos, vector<PossibleTur
double const segmentDistance = CalcDistanceMeters(ft.GetPoint(i), ft.GetPoint(i - inc));
distance += segmentDistance;
time += segmentDistance / DEFAULT_SPEED_MS;
time += segmentDistance / speed;
m2::PointD const & pt = ft.GetPoint(i);
@ -267,9 +273,15 @@ bool FeaturesRoadGraph::IsStreet(feature::TypesHolder const & types) const
ftypes::IsStreetChecker::Instance()(types));
}
bool FeaturesRoadGraph::IsOneway(feature::TypesHolder const & types) const
bool FeaturesRoadGraph::IsOneWay(FeatureType const & ft) const
{
return ftypes::IsStreetChecker::Instance().IsOneway(types);
return m_vehicleModel->IsOneWay(ft);
}
double FeaturesRoadGraph::GetSpeed(FeatureType const & ft) const
{
return m_vehicleModel->GetSpeed(ft);
}
} // namespace routing

View file

@ -1,6 +1,7 @@
#pragma once
#include "road_graph.hpp"
#include "../std/scoped_ptr.hpp"
class Index;
class FeatureType;
@ -13,6 +14,8 @@ namespace feature
namespace routing
{
class IVehicleModel;
class FeaturesRoadGraph : public IRoadGraph
{
public:
@ -29,13 +32,14 @@ private:
friend class CrossFeaturesLoader;
bool IsStreet(feature::TypesHolder const & types) const;
bool IsOneway(feature::TypesHolder const & types) const;
bool IsOneWay(FeatureType const & ft) const;
double GetSpeed(FeatureType const & ft) const;
void LoadFeature(uint32_t id, FeatureType & ft);
private:
Index const * m_pIndex;
size_t m_mwmID;
scoped_ptr<IVehicleModel> m_vehicleModel;
};
} // namespace routing

View file

@ -1,6 +1,7 @@
#include "road_graph_router.hpp"
#include "features_road_graph.hpp"
#include "route.hpp"
#include "vehicle_model.hpp"
#include "../indexer/feature.hpp"
#include "../indexer/ftypes_matcher.hpp"
@ -19,17 +20,19 @@ class Point2RoadPos
size_t m_segIdx;
bool m_isOneway;
FeatureID m_fID;
IVehicleModel const * m_vehicleModel;
public:
Point2RoadPos(m2::PointD const & pt)
: m_point(pt), m_minDist(numeric_limits<double>::max())
Point2RoadPos(m2::PointD const & pt, IVehicleModel const * vehicleModel)
: m_point(pt), m_minDist(numeric_limits<double>::max()), m_vehicleModel(vehicleModel)
{
}
void operator() (FeatureType const & ft)
{
if (ft.GetFeatureType() != feature::GEOM_LINE ||
!ftypes::IsStreetChecker::Instance()(ft))
double const speed = m_vehicleModel->GetSpeed(ft);
if (ft.GetFeatureType() != feature::GEOM_LINE || speed <= 0.0)
return;
ft.ParseGeometry(FeatureType::BEST_GEOMETRY);
@ -45,7 +48,7 @@ public:
m_minDist = d;
m_segIdx = i;
m_fID = ft.GetID();
m_isOneway = ftypes::IsStreetChecker::Instance().IsOneway(ft);
m_isOneway = m_vehicleModel->IsOneWay(ft);
}
}
}
@ -66,9 +69,19 @@ public:
}
};
RoadGraphRouter::~RoadGraphRouter()
{
}
RoadGraphRouter::RoadGraphRouter(Index const * pIndex) :
m_vehicleModel(new CarModel()), m_pIndex(pIndex)
{
}
size_t RoadGraphRouter::GetRoadPos(m2::PointD const & pt, vector<RoadPos> & pos)
{
Point2RoadPos getter(pt);
Point2RoadPos getter(pt, m_vehicleModel.get());
m_pIndex->ForEachInRect(getter,
MercatorBounds::RectByCenterXYAndSizeInMeters(pt, 100.0),
FeaturesRoadGraph::GetStreetReadScale());

View file

@ -14,10 +14,13 @@ class Index;
namespace routing
{
class IVehicleModel;
class RoadGraphRouter : public IRouter
{
public:
RoadGraphRouter(Index const * pIndex) : m_pIndex(pIndex) {}
RoadGraphRouter(Index const * pIndex);
~RoadGraphRouter();
virtual void SetFinalPoint(m2::PointD const & finalPt);
virtual void CalculateRoute(m2::PointD const & startPt, ReadyCallback const & callback);
@ -31,6 +34,7 @@ protected:
bool IsMyMWM(size_t mwmID) const;
scoped_ptr<IRoadGraph> m_pRoadGraph;
scoped_ptr<IVehicleModel> m_vehicleModel;
Index const * m_pIndex;
};