PR routing fixes

This commit is contained in:
Lev Dragunov 2015-02-13 17:02:44 +03:00 committed by Alex Zolotarev
parent 714a7e1a37
commit a2524383f6
8 changed files with 69 additions and 73 deletions

View file

@ -62,10 +62,8 @@ template <class DataFacadeT> class NMManyToManyRouting final : public BasicRouti
{
}
~NMManyToManyRouting() {}
std::shared_ptr<std::vector<EdgeWeight>> operator()(const PhantomNodeArray &phantom_sources_nodes_array, const PhantomNodeArray &phantom_targets_nodes_array)
const
std::shared_ptr<std::vector<EdgeWeight>> operator()(const PhantomNodeArray &phantom_sources_nodes_array,
const PhantomNodeArray &phantom_targets_nodes_array) const
{
const unsigned number_of_sources = static_cast<unsigned>(phantom_sources_nodes_array.size());
const unsigned number_of_targets = static_cast<unsigned>(phantom_targets_nodes_array.size());

View file

@ -4,17 +4,10 @@
#include "borders_loader.hpp"
#include "gen_mwm_info.hpp"
#include "../3party/osrm/osrm-backend/DataStructures/EdgeBasedNodeData.h"
#include "../3party/osrm/osrm-backend/DataStructures/QueryEdge.h"
#include "../3party/osrm/osrm-backend/DataStructures/RawRouteData.h"
#include "../base/logging.hpp"
#include "../coding/file_container.hpp"
#include "../coding/read_write_utils.hpp"
#include "../coding/internal/file_data.hpp"
#include "../geometry/distance_on_sphere.hpp"
#include "../routing/osrm2feature_map.hpp"
#include "../routing/osrm_data_facade.hpp"
#include "../routing/osrm_router.hpp"
#include "../routing/cross_routing_context.hpp"
#include "../indexer/index.hpp"
#include "../indexer/classificator_loader.hpp"
@ -22,13 +15,20 @@
#include "../indexer/ftypes_matcher.hpp"
#include "../indexer/mercator.hpp"
#include "../routing/osrm2feature_map.hpp"
#include "../routing/osrm_data_facade.hpp"
#include "../routing/osrm_router.hpp"
#include "../routing/cross_routing_context.hpp"
#include "../geometry/distance_on_sphere.hpp"
#include "../coding/file_container.hpp"
#include "../coding/read_write_utils.hpp"
#include "../coding/internal/file_data.hpp"
#include "../base/logging.hpp"
#include "../std/fstream.hpp"
#include "../3party/osrm/osrm-backend/DataStructures/EdgeBasedNodeData.h"
#include "../3party/osrm/osrm-backend/DataStructures/QueryEdge.h"
#include "../3party/osrm/osrm-backend/DataStructures/RawRouteData.h"
namespace routing
{

View file

@ -2,8 +2,8 @@
#include "../std/string.hpp"
#include "../std/vector.hpp"
#include "../std/set.hpp"
namespace routing
{

View file

@ -1,7 +1,7 @@
#include "cross_routing_context.hpp"
using namespace routing;
namespace routing
{
size_t CrossRoutingContextReader::GetIndexInAdjMatrix(IngoingEdgeIteratorT ingoing, OutgoingEdgeIteratorT outgoing) const
{
size_t ingoing_index = distance(m_ingoingNodes.cbegin(), ingoing);
@ -134,3 +134,4 @@ pair<OutgoingEdgeIteratorT, OutgoingEdgeIteratorT> CrossRoutingContextWriter::Ge
{
return make_pair(m_outgoingNodes.cbegin(), m_outgoingNodes.cend());
}
}

View file

@ -1,27 +1,26 @@
#pragma once
#include "cross_routing_context.hpp"
#include "../defines.hpp"
#include "../std/string.hpp"
#include "../base/bits.hpp"
#include "../coding/file_container.hpp"
#include "../coding/read_write_utils.hpp"
#include "../base/bits.hpp"
#include "../std/string.hpp"
#include "../3party/succinct/elias_fano.hpp"
#include "../3party/succinct/elias_fano_compressed_list.hpp"
#include "../3party/succinct/gamma_vector.hpp"
#include "../3party/succinct/rs_bit_vector.hpp"
#include "../3party/succinct/mapper.hpp"
#include "../3party/osrm/osrm-backend/Server/DataStructures/BaseDataFacade.h"
#include "../3party/osrm/osrm-backend/DataStructures/TravelMode.h"
#include "../generator/routing_generator.hpp"
#include "cross_routing_context.hpp"
namespace routing
{

View file

@ -1,9 +1,7 @@
#include "osrm_router.hpp"
#include "vehicle_model.hpp"
#include "../std/algorithm.hpp"
#include "../base/math.hpp"
#include "../platform/platform.hpp"
#include "../geometry/angles.hpp"
#include "../geometry/distance.hpp"
@ -16,12 +14,13 @@
#include "../indexer/mwm_version.hpp"
#include "../indexer/search_string_utils.hpp"
#include "../platform/platform.hpp"
#include "../coding/reader_wrapper.hpp"
#include "../base/logging.hpp"
#include "../base/timer.hpp"
#include "../base/math.hpp"
#include "../std/algorithm.hpp"
#include "../3party/osrm/osrm-backend/DataStructures/SearchEngineData.h"
#include "../3party/osrm/osrm-backend/Descriptors/DescriptionFactory.h"
@ -341,10 +340,9 @@ public:
} // namespace
RoutingMappingPtrT RoutingIndexManager::GetMappingByPoint(m2::PointD point, Index const * pIndex)
RoutingMappingPtrT RoutingIndexManager::GetMappingByPoint(m2::PointD const & point, Index const * pIndex)
{
string fName = m_countryFn(point);
return GetMappingByName(fName, pIndex);
return GetMappingByName(m_countryFn(point), pIndex);
}
RoutingMappingPtrT RoutingIndexManager::GetMappingByName(string const & fName, Index const * pIndex)
@ -356,12 +354,13 @@ RoutingMappingPtrT RoutingIndexManager::GetMappingByName(string const & fName, I
// Or load and check file
RoutingMappingPtrT new_mapping = make_shared<RoutingMapping>(fName, pIndex);
m_mapping.insert(std::make_pair(fName, new_mapping));
m_mapping.insert(make_pair(fName, new_mapping));
return new_mapping;
}
RoutingMapping::RoutingMapping(string const & fName, Index const * pIndex): m_mapCounter(0), m_facadeCounter(0), m_baseName(fName),
m_isValid(true), m_error(IRouter::ResultCode::NoError)
RoutingMapping::RoutingMapping(string const & fName, Index const * pIndex)
: m_mapCounter(0), m_facadeCounter(0), m_baseName(fName),
m_isValid(true), m_error(IRouter::ResultCode::NoError)
{
Platform & pl = GetPlatform();
string const mwmName = m_baseName + DATA_FILE_EXTENSION;
@ -516,14 +515,7 @@ void OsrmRouter::CalculateRouteAsync(ReadyCallback const & callback)
try
{
try
{
code = CalculateRouteImpl(startPt, startDr, finalPt, route);
}
catch (OsrmRouter::ResultCode e)
{
code = e;
}
code = CalculateRouteImpl(startPt, startDr, finalPt, route);
switch (code)
{
case StartPointNotFound:
@ -570,7 +562,7 @@ bool IsRouteExist(RawRouteData const & r)
}
void OsrmRouter::FindWeightsMatrix(MultiroutingTaskPointT const & sources, MultiroutingTaskPointT const & targets,
RawDataFacadeT &facade, std::vector<EdgeWeight> &result)
RawDataFacadeT &facade, vector<EdgeWeight> &result)
{
SearchEngineData engineData;
NMManyToManyRouting<RawDataFacadeT> pathFinder(&facade, engineData);
@ -587,15 +579,15 @@ void OsrmRouter::FindWeightsMatrix(MultiroutingTaskPointT const & sources, Multi
}
my::HighResTimer timer1(true);
std::shared_ptr<std::vector<EdgeWeight>> resultTable = pathFinder(sourcesTaskVector, targetsTaskVector);
shared_ptr<vector<EdgeWeight>> resultTable = pathFinder(sourcesTaskVector, targetsTaskVector);
LOG(LINFO, ("Duration of a single one-to-many routing call", timer1.ElapsedNano()));
timer1.Reset();
ASSERT_EQUAL(resultTable->size(), sources.size() * targets.size(), ());
result.swap(*resultTable);
}
bool OsrmRouter::FindSingleRoute(FeatureGraphNodeVecT const & source, FeatureGraphNodeVecT const & target, DataFacadeT &facade,
RawRoutingResultT& rawRoutingResult)
bool OsrmRouter::FindSingleRoute(FeatureGraphNodeVecT const & source, FeatureGraphNodeVecT const & target, DataFacadeT & facade,
RawRoutingResultT & rawRoutingResult)
{
/// @todo: make more complex nearest edge turnaround
SearchEngineData engineData;
@ -654,13 +646,10 @@ m2::PointD OsrmRouter::GetPointByNodeId(const size_t node_id, RoutingMappingPtrT
loader.GetFeature(seg.m_fid, ft);
ft.ParseGeometry(FeatureType::BEST_GEOMETRY);
if (use_start)
return ft.GetPoint(seg.m_pointStart);
else
return ft.GetPoint(seg.m_pointEnd);
return use_start ? ft.GetPoint(seg.m_pointStart) : ft.GetPoint(seg.m_pointEnd);
}
void OsrmRouter::GenerateRoutingTaskFromNodeId(const size_t nodeId, FeatureGraphNode & taskNode)
void OsrmRouter::GenerateRoutingTaskFromNodeId(size_t const nodeId, FeatureGraphNode & taskNode)
{
taskNode.m_node.forward_node_id = static_cast<size_t>(nodeId);
taskNode.m_node.reverse_node_id = static_cast<size_t>(nodeId);
@ -688,9 +677,9 @@ size_t OsrmRouter::FindNextMwmNode(RoutingMappingPtrT const & startMapping, size
targetPointEnd = m2::PointD(MercatorBounds::XToLon(targetPointEnd.x), MercatorBounds::YToLat(targetPointEnd.y));
double const dist = min(min(ms::DistanceOnEarth(startPointEnd.y, startPointEnd.x, targetPoint.y, targetPoint.x),
ms::DistanceOnEarth(startPointStart.y, startPointStart.x, targetPoint.y, targetPoint.x)),
ms::DistanceOnEarth(startPointStart.y, startPointStart.x, targetPoint.y, targetPoint.x)),
min(ms::DistanceOnEarth(startPointEnd.y, startPointEnd.x, targetPointEnd.y, targetPointEnd.x),
ms::DistanceOnEarth(startPointStart.y, startPointStart.x, targetPointEnd.y, targetPointEnd.x)));
ms::DistanceOnEarth(startPointStart.y, startPointStart.x, targetPointEnd.y, targetPointEnd.x)));
if (dist < FEATURE_BY_POINT_RADIUS_M)
return *i;
}
@ -776,7 +765,8 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(CheckedPathT const &
return OsrmRouter::NoError;
}
class OsrmRouter::LastCrossFinder {
class OsrmRouter::LastCrossFinder
{
CrossRoutingContextReader const & m_targetContext;
string const m_mwmName;
MultiroutingTaskPointT m_sources;
@ -784,9 +774,9 @@ class OsrmRouter::LastCrossFinder {
vector<EdgeWeight> m_weights;
public:
LastCrossFinder(RoutingMappingPtrT & mapping, FeatureGraphNodeVecT const & targetTask):
m_targetContext(mapping->m_dataFacade.getRoutingContext()),
m_mwmName(mapping->GetName())
LastCrossFinder(RoutingMappingPtrT & mapping, FeatureGraphNodeVecT const & targetTask)
: m_targetContext(mapping->m_dataFacade.getRoutingContext()),
m_mwmName(mapping->GetName())
{
auto income_iterators = m_targetContext.GetIngoingIterators();
MultiroutingTaskPointT targets(1);
@ -811,7 +801,11 @@ public:
}
}
}
throw OsrmRouter::EndPointNotFound;
}
bool IsValid()
{
return (!m_weights.empty());
}
bool MakeLastCrossSegment(size_t const incomeNodeId, OsrmRouter::RoutePathCross & outCrossTask)
@ -958,6 +952,9 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRouteImpl(m2::PointD const & startPt
// Load target data
LastCrossFinder targetFinder(targetMapping, m_CachedTargetTask);
if(!targetFinder.IsValid())
return EndPointNotFound;
EdgeWeight finalWeight = INVALID_EDGE_WEIGHT;
CheckedPathT finalPath;
@ -1114,8 +1111,8 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRouteImpl(m2::PointD const & startPt
}
}
m2::PointD OsrmRouter::GetPointForTurnAngle(OsrmFtSegMapping::FtSeg const &seg,
FeatureType const &ft, m2::PointD const &turnPnt,
m2::PointD OsrmRouter::GetPointForTurnAngle(OsrmFtSegMapping::FtSeg const & seg,
FeatureType const & ft, m2::PointD const & turnPnt,
size_t (*GetPndInd)(const size_t, const size_t, const size_t)) const
{
const size_t maxPntsNum = 7;
@ -1155,7 +1152,7 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation(RawRoutingResultT const &
#ifdef _DEBUG
size_t lastIdx = 0;
#endif
for (auto i : osrm::irange<std::size_t>(0, routingResult.m_routePath.unpacked_path_segments.size()))
for (auto i : osrm::irange<size_t>(0, routingResult.m_routePath.unpacked_path_segments.size()))
{
if (m_requestCancel)
return Cancelled;

View file

@ -122,12 +122,12 @@ class RoutingIndexManager
{
CountryFileFnT m_countryFn;
std::map<string, RoutingMappingPtrT> m_mapping;
map<string, RoutingMappingPtrT> m_mapping;
public:
RoutingIndexManager(CountryFileFnT const & fn): m_countryFn(fn) {}
RoutingMappingPtrT GetMappingByPoint(m2::PointD point, Index const * pIndex);
RoutingMappingPtrT GetMappingByPoint(m2::PointD const & point, Index const * pIndex);
RoutingMappingPtrT GetMappingByName(string const & fName, Index const * pIndex);
@ -183,7 +183,7 @@ public:
* cost(source1 -> target1) cost(source1 -> target2) cost(source2 -> target1) cost(source2 -> target2)
*/
static void FindWeightsMatrix(MultiroutingTaskPointT const & sources, MultiroutingTaskPointT const & targets,
RawDataFacadeT & facade, std::vector<EdgeWeight> & result);
RawDataFacadeT & facade, vector<EdgeWeight> & result);
/*!
* \brief GenerateRoutingTaskFromNodeId fill taskNode with values for making route
@ -229,7 +229,8 @@ private:
typedef pair<size_t,string> MwmOutT;
typedef set<MwmOutT> CheckedOutsT;
struct RoutePathCross {
struct RoutePathCross
{
string mwmName;
FeatureGraphNode startNode;
FeatureGraphNode targetNode;
@ -243,7 +244,8 @@ private:
return accumulate(path.begin(), path.end(), 0, [](EdgeWeight sum, RoutePathCross const & elem){return sum+elem.weight;});
}
struct PathChecker {
struct PathChecker
{
bool operator() (CheckedPathT const & a, CheckedPathT const & b) const {
// Backward sorting order
return getPathWeight(b)<getPathWeight(a);

View file

@ -19,7 +19,6 @@ SOURCES += \
osrm2feature_map.cpp \
vehicle_model.cpp \
cross_routing_context.cpp \
../3party/succinct/rs_bit_vector.cpp \
HEADERS += \
turns.hpp \