Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Gorbushin <m.gorbushin@corp.mail.ru>2019-03-14 13:02:36 +0300
committerVlad Mihaylenko <vxmihaylenko@gmail.com>2019-03-15 19:44:16 +0300
commitf9ed08034cc905000c6b07a963697ee86fc868f6 (patch)
tree9580924b207435425b7250e34d4239cd2d189135 /routing
parentf8b146675f5f525a42040bc9e17381ef235ec245 (diff)
[routing] repair restrcition tests, add one
Diffstat (limited to 'routing')
-rw-r--r--routing/routing_tests/cumulative_restriction_test.cpp152
-rw-r--r--routing/routing_tests/index_graph_tools.cpp13
-rw-r--r--routing/routing_tests/restriction_test.cpp49
3 files changed, 175 insertions, 39 deletions
diff --git a/routing/routing_tests/cumulative_restriction_test.cpp b/routing/routing_tests/cumulative_restriction_test.cpp
index e8814deff9..b76ef755a2 100644
--- a/routing/routing_tests/cumulative_restriction_test.cpp
+++ b/routing/routing_tests/cumulative_restriction_test.cpp
@@ -4,6 +4,7 @@
#include "routing/fake_ending.hpp"
#include "routing/geometry.hpp"
+#include "routing/restriction_loader.hpp"
#include "traffic/traffic_cache.hpp"
@@ -12,6 +13,7 @@
#include "geometry/point2d.hpp"
#include <memory>
+#include <utility>
#include <vector>
namespace
@@ -84,28 +86,34 @@ UNIT_TEST(XYGraph)
UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF1F3Only)
{
Init(BuildXYGraph());
- RestrictionVec restrictions = {
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {1 /* feature from */, 3 /* feature to */}}};
+ RestrictionVec restrictionsNo;
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
- MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictionsNo), *this);
}
// Route through XY graph with one restriciton (type only) from F3 to F5.
UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5Only)
{
Init(BuildXYGraph());
- RestrictionVec restrictions = {
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {3 /* feature from */, 5 /* feature to */}}};
+ RestrictionVec restrictionsNo;
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
- MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictionsNo), *this);
}
// Cumulative case. Route through XY graph with two restricitons (type only) applying
@@ -113,15 +121,18 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5Only)
UNIT_CLASS_TEST(RestrictionTest, XYGraph_PermutationsF3F5OnlyF1F3Only)
{
Init(BuildXYGraph());
- RestrictionVec restrictions = {
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {1 /* feature from */, 3 /* feature to */}},
{Restriction::Type::Only, {3 /* feature from */, 5 /* feature to */}}};
+ RestrictionVec restrictionsNo;
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
- MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictionsNo), *this);
}
// Cumulative case. Route through XY graph with two restricitons (type only and type no) applying
@@ -130,14 +141,21 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_PermutationsF3F5OnlyAndF0F2No)
{
Init(BuildXYGraph());
- RestrictionVec restrictions = {
- {Restriction::Type::No, {1 /* feature from */, 2 /* feature to */}},
- {Restriction::Type::Only, {3 /* feature from */, 5 /* feature to */}}};
+ RestrictionVec restrictionsNo = {
+ {Restriction::Type::No, {1 /* feature from */, 2 /* feature to */}}
+ };
+
+ RestrictionVec restrictionsOnly = {
+ {Restriction::Type::Only, {3 /* feature from */, 5 /* feature to */}}
+ };
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
+
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
- MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictionsNo), *this);
}
// Cumulative case. Trying to build route through XY graph with two restricitons applying
@@ -146,14 +164,19 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_PermutationsF3F5OnlyAndF0F2No)
UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5OnlyAndF1F3No)
{
Init(BuildXYGraph());
- RestrictionVec restrictions = {
- {Restriction::Type::No, {1 /* feature from */, 3 /* feature to */}},
- {Restriction::Type::Only, {3 /* feature from */, 5 /* feature to */}}};
+ RestrictionVec restrictionsNo = {
+ {Restriction::Type::No, {1 /* feature from */, 3 /* feature to */}}
+ };
+ RestrictionVec restrictionsOnly = {
+ {Restriction::Type::Only, {3 /* feature from */, 5 /* feature to */}}
+ };
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
TestRestrictions(
{} /* expectedGeom */, AStarAlgorithm<IndexGraphStarter>::Result::NoPath,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
- MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), move(restrictionsNo), *this);
}
// Finish
@@ -166,9 +189,9 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5OnlyAndF1F3No)
// F2 F3 F4
// ↖ ↗ ↖
// 1 * *
-// ↗ ↖ ^
+// ↗ ↖ ^
// F0 F1 F8
-// ↗ ↖ |
+// ↗ ↖ |
// 0 * *--F7--->*
// ^
// F9
@@ -219,6 +242,53 @@ unique_ptr<SingleVehicleWorldGraph> BuildXXGraph()
return BuildWorldGraph(move(loader), estimator, joints);
}
+
+// 2 * *
+// ↗ ↘
+// F4 F5
+// ↗ ↘
+// 1 * *
+// ↖ ↓
+// F2 F3
+// ↖ ↓ <-- Finish
+// 0 * *--F1--->*
+// ^
+// F0
+// |
+//-1 *
+// 0 1 2 3
+// Start
+// Note. This graph contains of 9 one segment directed features.
+unique_ptr<SingleVehicleWorldGraph> BuildCubeGraph()
+{
+ unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
+ loader->AddRoad(0 /* featureId */, true /* oneWay */, 1.0 /* speed */,
+ RoadGeometry::Points({{2.0, -1.0}, {2.0, 0.0}}));
+ loader->AddRoad(1 /* featureId */, true /* oneWay */, 1.0 /* speed */,
+ RoadGeometry::Points({{2.0, 0.0}, {3.0, 0.0}}));
+ loader->AddRoad(2 /* featureId */, true /* oneWay */, 1.0 /* speed */,
+ RoadGeometry::Points({{2.0, 0.0}, {1.0, 1.0}}));
+ loader->AddRoad(3 /* featureId */, false /* oneWay */, 1.0 /* speed */,
+ RoadGeometry::Points({{3.0, 1.0}, {3.0, 0.0}}));
+ loader->AddRoad(4 /* featureId */, true /* oneWay */, 1.0 /* speed */,
+ RoadGeometry::Points({{1.0, 1.0}, {2.0, 2.0}}));
+ loader->AddRoad(5 /* featureId */, true /* oneWay */, 1.0 /* speed */,
+ RoadGeometry::Points({{2.0, 2.0}, {3.0, 1.0}}));
+
+ vector<Joint> const joints = {
+ MakeJoint({{0 /* feature id */, 0 /* point id */}}), /* joint at point (2, -1) */
+ MakeJoint({{0, 1}, {1, 0}, {2, 0}}), /* joint at point (2, 0) */
+ MakeJoint({{2, 1}, {4, 0}}), /* joint at point (1, 1) */
+ MakeJoint({{4, 1}, {5, 0}}), /* joint at point (2, 2) */
+ MakeJoint({{5, 1}, {3, 0}}), /* joint at point (3, 1) */
+ MakeJoint({{1, 1}, {3, 1}}), /* joint at point (3, 0) */
+ };
+
+ traffic::TrafficCache const trafficCache;
+ shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
+ return BuildWorldGraph(move(loader), estimator, joints);
+}
+
// Route through XY graph without any restrictions.
UNIT_CLASS_TEST(RestrictionTest, XXGraph)
{
@@ -236,15 +306,19 @@ UNIT_CLASS_TEST(RestrictionTest, XXGraph)
UNIT_CLASS_TEST(RestrictionTest, XXGraph_PermutationsF1F3OnlyAndF3F6Only)
{
Init(BuildXXGraph());
- RestrictionVec restrictions = {
+ RestrictionVec restrictionsNo;
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {1 /* feature from */, 3 /* feature to */}},
- {Restriction::Type::Only, {3 /* feature from */, 6 /* feature to */}}};
+ {Restriction::Type::Only, {3 /* feature from */, 6 /* feature to */}}
+ };
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {1, 1}, {2, 2}, {3, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
- MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), move(restrictionsNo), *this);
}
// Route through XX graph with one restriciton (type no) from F1 to F3.
@@ -267,17 +341,49 @@ UNIT_CLASS_TEST(RestrictionTest, XXGraph_RestrictionF1F3No)
UNIT_CLASS_TEST(RestrictionTest, XXGraph_PermutationsF1F3NoF7F8OnlyF8F4OnlyF4F6Only)
{
Init(BuildXXGraph());
- RestrictionVec restrictions = {
- {Restriction::Type::No, {1 /* feature from */, 3 /* feature to */}},
+ RestrictionVec restrictionsNo = {
+ {Restriction::Type::No, {1 /* feature from */, 3 /* feature to */}}
+ };
+
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {4 /* feature from */, 6 /* feature to */}},
{Restriction::Type::Only, {7 /* feature from */, 8 /* feature to */}},
- {Restriction::Type::Only, {8 /* feature from */, 4 /* feature to */}}};
+ {Restriction::Type::Only, {8 /* feature from */, 4 /* feature to */}}
+ };
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
- MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), move(restrictionsNo), *this);
+}
+
+UNIT_CLASS_TEST(RestrictionTest, XXGraph_CheckOnlyRestriction)
+{
+ Init(BuildCubeGraph());
+
+ m2::PointD const start(2.0, -1.0);
+ m2::PointD const finish(3.0, 0.2);
+ auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo) {
+ TestRestrictions(
+ expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
+ MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
+ MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, finish, *m_graph),
+ move(restrictionsNo), *this);
+ };
+
+ RestrictionVec restrictionsOnly = {
+ {Restriction::Type::Only, {0 /* feature from */, 2 /* feature to */}},
+ };
+ RestrictionVec restrictionsNo;
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
+
+ // Check that without restrictions we can find path better.
+ test({start, {2, 0}, {1, 1}, {2, 2}, {3, 1}, finish, finish}, move(restrictionsNo));
+ test({start, {2, 0}, {3, 0}, finish, finish}, RestrictionVec());
}
} // namespace
diff --git a/routing/routing_tests/index_graph_tools.cpp b/routing/routing_tests/index_graph_tools.cpp
index 6fd0a69c52..b03abc5e37 100644
--- a/routing/routing_tests/index_graph_tools.cpp
+++ b/routing/routing_tests/index_graph_tools.cpp
@@ -9,6 +9,7 @@
#include "routing_common/car_model.hpp"
#include "base/assert.hpp"
+#include "base/math.hpp"
#include <unordered_map>
@@ -427,16 +428,22 @@ void TestRouteGeometry(IndexGraphStarter & starter,
geom.push_back(point);
};
- for (size_t i = 0; i < routeSegs.size(); ++i)
+ for (auto const & routeSeg : routeSegs)
{
- m2::PointD const & pnt = starter.GetPoint(routeSegs[i], false /* front */);
+ m2::PointD const & pnt = starter.GetPoint(routeSeg, false /* front */);
// Note. In case of A* router all internal points of route are duplicated.
// So it's necessary to exclude the duplicates.
pushPoint(pnt);
}
pushPoint(starter.GetPoint(routeSegs.back(), false /* front */));
- TEST_EQUAL(geom, expectedRouteGeom, ());
+ TEST_EQUAL(geom.size(), expectedRouteGeom.size(), ("geom:", geom, "expectedRouteGeom:", expectedRouteGeom));
+ for (size_t i = 0; i < geom.size(); ++i)
+ {
+ static double constexpr kEps = 1e-8;
+ TEST(base::AlmostEqualAbs(geom[i], expectedRouteGeom[i], kEps),
+ ("geom:", geom, "expectedRouteGeom:", expectedRouteGeom));
+ }
}
void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom,
diff --git a/routing/routing_tests/restriction_test.cpp b/routing/routing_tests/restriction_test.cpp
index ea48b74e7f..09c250270e 100644
--- a/routing/routing_tests/restriction_test.cpp
+++ b/routing/routing_tests/restriction_test.cpp
@@ -199,16 +199,23 @@ UNIT_CLASS_TEST(RestrictionTest, TriangularGraph_RestrictionOnlyF5F3)
UNIT_CLASS_TEST(RestrictionTest, TriangularGraph_RestrictionNoF5F2RestrictionOnlyF5F3)
{
Init(BuildTriangularGraph());
- RestrictionVec restrictions = {
- {Restriction::Type::No, {5 /* feature from */, 2 /* feature to */}},
- {Restriction::Type::Only, {5 /* feature from */, 3 /* feature to */}}};
+ RestrictionVec restrictionsNo = {
+ {Restriction::Type::No, {5 /* feature from */, 2 /* feature to */}},
+ };
+
+ RestrictionVec restrictionsOnly = {
+ {Restriction::Type::Only, {5 /* feature from */, 3 /* feature to */}},
+ };
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
+
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
- MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), move(restrictionsNo), *this);
}
// Finish
@@ -515,17 +522,24 @@ UNIT_CLASS_TEST(RestrictionTest, FlagGraph_RestrictionF0F1Only)
UNIT_CLASS_TEST(RestrictionTest, FlagGraph_PermutationsF1F3NoF7F8OnlyF8F4OnlyF4F6Only)
{
Init(BuildFlagGraph());
- RestrictionVec restrictions = {
- {Restriction::Type::No, {0 /* feature from */, 3 /* feature to */}},
- {Restriction::Type::Only, {0 /* feature from */, 1 /* feature to */}},
- {Restriction::Type::Only, {1 /* feature from */, 2 /* feature to */}}};
+ RestrictionVec restrictionsNo = {
+ {Restriction::Type::No, {0 /* feature from */, 3 /* feature to */}}
+ };
+
+ RestrictionVec restrictionsOnly = {
+ {Restriction::Type::Only, {0 /* feature from */, 1 /* feature to */}},
+ {Restriction::Type::Only, {1 /* feature from */, 2 /* feature to */}}
+ };
+
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
- MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), move(restrictionsNo), *this);
}
// 1 *-F4-*-F5-*---F6---* Finish
@@ -715,15 +729,20 @@ UNIT_TEST(SquaresGraph)
UNIT_CLASS_TEST(RestrictionTest, SquaresGraph_RestrictionF0F1OnlyF1F5Only)
{
Init(BuildSquaresGraph());
- RestrictionVec restrictions = {
+ RestrictionVec restrictionsNo;
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {0 /* feature from */, 1 /* feature to */}},
{Restriction::Type::Only, {1 /* feature from */, 5 /* feature to */}}};
+
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
+
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
- MakeFakeEnding(5, 0, m2::PointD(0, 0), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(5, 0, m2::PointD(0, 0), *m_graph), move(restrictionsNo), *this);
}
// 0 Start *--F0--->*---F1---*---F1---*---F1---*---F2-->* Finish
@@ -807,14 +826,18 @@ unique_ptr<SingleVehicleWorldGraph> BuildFGraph()
UNIT_CLASS_TEST(RestrictionTest, FGraph_RestrictionF0F2Only)
{
Init(BuildFGraph());
- RestrictionVec restrictions = {
+ RestrictionVec restrictionsNo;
+ RestrictionVec restrictionsOnly = {
{Restriction::Type::Only, {0 /* feature from */, 2 /* feature to */}}};
+ ConvertRestrictionsOnlyToNoAndSort(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
+ restrictionsNo);
+
vector<m2::PointD> const expectedGeom = {{0 /* x */, 0 /* y */}, {0, 1}, {1, 1}};
TestRestrictions(
expectedGeom, AStarAlgorithm<IndexGraphStarter>::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(0, 0), *m_graph),
- MakeFakeEnding(1, 0, m2::PointD(1, 1), *m_graph), move(restrictions), *this);
+ MakeFakeEnding(1, 0, m2::PointD(1, 1), *m_graph), move(restrictionsNo), *this);
}
// *---F4---*