forked from organicmaps/organicmaps
Optimization: removed redundant copying and calculations
This commit is contained in:
parent
6ed6bb7777
commit
c0a5b3be88
5 changed files with 46 additions and 39 deletions
|
@ -42,24 +42,22 @@ public:
|
|||
|
||||
void operator()(FeatureType & ft)
|
||||
{
|
||||
// check type to skip not line objects
|
||||
if (ft.GetFeatureType() != feature::GEOM_LINE)
|
||||
return;
|
||||
|
||||
// skip roads with null speed
|
||||
double const speedKMPH = m_graph.GetSpeedKMPHFromFt(ft);
|
||||
if (speedKMPH <= 0.0)
|
||||
return;
|
||||
|
||||
FeatureID const fID = ft.GetID();
|
||||
if (fID.m_mwmId != m_graph.GetMwmID())
|
||||
return;
|
||||
|
||||
/// @todo remove overhead with type and speed checks (now speed loads in cache creation)
|
||||
// check type to skip not line objects
|
||||
feature::TypesHolder types(ft);
|
||||
if (types.GetGeoType() != feature::GEOM_LINE)
|
||||
return;
|
||||
|
||||
// skip roads with null speed
|
||||
double const speed = m_graph.GetSpeedKMPHFromFt(ft);
|
||||
if (speed <= 0.0)
|
||||
return;
|
||||
|
||||
// load feature from cache
|
||||
IRoadGraph::RoadInfo const & ri = m_graph.GetCachedRoadInfo(fID.m_offset, ft, false /*fullLoad*/);
|
||||
ASSERT_EQUAL(speed, ri.m_speedKMPH, ());
|
||||
IRoadGraph::RoadInfo const & ri = m_graph.GetCachedRoadInfo(fID.m_offset, true /*preload*/, ft, speedKMPH);
|
||||
ASSERT_EQUAL(speedKMPH, ri.m_speedKMPH, ());
|
||||
|
||||
m_edgesLoader(fID.m_offset, ri);
|
||||
}
|
||||
|
@ -82,13 +80,13 @@ void FeaturesRoadGraph::LoadFeature(uint32_t featureId, FeatureType & ft) const
|
|||
IRoadGraph::RoadInfo FeaturesRoadGraph::GetRoadInfo(uint32_t featureId) const
|
||||
{
|
||||
FeatureType ft;
|
||||
return GetCachedRoadInfo(featureId, ft, true /*fullLoad*/);
|
||||
return GetCachedRoadInfo(featureId, false /*preload*/, ft, 0.0 /*speedKMPH*/);
|
||||
}
|
||||
|
||||
double FeaturesRoadGraph::GetSpeedKMPH(uint32_t featureId) const
|
||||
{
|
||||
FeatureType ft;
|
||||
return GetCachedRoadInfo(featureId, ft, true /*fullLoad*/).m_speedKMPH;
|
||||
return GetCachedRoadInfo(featureId, false /*preload*/, ft, 0.0 /*speedKMPH*/).m_speedKMPH;
|
||||
}
|
||||
|
||||
double FeaturesRoadGraph::GetMaxSpeedKMPH() const
|
||||
|
@ -117,29 +115,37 @@ double FeaturesRoadGraph::GetSpeedKMPHFromFt(FeatureType const & ft) const
|
|||
}
|
||||
|
||||
IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(uint32_t featureId,
|
||||
FeatureType & ft, bool fullLoad) const
|
||||
bool preload,
|
||||
FeatureType & ft,
|
||||
double speedKMPH) const
|
||||
{
|
||||
bool found = false;
|
||||
RoadInfo & ri = m_cache.Find(featureId, found);
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (fullLoad)
|
||||
LoadFeature(featureId, ft);
|
||||
else
|
||||
if (preload)
|
||||
{
|
||||
// ft must be set
|
||||
ASSERT(featureId == ft.GetID().m_offset, ());
|
||||
ft.ParseGeometry(FeatureType::BEST_GEOMETRY);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadFeature(featureId, ft);
|
||||
speedKMPH = GetSpeedKMPHFromFt(ft);
|
||||
}
|
||||
|
||||
ri.m_bidirectional = !IsOneWay(ft);
|
||||
ri.m_speedKMPH = GetSpeedKMPHFromFt(ft);
|
||||
ri.m_speedKMPH = speedKMPH;
|
||||
ft.SwapPoints(ri.m_points);
|
||||
|
||||
m_cacheMiss++;
|
||||
}
|
||||
m_cacheAccess++;
|
||||
|
||||
ASSERT_EQUAL(ri.m_speedKMPH, GetSpeedKMPHFromFt(ft), ());
|
||||
|
||||
return ri;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
static uint32_t GetStreetReadScale();
|
||||
|
||||
inline MwmSet::MwmId GetMwmID() const { return m_mwmID; }
|
||||
inline MwmSet::MwmId const & GetMwmID() const { return m_mwmID; }
|
||||
|
||||
double GetCacheMiss() const
|
||||
{
|
||||
|
@ -49,8 +49,13 @@ private:
|
|||
double GetSpeedKMPHFromFt(FeatureType const & ft) const;
|
||||
void LoadFeature(uint32_t featureId, FeatureType & ft) const;
|
||||
|
||||
// ft must be set if fullLoad set to false (optimization)
|
||||
RoadInfo const & GetCachedRoadInfo(uint32_t featureId, FeatureType & ft, bool fullLoad) const;
|
||||
// Optimization:
|
||||
// If preload is set to true then feature ft is set and speedKMPH contains valid value,
|
||||
// otherwise feature is not set and must be load and speed is not valid.
|
||||
RoadInfo const & GetCachedRoadInfo(uint32_t featureId,
|
||||
bool preload,
|
||||
FeatureType & ft,
|
||||
double speedKMPH) const;
|
||||
|
||||
Index const & m_index;
|
||||
MwmSet::MwmId const m_mwmID;
|
||||
|
|
|
@ -165,9 +165,6 @@ IRoadGraph::CrossEdgesLoader::CrossEdgesLoader(m2::PointD const & cross, TEdgeVe
|
|||
|
||||
void IRoadGraph::CrossEdgesLoader::operator()(uint32_t featureId, RoadInfo const & roadInfo)
|
||||
{
|
||||
if (roadInfo.m_points.empty())
|
||||
return;
|
||||
|
||||
size_t const numPoints = roadInfo.m_points.size();
|
||||
|
||||
for (size_t i = 0; i < numPoints; ++i)
|
||||
|
@ -182,8 +179,7 @@ void IRoadGraph::CrossEdgesLoader::operator()(uint32_t featureId, RoadInfo const
|
|||
// p
|
||||
// o------------>o
|
||||
|
||||
Edge edge(featureId, false /* forward */, i - 1, p, roadInfo.m_points[i - 1]);
|
||||
m_outgoingEdges.push_back(edge);
|
||||
m_outgoingEdges.emplace_back(featureId, false /* forward */, i - 1, p, roadInfo.m_points[i - 1]);
|
||||
}
|
||||
|
||||
if (i < numPoints - 1)
|
||||
|
@ -191,8 +187,7 @@ void IRoadGraph::CrossEdgesLoader::operator()(uint32_t featureId, RoadInfo const
|
|||
// p
|
||||
// o------------>o
|
||||
|
||||
Edge edge(featureId, true /* forward */, i, p, roadInfo.m_points[i + 1]);
|
||||
m_outgoingEdges.push_back(edge);
|
||||
m_outgoingEdges.emplace_back(featureId, true /* forward */, i, p, roadInfo.m_points[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
|
||||
RoadGraph(IRoadGraph const & roadGraph)
|
||||
: m_roadGraph(roadGraph)
|
||||
, m_maxSpeedMPS(roadGraph.GetMaxSpeedKMPH() * KMPH2MPS)
|
||||
{}
|
||||
|
||||
void GetOutgoingEdgesList(Junction const & v, vector<WeightedEdge> & adj) const
|
||||
|
@ -55,13 +56,13 @@ public:
|
|||
|
||||
for (auto const & e : edges)
|
||||
{
|
||||
double const speedMPS = m_roadGraph.GetSpeedKMPH(e) * KMPH2MPS;
|
||||
if (speedMPS <= 0.0)
|
||||
double const speedKMPH = m_roadGraph.GetSpeedKMPH(e);
|
||||
if (speedKMPH <= 0.0)
|
||||
continue;
|
||||
|
||||
ASSERT_EQUAL(v, e.GetStartJunction(), ());
|
||||
|
||||
adj.emplace_back(e.GetEndJunction(), TimeBetweenSec(e.GetStartJunction(), e.GetEndJunction(), speedMPS));
|
||||
adj.emplace_back(e.GetEndJunction(), TimeBetweenSec(e.GetStartJunction(), e.GetEndJunction(), speedKMPH * KMPH2MPS));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,24 +76,24 @@ public:
|
|||
|
||||
for (auto const & e : edges)
|
||||
{
|
||||
double const speedMPS = m_roadGraph.GetSpeedKMPH(e) * KMPH2MPS;
|
||||
if (speedMPS <= 0.0)
|
||||
double const speedKMPH = m_roadGraph.GetSpeedKMPH(e);
|
||||
if (speedKMPH <= 0.0)
|
||||
continue;
|
||||
|
||||
ASSERT_EQUAL(v, e.GetEndJunction(), ());
|
||||
|
||||
adj.emplace_back(e.GetStartJunction(), TimeBetweenSec(e.GetStartJunction(), e.GetEndJunction(), speedMPS));
|
||||
adj.emplace_back(e.GetStartJunction(), TimeBetweenSec(e.GetStartJunction(), e.GetEndJunction(), speedKMPH * KMPH2MPS));
|
||||
}
|
||||
}
|
||||
|
||||
double HeuristicCostEstimate(Junction const & v, Junction const & w) const
|
||||
{
|
||||
double const speedMPS = m_roadGraph.GetMaxSpeedKMPH() * KMPH2MPS;
|
||||
return TimeBetweenSec(v, w, speedMPS);
|
||||
return TimeBetweenSec(v, w, m_maxSpeedMPS);
|
||||
}
|
||||
|
||||
private:
|
||||
IRoadGraph const & m_roadGraph;
|
||||
double const m_maxSpeedMPS;
|
||||
};
|
||||
|
||||
typedef AStarAlgorithm<RoadGraph> TAlgorithmImpl;
|
||||
|
|
|
@ -170,7 +170,7 @@ double PedestrianModel::GetSpeed(FeatureType const & f) const
|
|||
feature::TypesHolder types(f);
|
||||
|
||||
if (IsFoot(types) && IsRoad(types))
|
||||
return VehicleModel::GetSpeed(f);
|
||||
return VehicleModel::GetSpeed(types);
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue