[routing] Fix bug with resolving start/end points, when they have intersection in candidates set

This commit is contained in:
Denis Koronchik 2014-10-02 18:52:55 +03:00 committed by Alex Zolotarev
parent c839ecc692
commit 35a76a8ea4
3 changed files with 21 additions and 8 deletions

View file

@ -146,7 +146,7 @@ void OsrmFtSegMapping::DumpSegmentByNode(OsrmNodeIdT nodeId) const
}
void OsrmFtSegMapping::GetOsrmNodes(vector<FtSeg> & segments, OsrmNodesT & res) const
void OsrmFtSegMapping::GetOsrmNodes(FtSegSetT & segments, OsrmNodesT & res) const
{
auto addResFn = [&res](uint64_t seg, OsrmNodeIdT nodeId, bool forward)
{
@ -175,9 +175,9 @@ void OsrmFtSegMapping::GetOsrmNodes(vector<FtSeg> & segments, OsrmNodesT & res)
{
FtSeg s(m_segments[i]);
for (size_t j = 0; j < segments.size(); ++j)
for (auto it = segments.begin(); it != segments.end(); ++it)
{
FtSeg const & seg = segments[j];
FtSeg const & seg = *(*it);
if (s.m_fid != seg.m_fid)
continue;
@ -187,7 +187,7 @@ void OsrmFtSegMapping::GetOsrmNodes(vector<FtSeg> & segments, OsrmNodesT & res)
{
if (addResFn(seg.Store(), GetNodeId(i), true))
{
segments.erase(segments.begin() + j);
segments.erase(it);
break;
}
}
@ -198,7 +198,7 @@ void OsrmFtSegMapping::GetOsrmNodes(vector<FtSeg> & segments, OsrmNodesT & res)
{
if (addResFn(seg.Store(), GetNodeId(i), false))
{
segments.erase(segments.begin() + j);
segments.erase(it);
break;
}
}

View file

@ -71,6 +71,16 @@ public:
};
#pragma pack (pop)
struct FtSegLess
{
bool operator() (FtSeg const * a, FtSeg const * b) const
{
return a->Store() < b->Store();
}
};
typedef set<FtSeg*, FtSegLess> FtSegSetT;
void Clear();
void Load(FilesMappingContainer & cont);
@ -87,7 +97,7 @@ public:
}
typedef unordered_map<uint64_t, pair<OsrmNodeIdT, OsrmNodeIdT> > OsrmNodesT;
void GetOsrmNodes(vector<FtSeg> & segments, OsrmNodesT & res) const;
void GetOsrmNodes(FtSegSetT & segments, OsrmNodesT & res) const;
/// @name For debug purpose only.
//@{

View file

@ -107,6 +107,8 @@ public:
vector<OsrmFtSegMapping::FtSeg> segments;
segments.resize(maxCount * 2);
OsrmFtSegMapping::FtSegSetT segmentSet;
for (size_t i = 0; i < 2; ++i)
{
sort(m_candidates[i].begin(), m_candidates[i].end(), [] (Candidate const & r1, Candidate const & r2)
@ -123,12 +125,13 @@ public:
seg.m_fid = c.m_fid;
seg.m_pointStart = c.m_segIdx;
seg.m_pointEnd = c.m_segIdx + 1;
segmentSet.insert(&seg);
}
}
OsrmFtSegMapping::OsrmNodesT nodes;
vector<OsrmFtSegMapping::FtSeg> scopy(segments);
m_mapping.GetOsrmNodes(scopy, nodes);
m_mapping.GetOsrmNodes(segmentSet, nodes);
res.clear();
res.resize(maxCount * 2);