Make edge metrics strongly typed (#6421)

This change takes the existing typedefs for weight, duration and
distance, and makes them proper types, using the existing Alias
functionality.

Primarily this is to prevent bugs where the metrics are switched,
but it also adds additional documentation. For example, it now
makes it clear (despite the naming of variables) that most of the
trip algorithm is running on the duration metric.

I've not made any changes to the casts performed between metrics
and numeric types, they now just more explicit.
This commit is contained in:
Michael Bell
2022-10-28 15:16:12 +01:00
committed by GitHub
parent 16685d0de9
commit 5d468f2897
69 changed files with 922 additions and 686 deletions
@@ -15,7 +15,7 @@ BOOST_AUTO_TEST_CASE(long_road_test)
CompressedEdgeContainer container;
// compress 0---1---2 to 0---2
container.CompressEdge(0, 1, 1, 2, 1, 1, 11, 11);
container.CompressEdge(0, 1, 1, 2, {1}, {1}, {11}, {11});
BOOST_CHECK(container.HasEntryForID(0));
BOOST_CHECK(!container.HasEntryForID(1));
BOOST_CHECK(!container.HasEntryForID(2));
@@ -24,7 +24,7 @@ BOOST_AUTO_TEST_CASE(long_road_test)
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(0), 1);
// compress 2---3---4 to 2---4
container.CompressEdge(2, 3, 3, 4, 1, 1, 11, 11);
container.CompressEdge(2, 3, 3, 4, {1}, {1}, {11}, {11});
BOOST_CHECK(container.HasEntryForID(0));
BOOST_CHECK(!container.HasEntryForID(1));
BOOST_CHECK(container.HasEntryForID(2));
@@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(long_road_test)
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(2), 3);
// compress 0---2---4 to 0---4
container.CompressEdge(0, 2, 2, 4, 2, 2, 22, 22);
container.CompressEdge(0, 2, 2, 4, {2}, {2}, {22}, {22});
BOOST_CHECK(container.HasEntryForID(0));
BOOST_CHECK(!container.HasEntryForID(1));
BOOST_CHECK(!container.HasEntryForID(2));
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(t_crossing)
CompressedEdgeContainer container;
// compress 0---1---2 to 0---2
container.CompressEdge(0, 1, 1, 2, 1, 1, 11, 11);
container.CompressEdge(0, 1, 1, 2, {1}, {1}, {11}, {11});
BOOST_CHECK(container.HasEntryForID(0));
BOOST_CHECK(!container.HasEntryForID(1));
BOOST_CHECK(!container.HasEntryForID(2));
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(t_crossing)
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(0), 1);
// compress 2---5---6 to 2---6
container.CompressEdge(4, 5, 5, 6, 1, 1, 11, 11);
container.CompressEdge(4, 5, 5, 6, {1}, {1}, {11}, {11});
BOOST_CHECK(container.HasEntryForID(0));
BOOST_CHECK(!container.HasEntryForID(1));
BOOST_CHECK(!container.HasEntryForID(2));
@@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(t_crossing)
BOOST_CHECK_EQUAL(container.GetLastEdgeSourceID(4), 5);
// compress 2---3---4 to 2---4
container.CompressEdge(2, 3, 3, 4, 1, 1, 11, 11);
container.CompressEdge(2, 3, 3, 4, {1}, {1}, {11}, {11});
BOOST_CHECK(container.HasEntryForID(0));
BOOST_CHECK(!container.HasEntryForID(1));
BOOST_CHECK(container.HasEntryForID(2));
+3 -3
View File
@@ -27,9 +27,9 @@ inline InputEdge MakeUnitEdge(const NodeID from, const NodeID to)
{
return {from, // source
to, // target
1, // weight
1, // duration
1, // distance
EdgeWeight{1}, // weight
EdgeDuration{1}, // duration
EdgeDistance{1}, // distance
GeometryID{0, false}, // geometry_id
false, // reversed
NodeBasedEdgeClassification(), // default flags
@@ -43,9 +43,9 @@ BOOST_AUTO_TEST_CASE(simple_intersection_connectivity)
[](const NodeID from, const NodeID to, bool allowed, AnnotationID annotation) {
return InputEdge{from,
to,
1,
1,
1,
EdgeWeight{1},
EdgeDuration{1},
EdgeDistance{1},
GeometryID{0, false},
!allowed,
NodeBasedEdgeClassification(),
@@ -170,9 +170,9 @@ BOOST_AUTO_TEST_CASE(roundabout_intersection_connectivity)
const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed, bool roundabout) {
return InputEdge{from,
to,
1,
1,
1,
EdgeWeight{1},
EdgeDuration{1},
EdgeDistance{1},
GeometryID{0, false},
!allowed,
NodeBasedEdgeClassification{
@@ -275,8 +275,15 @@ BOOST_AUTO_TEST_CASE(skip_degree_two_nodes)
// 6 8 ↔ 9
//
const auto unit_edge = [](const NodeID from, const NodeID to, bool allowed) {
return InputEdge{
from, to, 1, 1, 1, GeometryID{0, false}, !allowed, NodeBasedEdgeClassification{}, 0};
return InputEdge{from,
to,
EdgeWeight{1},
EdgeDuration{1},
EdgeDistance{1},
GeometryID{0, false},
!allowed,
NodeBasedEdgeClassification{},
0};
};
std::vector<InputEdge> edges = {unit_edge(0, 1, true), // 0
unit_edge(1, 0, true),