From d3e6aa0b15d4bf3993bb25af36e223b3254ed4db Mon Sep 17 00:00:00 2001 From: vng Date: Sat, 11 Jan 2014 14:56:31 +0300 Subject: [PATCH] [search] Added some diagnostics into street's merging. --- search/house_detector.cpp | 68 +++++++++++++++++--- search/house_detector.hpp | 5 ++ search/search_query.cpp | 5 +- search/search_tests/house_detector_tests.cpp | 20 +++++- 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/search/house_detector.cpp b/search/house_detector.cpp index 89334cc788..29a455bcf5 100644 --- a/search/house_detector.cpp +++ b/search/house_detector.cpp @@ -126,17 +126,25 @@ m2::RectD Street::GetLimitRect(double offsetMeters) const void Street::SetName(string const & name) { m_name = name; - strings::SimpleTokenizer iter(name, " -"); + strings::SimpleTokenizer iter(name, "\t -,."); GetStreetName(iter, m_processedName); strings::MakeLowerCase(m_processedName); } namespace { + bool LessDistance(HouseProjection const & p1, HouseProjection const & p2) { return p1.m_streetDistance < p2.m_streetDistance; } + +double GetDistanceMeters(m2::PointD const & p1, m2::PointD const & p2) +{ + return ms::DistanceOnEarth(MercatorBounds::YToLat(p1.y), MercatorBounds::XToLon(p1.x), + MercatorBounds::YToLat(p2.y), MercatorBounds::XToLon(p2.x)); +} + } void Street::SortHousesProjection() @@ -154,11 +162,13 @@ HouseDetector::HouseDetector(Index const * pIndex) void HouseDetector::SetMetres2Mercator(double factor) { m_epsMercator = factor * STREET_CONNECTION_LENGTH_M; + + LOG(LDEBUG, ("Street join epsilon = ", m_epsMercator)); } void HouseDetector::FillQueue(queue & q, Street const * street, bool isBeg) { - pair const & range = + pair const range = m_end2st.equal_range(isBeg ? street->m_points.front() : street->m_points.back()); for (IterT it = range.first; it != range.second; ++it) @@ -211,9 +221,17 @@ int HouseDetector::LoadStreets(vector & ids) st->SetName(name); f.ForEachPoint(StreetCreator(st), FeatureType::BEST_GEOMETRY); + if (m_end2st.empty()) + { + m2::PointD const p1 = st->m_points.front(); + m2::PointD const p2 = st->m_points.back(); + + SetMetres2Mercator(p1.Length(p2) / GetDistanceMeters(p1, p2)); + } + m_id2st[ids[i]] = st; - m_end2st.insert(pair (st->m_points.front(), st)); - m_end2st.insert(pair (st->m_points.back(), st)); + m_end2st.insert(make_pair(st->m_points.front(), st)); + m_end2st.insert(make_pair(st->m_points.back(), st)); } else ASSERT(false, ()); @@ -225,6 +243,8 @@ int HouseDetector::LoadStreets(vector & ids) int HouseDetector::MergeStreets() { + LOG(LDEBUG, ("MergeStreets() called", m_end2st.size())); + for (IterT it = m_end2st.begin(); it != m_end2st.end(); ++it) { if (it->second->m_number == -1) @@ -263,12 +283,6 @@ public: } }; -double GetDistanceMeters(m2::PointD const & p1, m2::PointD const & p2) -{ - return ms::DistanceOnEarth(MercatorBounds::YToLat(p1.y), MercatorBounds::XToLon(p1.x), - MercatorBounds::YToLat(p2.y), MercatorBounds::XToLon(p2.x)); -} - class ProjectionCalcToStreet { vector const & m_points; @@ -651,8 +665,42 @@ void HouseDetector::GetHouseForName(string const & houseNumber, vector > sets; for (size_t i = 0; i < count; ++i) { + sets.push_back(set()); + for (size_t j = 0; j < m_streets[i].size(); ++j) + { + sets.back().insert(m_streets[i][j]->m_points.front()); + sets.back().insert(m_streets[i][j]->m_points.back()); + } + } + + double dist = numeric_limits::max(); + for (size_t i = 0; i < sets.size()-1; ++i) + for (size_t j = i+1; j < sets.size(); ++j) + { + for (set::const_iterator it1 = sets[i].begin(); it1 != sets[i].end(); ++it1) + for (set::const_iterator it2 = sets[j].begin(); it2 != sets[j].end(); ++it2) + { + double const d = GetDistanceMeters(*it1, *it2); + if (d < dist) + dist = d; + } + } + + LOG(LDEBUG, ("Minimal distance = ", dist)); +#endif + + for (size_t i = 0; i < count; ++i) + { + LOG(LDEBUG, (Street::GetDbgName(m_streets[i]))); + House const * house = GetLSHouse(m_streets[i], houseNumber); if (house == 0) house = GetClosestHouse(m_streets[i], houseNumber); diff --git a/search/house_detector.hpp b/search/house_detector.hpp index 5d1402ea30..651a10cc2b 100644 --- a/search/house_detector.hpp +++ b/search/house_detector.hpp @@ -102,6 +102,11 @@ public: { return s1->m_processedName == s2->m_processedName; } + + inline static string GetDbgName(vector const & streets) + { + return streets.front()->m_processedName; + } }; class HouseDetector diff --git a/search/search_query.cpp b/search/search_query.cpp index e9d5143902..9c9587ff48 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -318,8 +318,9 @@ bool IsNumber(strings::UniString const & s) /// Check that token can be house number. bool IsHouseNumber(strings::UniString const & s) { + size_t const count = s.size(); /// @todo Probably, call some check function from House:: - return (s.size() < 8 && s[0] <= 127 && isdigit(s[0])); + return (count > 0 && count < 8 && s[0] <= 127 && isdigit(s[0])); } } @@ -573,9 +574,11 @@ void Query::FlushResults(Results & res, void (Results::*pAddFn)(Result const &)) m_houseDetector.GetHouseForName(strings::ToUtf8(m_house), houses); for (size_t i = 0; i < houses.size(); ++i) + { (res.*pAddFn)(Result(houses[i]->GetPosition(), houses[i]->GetNumber(), string(), string(), IsValidPosition() ? houses[i]->GetPosition().Length(m_position) : -1.0)); + } } #endif diff --git a/search/search_tests/house_detector_tests.cpp b/search/search_tests/house_detector_tests.cpp index b8d7485b24..3183c355f9 100644 --- a/search/search_tests/house_detector_tests.cpp +++ b/search/search_tests/house_detector_tests.cpp @@ -74,8 +74,8 @@ UNIT_TEST(LESS_WITH_EPSILON) struct Process { - vector vect; - vector streetNames; + vector vect; + vector streetNames; void operator() (FeatureType const & f) { if (f.GetFeatureType() == feature::GEOM_LINE) @@ -101,12 +101,24 @@ UNIT_TEST(STREET_MERGE_TEST) Index index; m2::RectD rect; - index.Add("minsk-pass.mwm", rect); + TEST(index.Add("minsk-pass.mwm", rect), ()); + + { + search::HouseDetector houser(&index); + Process toDo; + toDo.streetNames.push_back("улица Володарского"); + index.ForEachInScale(toDo, scales::GetUpperScale()); + LOG(LINFO, ("Count = ", toDo.vect.size())); + houser.LoadStreets(toDo.vect); + TEST_EQUAL(houser.MergeStreets(), 1, ()); + } + { search::HouseDetector houser(&index); Process toDo; toDo.streetNames.push_back("Московская улица"); index.ForEachInScale(toDo, scales::GetUpperScale()); + LOG(LINFO, ("Count = ", toDo.vect.size())); houser.LoadStreets(toDo.vect); TEST_EQUAL(houser.MergeStreets(), 1, ()); } @@ -120,6 +132,7 @@ UNIT_TEST(STREET_MERGE_TEST) houser.LoadStreets(toDo.vect); TEST_EQUAL(houser.MergeStreets(), 2, ()); } + { search::HouseDetector houser(&index); Process toDo; @@ -132,6 +145,7 @@ UNIT_TEST(STREET_MERGE_TEST) houser.LoadStreets(toDo.vect); TEST_EQUAL(houser.MergeStreets(), 5, ()); } + { search::HouseDetector houser(&index); Process toDo;