reformatting code according to guidelines

This commit is contained in:
Dennis Luxen 2014-07-23 19:28:04 +02:00
parent a87cf60dfc
commit 85eb38e755
5 changed files with 170 additions and 218 deletions

View File

@ -21,16 +21,14 @@ typedef boost::mpl::list<ArrayStorage<TestNodeID, TestKey>,
MapStorage<TestNodeID, TestKey>, MapStorage<TestNodeID, TestKey>,
UnorderedMapStorage<TestNodeID, TestKey>> storage_types; UnorderedMapStorage<TestNodeID, TestKey>> storage_types;
template <unsigned NUM_ELEM> struct RandomDataFixture
template<unsigned NUM_ELEM>
struct RandomDataFixture
{ {
RandomDataFixture() RandomDataFixture()
{ {
for (unsigned i = 0; i < NUM_ELEM; i++) for (unsigned i = 0; i < NUM_ELEM; i++)
{ {
data.push_back(TestData {i*3}); data.push_back(TestData{i * 3});
weights.push_back((i+1)*100); weights.push_back((i + 1) * 100);
ids.push_back(i); ids.push_back(i);
order.push_back(i); order.push_back(i);
} }
@ -74,10 +72,10 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(insert_test, T, storage_types, RandomDataFixtur
for (auto id : ids) for (auto id : ids)
{ {
const auto& d = heap.GetData(id); const auto &d = heap.GetData(id);
BOOST_CHECK_EQUAL(d.value, data[id].value); BOOST_CHECK_EQUAL(d.value, data[id].value);
const auto& w = heap.GetKey(id); const auto &w = heap.GetKey(id);
BOOST_CHECK_EQUAL(w, weights[id]); BOOST_CHECK_EQUAL(w, weights[id]);
} }
} }
@ -97,8 +95,8 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(delete_min_test, T, storage_types, RandomDataFi
BOOST_CHECK_EQUAL(heap.Min(), id); BOOST_CHECK_EQUAL(heap.Min(), id);
BOOST_CHECK_EQUAL(id, heap.DeleteMin()); BOOST_CHECK_EQUAL(id, heap.DeleteMin());
if (id+1 < NUM_NODES) if (id + 1 < NUM_NODES)
BOOST_CHECK_EQUAL(heap.Min(), id+1); BOOST_CHECK_EQUAL(heap.Min(), id + 1);
BOOST_CHECK(heap.WasRemoved(id)); BOOST_CHECK(heap.WasRemoved(id));
} }
@ -151,4 +149,3 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(decrease_key_test, T, storage_types, RandomData
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -21,17 +21,18 @@ void ConstructionTest(std::vector<unsigned> lengths, std::vector<unsigned> offse
{ {
auto range = table.GetRange(i); auto range = table.GetRange(i);
BOOST_CHECK_EQUAL(range.front(), offsets[i]); BOOST_CHECK_EQUAL(range.front(), offsets[i]);
BOOST_CHECK_EQUAL(range.back()+1, offsets[i+1]); BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]);
} }
} }
void ComputeLengthsOffsets(std::vector<unsigned>& lengths, std::vector<unsigned>& offsets, unsigned num) void
ComputeLengthsOffsets(std::vector<unsigned> &lengths, std::vector<unsigned> &offsets, unsigned num)
{ {
lengths.resize(num); lengths.resize(num);
offsets.resize(num+1); offsets.resize(num + 1);
std::iota(lengths.begin(), lengths.end(), 1); std::iota(lengths.begin(), lengths.end(), 1);
offsets[0] = 0; offsets[0] = 0;
std::partial_sum(lengths.begin(), lengths.end(), offsets.begin()+1); std::partial_sum(lengths.begin(), lengths.end(), offsets.begin() + 1);
std::stringstream l_ss; std::stringstream l_ss;
l_ss << "Lengths: "; l_ss << "Lengths: ";
@ -49,7 +50,7 @@ BOOST_AUTO_TEST_CASE(serialization_test)
{ {
std::vector<unsigned> lengths; std::vector<unsigned> lengths;
std::vector<unsigned> offsets; std::vector<unsigned> offsets;
ComputeLengthsOffsets(lengths, offsets, (BLOCK_SIZE+1)*10); ComputeLengthsOffsets(lengths, offsets, (BLOCK_SIZE + 1) * 10);
TestRangeTable in_table(lengths); TestRangeTable in_table(lengths);
TestRangeTable out_table; TestRangeTable out_table;
@ -62,7 +63,7 @@ BOOST_AUTO_TEST_CASE(serialization_test)
{ {
auto range = out_table.GetRange(i); auto range = out_table.GetRange(i);
BOOST_CHECK_EQUAL(range.front(), offsets[i]); BOOST_CHECK_EQUAL(range.front(), offsets[i]);
BOOST_CHECK_EQUAL(range.back()+1, offsets[i+1]); BOOST_CHECK_EQUAL(range.back() + 1, offsets[i + 1]);
} }
} }
@ -82,7 +83,7 @@ BOOST_AUTO_TEST_CASE(construction_test)
// [(153)] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // [(153)] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
std::vector<unsigned> full_lengths; std::vector<unsigned> full_lengths;
std::vector<unsigned> full_offsets; std::vector<unsigned> full_offsets;
ComputeLengthsOffsets(full_lengths, full_offsets, BLOCK_SIZE+1); ComputeLengthsOffsets(full_lengths, full_offsets, BLOCK_SIZE + 1);
ConstructionTest(full_lengths, full_offsets); ConstructionTest(full_lengths, full_offsets);
// first block full and offset of next block not sentinel, but the first differential value // first block full and offset of next block not sentinel, but the first differential value
@ -90,13 +91,13 @@ BOOST_AUTO_TEST_CASE(construction_test)
// [153] {(17), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // [153] {(17), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
std::vector<unsigned> over_full_lengths; std::vector<unsigned> over_full_lengths;
std::vector<unsigned> over_full_offsets; std::vector<unsigned> over_full_offsets;
ComputeLengthsOffsets(over_full_lengths, over_full_offsets, BLOCK_SIZE+2); ComputeLengthsOffsets(over_full_lengths, over_full_offsets, BLOCK_SIZE + 2);
ConstructionTest(over_full_lengths, over_full_offsets); ConstructionTest(over_full_lengths, over_full_offsets);
// test multiple blocks // test multiple blocks
std::vector<unsigned> multiple_lengths; std::vector<unsigned> multiple_lengths;
std::vector<unsigned> multiple_offsets; std::vector<unsigned> multiple_offsets;
ComputeLengthsOffsets(multiple_lengths, multiple_offsets, (BLOCK_SIZE+1)*10); ComputeLengthsOffsets(multiple_lengths, multiple_offsets, (BLOCK_SIZE + 1) * 10);
ConstructionTest(multiple_lengths, multiple_offsets); ConstructionTest(multiple_lengths, multiple_offsets);
} }

View File

@ -34,14 +34,13 @@ constexpr unsigned TEST_NUM_EDGES = 500;
// Choosen by a fair W20 dice roll (this value is completely arbitrary) // Choosen by a fair W20 dice roll (this value is completely arbitrary)
constexpr unsigned RANDOM_SEED = 15; constexpr unsigned RANDOM_SEED = 15;
template<unsigned NUM_NODES, unsigned NUM_EDGES> template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomArrayEntryFixture
struct RandomArrayEntryFixture
{ {
RandomArrayEntryFixture() RandomArrayEntryFixture()
{ {
std::mt19937 g(RANDOM_SEED); std::mt19937 g(RANDOM_SEED);
std::uniform_int_distribution<> edge_udist(0, NUM_EDGES-1); std::uniform_int_distribution<> edge_udist(0, NUM_EDGES - 1);
std::vector<unsigned> offsets; std::vector<unsigned> offsets;
for (unsigned i = 0; i < NUM_NODES; i++) for (unsigned i = 0; i < NUM_NODES; i++)
{ {
@ -52,27 +51,24 @@ struct RandomArrayEntryFixture
offsets.push_back(offsets.back()); offsets.push_back(offsets.back());
// extract interval lengths // extract interval lengths
for(unsigned i = 0; i < offsets.size()-1; i++) for (unsigned i = 0; i < offsets.size() - 1; i++)
{ {
lengths.push_back(offsets[i+1] - offsets[i]); lengths.push_back(offsets[i + 1] - offsets[i]);
} }
lengths.push_back(NUM_EDGES - offsets[NUM_NODES-1]); lengths.push_back(NUM_EDGES - offsets[NUM_NODES - 1]);
for (auto offset : offsets) for (auto offset : offsets)
{ {
nodes.emplace_back(TestNodeArrayEntry {offset}); nodes.emplace_back(TestNodeArrayEntry{offset});
} }
std::uniform_int_distribution<> lengths_udist(0, 100000); std::uniform_int_distribution<> lengths_udist(0, 100000);
std::uniform_int_distribution<> node_udist(0, NUM_NODES-1); std::uniform_int_distribution<> node_udist(0, NUM_NODES - 1);
for (unsigned i = 0; i < NUM_EDGES; i++) for (unsigned i = 0; i < NUM_EDGES; i++)
{ {
edges.emplace_back( edges.emplace_back(
TestEdgeArrayEntry { TestEdgeArrayEntry{static_cast<unsigned>(node_udist(g)),
static_cast<unsigned>(node_udist(g)), TestData{i, false, static_cast<unsigned>(lengths_udist(g))}});
TestData {i, false, static_cast<unsigned>(lengths_udist(g))}
}
);
} }
for (unsigned i = 0; i < NUM_NODES; i++) for (unsigned i = 0; i < NUM_NODES; i++)
@ -99,24 +95,20 @@ BOOST_FIXTURE_TEST_CASE(array_test, TestRandomArrayEntryFixture)
for (auto idx : order) for (auto idx : order)
{ {
BOOST_CHECK_EQUAL(graph.BeginEdges((NodeID) idx), nodes_copy[idx].first_edge); BOOST_CHECK_EQUAL(graph.BeginEdges((NodeID)idx), nodes_copy[idx].first_edge);
BOOST_CHECK_EQUAL(graph.EndEdges((NodeID) idx), nodes_copy[idx+1].first_edge); BOOST_CHECK_EQUAL(graph.EndEdges((NodeID)idx), nodes_copy[idx + 1].first_edge);
BOOST_CHECK_EQUAL(graph.GetOutDegree((NodeID) idx), lengths[idx]); BOOST_CHECK_EQUAL(graph.GetOutDegree((NodeID)idx), lengths[idx]);
} }
} }
TestStaticGraph GraphFromEdgeList(const std::vector<TestEdge>& edges) TestStaticGraph GraphFromEdgeList(const std::vector<TestEdge> &edges)
{ {
std::vector<TestInputEdge> input_edges; std::vector<TestInputEdge> input_edges;
unsigned i = 0; unsigned i = 0;
unsigned num_nodes = 0; unsigned num_nodes = 0;
for (const auto& e : edges) for (const auto &e : edges)
{ {
input_edges.push_back(TestInputEdge { input_edges.push_back(TestInputEdge{e.source, e.target, TestData{i++, false, e.distance}});
e.source,
e.target,
TestData {i++, false, e.distance}
});
num_nodes = std::max(num_nodes, std::max(e.source, e.target)); num_nodes = std::max(num_nodes, std::max(e.source, e.target));
} }
@ -134,13 +126,11 @@ BOOST_AUTO_TEST_CASE(find_test)
* (3) -4-> (4) * (3) -4-> (4)
* <-3- * <-3-
*/ */
TestStaticGraph simple_graph = GraphFromEdgeList({ TestStaticGraph simple_graph = GraphFromEdgeList({TestEdge{0, 1, 1},
TestEdge {0, 1, 1}, TestEdge{3, 0, 2},
TestEdge {3, 0, 2}, TestEdge{3, 4, 4},
TestEdge {3, 4, 4}, TestEdge{4, 3, 3},
TestEdge {4, 3, 3}, TestEdge{3, 0, 1}});
TestEdge {3, 0, 1}
});
auto eit = simple_graph.FindEdge(0, 1); auto eit = simple_graph.FindEdge(0, 1);
BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0); BOOST_CHECK_EQUAL(simple_graph.GetEdgeData(eit).id, 0);
@ -172,4 +162,3 @@ BOOST_AUTO_TEST_CASE(find_test)
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -23,24 +23,23 @@ typedef StaticRTree<TestData,
std::vector<FixedPointCoordinate>, std::vector<FixedPointCoordinate>,
false, false,
TEST_BRANCHING_FACTOR, TEST_BRANCHING_FACTOR,
TEST_LEAF_NODE_SIZE> TEST_LEAF_NODE_SIZE> TestStaticRTree;
TestStaticRTree;
// Choosen by a fair W20 dice roll (this value is completely arbitrary) // Choosen by a fair W20 dice roll (this value is completely arbitrary)
constexpr unsigned RANDOM_SEED = 15; constexpr unsigned RANDOM_SEED = 15;
static const int32_t WORLD_MIN_LAT = -90*COORDINATE_PRECISION; static const int32_t WORLD_MIN_LAT = -90 * COORDINATE_PRECISION;
static const int32_t WORLD_MAX_LAT = 90*COORDINATE_PRECISION; static const int32_t WORLD_MAX_LAT = 90 * COORDINATE_PRECISION;
static const int32_t WORLD_MIN_LON = -180*COORDINATE_PRECISION; static const int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
static const int32_t WORLD_MAX_LON = 180*COORDINATE_PRECISION; static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
class LinearSearchNN class LinearSearchNN
{ {
public: public:
LinearSearchNN(const std::shared_ptr<std::vector<FixedPointCoordinate>>& coords, LinearSearchNN(const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
const std::vector<TestData>& edges) const std::vector<TestData> &edges)
: coords(coords) : coords(coords), edges(edges)
, edges(edges) {
{ } }
bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate, bool LocateClosestEndPointForCoordinate(const FixedPointCoordinate &input_coordinate,
FixedPointCoordinate &result_coordinate, FixedPointCoordinate &result_coordinate,
@ -50,18 +49,15 @@ public:
float min_dist = std::numeric_limits<float>::max(); float min_dist = std::numeric_limits<float>::max();
FixedPointCoordinate min_coord; FixedPointCoordinate min_coord;
for (const TestData& e : edges) for (const TestData &e : edges)
{ {
if (ignore_tiny_components && e.is_in_tiny_cc) if (ignore_tiny_components && e.is_in_tiny_cc)
continue; continue;
const FixedPointCoordinate& start = coords->at(e.u); const FixedPointCoordinate &start = coords->at(e.u);
const FixedPointCoordinate& end = coords->at(e.v); const FixedPointCoordinate &end = coords->at(e.v);
float distance = FixedPointCoordinate::ApproximateEuclideanDistance( float distance = FixedPointCoordinate::ApproximateEuclideanDistance(
input_coordinate.lat, input_coordinate.lat, input_coordinate.lon, start.lat, start.lon);
input_coordinate.lon,
start.lat,
start.lon);
if (distance < min_dist) if (distance < min_dist)
{ {
min_coord = start; min_coord = start;
@ -69,10 +65,7 @@ public:
} }
distance = FixedPointCoordinate::ApproximateEuclideanDistance( distance = FixedPointCoordinate::ApproximateEuclideanDistance(
input_coordinate.lat, input_coordinate.lat, input_coordinate.lon, end.lat, end.lon);
input_coordinate.lon,
end.lat,
end.lon);
if (distance < min_dist) if (distance < min_dist)
{ {
min_coord = end; min_coord = end;
@ -92,7 +85,7 @@ public:
float min_dist = std::numeric_limits<float>::max(); float min_dist = std::numeric_limits<float>::max();
TestData nearest_edge; TestData nearest_edge;
for (const TestData& e : edges) for (const TestData &e : edges)
{ {
if (ignore_tiny_components && e.is_in_tiny_cc) if (ignore_tiny_components && e.is_in_tiny_cc)
continue; continue;
@ -101,17 +94,13 @@ public:
FixedPointCoordinate nearest; FixedPointCoordinate nearest;
const float current_perpendicular_distance = const float current_perpendicular_distance =
FixedPointCoordinate::ComputePerpendicularDistance( FixedPointCoordinate::ComputePerpendicularDistance(
coords->at(e.u), coords->at(e.u), coords->at(e.v), input_coordinate, nearest, current_ratio);
coords->at(e.v),
input_coordinate,
nearest,
current_ratio);
if ((current_perpendicular_distance < min_dist) && if ((current_perpendicular_distance < min_dist) &&
!EpsilonCompare(current_perpendicular_distance, min_dist)) !EpsilonCompare(current_perpendicular_distance, min_dist))
{ // found a new minimum { // found a new minimum
min_dist = current_perpendicular_distance; min_dist = current_perpendicular_distance;
result_phantom_node = { e.forward_edge_based_node_id, result_phantom_node = {e.forward_edge_based_node_id,
e.reverse_edge_based_node_id, e.reverse_edge_based_node_id,
e.name_id, e.name_id,
e.forward_weight, e.forward_weight,
@ -138,11 +127,9 @@ public:
} }
const float distance_1 = FixedPointCoordinate::ApproximateEuclideanDistance( const float distance_1 = FixedPointCoordinate::ApproximateEuclideanDistance(
coords->at(nearest_edge.u), coords->at(nearest_edge.u), result_phantom_node.location);
result_phantom_node.location);
const float distance_2 = FixedPointCoordinate::ApproximateEuclideanDistance( const float distance_2 = FixedPointCoordinate::ApproximateEuclideanDistance(
coords->at(nearest_edge.u), coords->at(nearest_edge.u), coords->at(nearest_edge.v));
coords->at(nearest_edge.v));
const float ratio = std::min(1.f, distance_1 / distance_2); const float ratio = std::min(1.f, distance_1 / distance_2);
if (SPECIAL_NODEID != result_phantom_node.forward_node_id) if (SPECIAL_NODEID != result_phantom_node.forward_node_id)
@ -158,31 +145,28 @@ public:
return result_phantom_node.location.isValid(); return result_phantom_node.location.isValid();
} }
private: private:
const std::shared_ptr<std::vector<FixedPointCoordinate>>& coords; const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords;
const std::vector<TestData>& edges; const std::vector<TestData> &edges;
}; };
template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
template<unsigned NUM_NODES, unsigned NUM_EDGES>
struct RandomGraphFixture
{ {
struct TupleHash struct TupleHash
{ {
typedef std::pair<unsigned, unsigned> argument_type; typedef std::pair<unsigned, unsigned> argument_type;
typedef std::size_t result_type; typedef std::size_t result_type;
result_type operator()(const argument_type & t) const result_type operator()(const argument_type &t) const
{ {
std::size_t val { 0 }; std::size_t val{0};
boost::hash_combine(val, t.first); boost::hash_combine(val, t.first);
boost::hash_combine(val, t.second); boost::hash_combine(val, t.second);
return val; return val;
} }
}; };
RandomGraphFixture() RandomGraphFixture() : coords(std::make_shared<std::vector<FixedPointCoordinate>>())
: coords(std::make_shared<std::vector<FixedPointCoordinate>>())
{ {
BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges."); BOOST_TEST_MESSAGE("Constructing " << NUM_NODES << " nodes and " << NUM_EDGES << " edges.");
@ -203,19 +187,19 @@ struct RandomGraphFixture
std::unordered_set<std::pair<unsigned, unsigned>, TupleHash> used_edges; std::unordered_set<std::pair<unsigned, unsigned>, TupleHash> used_edges;
while(edges.size() < NUM_EDGES) while (edges.size() < NUM_EDGES)
{ {
TestData data; TestData data;
data.u = edge_udist(g); data.u = edge_udist(g);
data.v = edge_udist(g); data.v = edge_udist(g);
if (used_edges.find(std::pair<unsigned, unsigned>(std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end()) if (used_edges.find(std::pair<unsigned, unsigned>(
std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end())
{ {
data.is_in_tiny_cc = false; data.is_in_tiny_cc = false;
edges.emplace_back(data); edges.emplace_back(data);
used_edges.emplace(std::min(data.u, data.v), std::max(data.u, data.v)); used_edges.emplace(std::min(data.u, data.v), std::max(data.u, data.v));
} }
} }
} }
std::vector<NodeInfo> nodes; std::vector<NodeInfo> nodes;
@ -225,26 +209,26 @@ struct RandomGraphFixture
struct GraphFixture struct GraphFixture
{ {
GraphFixture(const std::vector<std::pair<float, float>>& input_coords, GraphFixture(const std::vector<std::pair<float, float>> &input_coords,
const std::vector<std::pair<unsigned, unsigned>>& input_edges) const std::vector<std::pair<unsigned, unsigned>> &input_edges)
: coords(std::make_shared<std::vector<FixedPointCoordinate>>()) : coords(std::make_shared<std::vector<FixedPointCoordinate>>())
{ {
for (unsigned i = 0; i < input_coords.size(); i++) for (unsigned i = 0; i < input_coords.size(); i++)
{ {
FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION, input_coords[i].second * COORDINATE_PRECISION); FixedPointCoordinate c(input_coords[i].first * COORDINATE_PRECISION,
input_coords[i].second * COORDINATE_PRECISION);
coords->emplace_back(c); coords->emplace_back(c);
nodes.emplace_back(NodeInfo(c.lat, c.lon, i)); nodes.emplace_back(NodeInfo(c.lat, c.lon, i));
} }
for (const auto& pair : input_edges) for (const auto &pair : input_edges)
{ {
TestData d; TestData d;
d.u = pair.first; d.u = pair.first;
d.v = pair.second; d.v = pair.second;
edges.emplace_back(d); edges.emplace_back(d);
} }
} }
std::vector<NodeInfo> nodes; std::vector<NodeInfo> nodes;
@ -252,44 +236,44 @@ struct GraphFixture
std::vector<TestData> edges; std::vector<TestData> edges;
}; };
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 3, TEST_LEAF_NODE_SIZE / 2>
TestRandomGraphFixture_LeafHalfFull;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 5, TEST_LEAF_NODE_SIZE>
TestRandomGraphFixture_LeafFull;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * 10, TEST_LEAF_NODE_SIZE * 2>
TestRandomGraphFixture_TwoLeaves;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR>
TestRandomGraphFixture_Branch;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 3,
TEST_LEAF_NODE_SIZE * TEST_BRANCHING_FACTOR * 2>
TestRandomGraphFixture_MultipleLevels;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*3, TEST_LEAF_NODE_SIZE/2> TestRandomGraphFixture_LeafHalfFull; template <typename RTreeT>
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*5, TEST_LEAF_NODE_SIZE> TestRandomGraphFixture_LeafFull; void simple_verify_rtree(RTreeT &rtree,
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*10, TEST_LEAF_NODE_SIZE*2> TestRandomGraphFixture_TwoLeaves; const std::shared_ptr<std::vector<FixedPointCoordinate>> &coords,
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*TEST_BRANCHING_FACTOR*3, const std::vector<TestData> &edges)
TEST_LEAF_NODE_SIZE*TEST_BRANCHING_FACTOR> TestRandomGraphFixture_Branch;
typedef RandomGraphFixture<TEST_LEAF_NODE_SIZE*TEST_BRANCHING_FACTOR*3,
TEST_LEAF_NODE_SIZE*TEST_BRANCHING_FACTOR*2> TestRandomGraphFixture_MultipleLevels;
template<typename RTreeT>
void simple_verify_rtree(RTreeT& rtree, const std::shared_ptr<std::vector<FixedPointCoordinate>>& coords, const std::vector<TestData>& edges)
{ {
BOOST_TEST_MESSAGE("Verify end points"); BOOST_TEST_MESSAGE("Verify end points");
for (const auto& e : edges) for (const auto &e : edges)
{ {
FixedPointCoordinate result_u, result_v; FixedPointCoordinate result_u, result_v;
const FixedPointCoordinate& pu = coords->at(e.u); const FixedPointCoordinate &pu = coords->at(e.u);
const FixedPointCoordinate& pv = coords->at(e.v); const FixedPointCoordinate &pv = coords->at(e.v);
bool found_u = rtree.LocateClosestEndPointForCoordinate(pu, result_u, 1); bool found_u = rtree.LocateClosestEndPointForCoordinate(pu, result_u, 1);
bool found_v = rtree.LocateClosestEndPointForCoordinate(pv, result_v, 1); bool found_v = rtree.LocateClosestEndPointForCoordinate(pv, result_v, 1);
BOOST_CHECK(found_u && found_v); BOOST_CHECK(found_u && found_v);
float dist_u = FixedPointCoordinate::ApproximateEuclideanDistance( float dist_u = FixedPointCoordinate::ApproximateEuclideanDistance(
result_u.lat, result_u.lat, result_u.lon, pu.lat, pu.lon);
result_u.lon,
pu.lat,
pu.lon);
BOOST_CHECK_LE(dist_u, std::numeric_limits<float>::epsilon()); BOOST_CHECK_LE(dist_u, std::numeric_limits<float>::epsilon());
float dist_v = FixedPointCoordinate::ApproximateEuclideanDistance( float dist_v = FixedPointCoordinate::ApproximateEuclideanDistance(
result_v.lat, result_v.lat, result_v.lon, pv.lat, pv.lon);
result_v.lon,
pv.lat,
pv.lon);
BOOST_CHECK_LE(dist_v, std::numeric_limits<float>::epsilon()); BOOST_CHECK_LE(dist_v, std::numeric_limits<float>::epsilon());
} }
} }
template<typename RTreeT> template <typename RTreeT>
void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_samples) void sampling_verify_rtree(RTreeT &rtree, LinearSearchNN &lsnn, unsigned num_samples)
{ {
std::mt19937 g(RANDOM_SEED); std::mt19937 g(RANDOM_SEED);
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT); std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
@ -297,13 +281,11 @@ void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_sam
std::vector<FixedPointCoordinate> queries; std::vector<FixedPointCoordinate> queries;
for (unsigned i = 0; i < num_samples; i++) for (unsigned i = 0; i < num_samples; i++)
{ {
queries.emplace_back( queries.emplace_back(FixedPointCoordinate(lat_udist(g), lon_udist(g)));
FixedPointCoordinate(lat_udist(g), lon_udist(g))
);
} }
BOOST_TEST_MESSAGE("Sampling queries"); BOOST_TEST_MESSAGE("Sampling queries");
for (const auto& q : queries) for (const auto &q : queries)
{ {
FixedPointCoordinate result_rtree; FixedPointCoordinate result_rtree;
rtree.LocateClosestEndPointForCoordinate(q, result_rtree, 1); rtree.LocateClosestEndPointForCoordinate(q, result_rtree, 1);
@ -319,8 +301,11 @@ void sampling_verify_rtree(RTreeT& rtree, LinearSearchNN& lsnn, unsigned num_sam
} }
} }
template<typename FixtureT, typename RTreeT=TestStaticRTree> template <typename FixtureT, typename RTreeT = TestStaticRTree>
void build_rtree(const std::string& prefix, FixtureT* fixture, std::string& leaves_path, std::string& nodes_path) void build_rtree(const std::string &prefix,
FixtureT *fixture,
std::string &leaves_path,
std::string &nodes_path)
{ {
nodes_path = prefix + ".ramIndex"; nodes_path = prefix + ".ramIndex";
leaves_path = prefix + ".fileIndex"; leaves_path = prefix + ".fileIndex";
@ -335,8 +320,8 @@ void build_rtree(const std::string& prefix, FixtureT* fixture, std::string& leav
RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->nodes); RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->nodes);
} }
template<typename FixtureT, typename RTreeT=TestStaticRTree> template <typename FixtureT, typename RTreeT = TestStaticRTree>
void construction_test(const std::string& prefix, FixtureT* fixture) void construction_test(const std::string &prefix, FixtureT *fixture)
{ {
std::string leaves_path; std::string leaves_path;
std::string nodes_path; std::string nodes_path;
@ -397,24 +382,14 @@ BOOST_AUTO_TEST_CASE(regression_test)
Coord(5.0, 105.0), Coord(5.0, 105.0),
Coord(0.0, 110.0), Coord(0.0, 110.0),
}, },
{ {Edge(0, 1), Edge(2, 3), Edge(4, 5), Edge(6, 7), Edge(8, 9)});
Edge(0, 1),
Edge(2, 3),
Edge(4, 5),
Edge(6, 7),
Edge(8, 9)
}
);
typedef StaticRTree<TestData, typedef StaticRTree<TestData, std::vector<FixedPointCoordinate>, false, 2, 3> MiniStaticRTree;
std::vector<FixedPointCoordinate>,
false,
2,
3> MiniStaticRTree;
std::string leaves_path; std::string leaves_path;
std::string nodes_path; std::string nodes_path;
build_rtree<GraphFixture, MiniStaticRTree>("test_regression", &fixture, leaves_path, nodes_path); build_rtree<GraphFixture, MiniStaticRTree>(
"test_regression", &fixture, leaves_path, nodes_path);
MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords); MiniStaticRTree rtree(nodes_path, leaves_path, fixture.coords);
// query a node just right of the center of the gap // query a node just right of the center of the gap
@ -430,15 +405,16 @@ BOOST_AUTO_TEST_CASE(regression_test)
void TestRectangle(double width, double height, double center_lat, double center_lon) void TestRectangle(double width, double height, double center_lat, double center_lon)
{ {
FixedPointCoordinate center(center_lat*COORDINATE_PRECISION, center_lon*COORDINATE_PRECISION); FixedPointCoordinate center(center_lat * COORDINATE_PRECISION,
center_lon * COORDINATE_PRECISION);
TestStaticRTree::RectangleT rect; TestStaticRTree::RectangleT rect;
rect.min_lat = center.lat - height/2.0 * COORDINATE_PRECISION; rect.min_lat = center.lat - height / 2.0 * COORDINATE_PRECISION;
rect.max_lat = center.lat + height/2.0 * COORDINATE_PRECISION; rect.max_lat = center.lat + height / 2.0 * COORDINATE_PRECISION;
rect.min_lon = center.lon - width/2.0 * COORDINATE_PRECISION; rect.min_lon = center.lon - width / 2.0 * COORDINATE_PRECISION;
rect.max_lon = center.lon + width/2.0 * COORDINATE_PRECISION; rect.max_lon = center.lon + width / 2.0 * COORDINATE_PRECISION;
unsigned offset = 5*COORDINATE_PRECISION; unsigned offset = 5 * COORDINATE_PRECISION;
FixedPointCoordinate north(rect.max_lat + offset, center.lon); FixedPointCoordinate north(rect.max_lat + offset, center.lon);
FixedPointCoordinate south(rect.min_lat - offset, center.lon); FixedPointCoordinate south(rect.min_lat - offset, center.lon);
FixedPointCoordinate west(center.lat, rect.min_lon - offset); FixedPointCoordinate west(center.lat, rect.min_lon - offset);
@ -448,42 +424,33 @@ void TestRectangle(double width, double height, double center_lat, double center
FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset); FixedPointCoordinate south_east(rect.min_lat - offset, rect.max_lon + offset);
FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - offset); FixedPointCoordinate south_west(rect.min_lat - offset, rect.min_lon - offset);
/* Distance to line segments of rectangle */ /* Distance to line segments of rectangle */
BOOST_CHECK_EQUAL( BOOST_CHECK_EQUAL(rect.GetMinDist(north),
rect.GetMinDist(north), FixedPointCoordinate::ApproximateEuclideanDistance(
FixedPointCoordinate::ApproximateEuclideanDistance(north, FixedPointCoordinate(rect.max_lat, north.lon)) north, FixedPointCoordinate(rect.max_lat, north.lon)));
); BOOST_CHECK_EQUAL(rect.GetMinDist(south),
BOOST_CHECK_EQUAL( FixedPointCoordinate::ApproximateEuclideanDistance(
rect.GetMinDist(south), south, FixedPointCoordinate(rect.min_lat, south.lon)));
FixedPointCoordinate::ApproximateEuclideanDistance(south, FixedPointCoordinate(rect.min_lat, south.lon)) BOOST_CHECK_EQUAL(rect.GetMinDist(west),
); FixedPointCoordinate::ApproximateEuclideanDistance(
BOOST_CHECK_EQUAL( west, FixedPointCoordinate(west.lat, rect.min_lon)));
rect.GetMinDist(west), BOOST_CHECK_EQUAL(rect.GetMinDist(east),
FixedPointCoordinate::ApproximateEuclideanDistance(west, FixedPointCoordinate(west.lat, rect.min_lon)) FixedPointCoordinate::ApproximateEuclideanDistance(
); east, FixedPointCoordinate(east.lat, rect.max_lon)));
BOOST_CHECK_EQUAL(
rect.GetMinDist(east),
FixedPointCoordinate::ApproximateEuclideanDistance(east, FixedPointCoordinate(east.lat, rect.max_lon))
);
/* Distance to corner points */ /* Distance to corner points */
BOOST_CHECK_EQUAL( BOOST_CHECK_EQUAL(rect.GetMinDist(north_east),
rect.GetMinDist(north_east), FixedPointCoordinate::ApproximateEuclideanDistance(
FixedPointCoordinate::ApproximateEuclideanDistance(north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon)) north_east, FixedPointCoordinate(rect.max_lat, rect.max_lon)));
); BOOST_CHECK_EQUAL(rect.GetMinDist(north_west),
BOOST_CHECK_EQUAL( FixedPointCoordinate::ApproximateEuclideanDistance(
rect.GetMinDist(north_west), north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon)));
FixedPointCoordinate::ApproximateEuclideanDistance(north_west, FixedPointCoordinate(rect.max_lat, rect.min_lon)) BOOST_CHECK_EQUAL(rect.GetMinDist(south_east),
); FixedPointCoordinate::ApproximateEuclideanDistance(
BOOST_CHECK_EQUAL( south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon)));
rect.GetMinDist(south_east), BOOST_CHECK_EQUAL(rect.GetMinDist(south_west),
FixedPointCoordinate::ApproximateEuclideanDistance(south_east, FixedPointCoordinate(rect.min_lat, rect.max_lon)) FixedPointCoordinate::ApproximateEuclideanDistance(
); south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon)));
BOOST_CHECK_EQUAL(
rect.GetMinDist(south_west),
FixedPointCoordinate::ApproximateEuclideanDistance(south_west, FixedPointCoordinate(rect.min_lat, rect.min_lon))
);
} }
BOOST_AUTO_TEST_CASE(rectangle_test) BOOST_AUTO_TEST_CASE(rectangle_test)
@ -496,4 +463,3 @@ BOOST_AUTO_TEST_CASE(rectangle_test)
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View File

@ -5,4 +5,3 @@
/* /*
* This file will contain an automatically generated main function. * This file will contain an automatically generated main function.
*/ */