Only use const-ref for coordinate vector
This commit is contained in:
parent
f5aa5c0769
commit
ddd128ce0e
@ -69,7 +69,7 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
std::unique_ptr<QueryGraph> m_query_graph;
|
||||
std::string m_timestamp;
|
||||
|
||||
std::shared_ptr<util::ShM<util::Coordinate, false>::vector> m_coordinate_list;
|
||||
util::ShM<util::Coordinate, false>::vector m_coordinate_list;
|
||||
util::ShM<NodeID, false>::vector m_via_node_list;
|
||||
util::ShM<unsigned, false>::vector m_name_ID_list;
|
||||
util::ShM<extractor::guidance::TurnInstruction, false>::vector m_turn_instruction_list;
|
||||
@ -139,12 +139,12 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
extractor::QueryNode current_node;
|
||||
unsigned number_of_coordinates = 0;
|
||||
nodes_input_stream.read((char *)&number_of_coordinates, sizeof(unsigned));
|
||||
m_coordinate_list = std::make_shared<std::vector<util::Coordinate>>(number_of_coordinates);
|
||||
m_coordinate_list.resize(number_of_coordinates);
|
||||
for (unsigned i = 0; i < number_of_coordinates; ++i)
|
||||
{
|
||||
nodes_input_stream.read((char *)¤t_node, sizeof(extractor::QueryNode));
|
||||
m_coordinate_list->at(i) = util::Coordinate(current_node.lon, current_node.lat);
|
||||
BOOST_ASSERT(m_coordinate_list->at(i).IsValid());
|
||||
m_coordinate_list[i] = util::Coordinate(current_node.lon, current_node.lat);
|
||||
BOOST_ASSERT(m_coordinate_list[i].IsValid());
|
||||
}
|
||||
|
||||
boost::filesystem::ifstream edges_input_stream(edges_file, std::ios::binary);
|
||||
@ -253,7 +253,7 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
|
||||
void LoadRTree()
|
||||
{
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list.empty(), "coordinates must be loaded before r-tree");
|
||||
|
||||
m_static_rtree.reset(new InternalRTree(ram_index_path, file_index_path, m_coordinate_list));
|
||||
m_geospatial_query.reset(
|
||||
@ -364,7 +364,7 @@ class InternalDataFacade final : public BaseDataFacade
|
||||
// node and edge information access
|
||||
util::Coordinate GetCoordinateOfNode(const unsigned id) const override final
|
||||
{
|
||||
return m_coordinate_list->at(id);
|
||||
return m_coordinate_list[id];
|
||||
}
|
||||
|
||||
extractor::guidance::TurnInstruction
|
||||
|
@ -72,7 +72,7 @@ class SharedDataFacade final : public BaseDataFacade
|
||||
std::string m_timestamp;
|
||||
extractor::ProfileProperties *m_profile_properties;
|
||||
|
||||
std::shared_ptr<util::ShM<util::Coordinate, true>::vector> m_coordinate_list;
|
||||
util::ShM<util::Coordinate, true>::vector m_coordinate_list;
|
||||
util::ShM<NodeID, true>::vector m_via_node_list;
|
||||
util::ShM<unsigned, true>::vector m_name_ID_list;
|
||||
util::ShM<extractor::guidance::TurnInstruction, true>::vector m_turn_instruction_list;
|
||||
@ -119,7 +119,7 @@ class SharedDataFacade final : public BaseDataFacade
|
||||
|
||||
void LoadRTree()
|
||||
{
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list->empty(), "coordinates must be loaded before r-tree");
|
||||
BOOST_ASSERT_MSG(!m_coordinate_list.empty(), "coordinates must be loaded before r-tree");
|
||||
|
||||
auto tree_ptr = data_layout->GetBlockPtr<RTreeNode>(
|
||||
shared_memory, storage::SharedDataLayout::R_SEARCH_TREE);
|
||||
@ -149,8 +149,7 @@ class SharedDataFacade final : public BaseDataFacade
|
||||
{
|
||||
auto coordinate_list_ptr = data_layout->GetBlockPtr<util::Coordinate>(
|
||||
shared_memory, storage::SharedDataLayout::COORDINATE_LIST);
|
||||
m_coordinate_list = util::make_unique<util::ShM<util::Coordinate, true>::vector>(
|
||||
coordinate_list_ptr,
|
||||
m_coordinate_list.reset(coordinate_list_ptr,
|
||||
data_layout->num_entries[storage::SharedDataLayout::COORDINATE_LIST]);
|
||||
|
||||
auto travel_mode_list_ptr = data_layout->GetBlockPtr<extractor::TravelMode>(
|
||||
@ -353,13 +352,10 @@ class SharedDataFacade final : public BaseDataFacade
|
||||
LoadRTree();
|
||||
|
||||
util::SimpleLogger().Write() << "number of geometries: "
|
||||
<< m_coordinate_list->size();
|
||||
for (unsigned i = 0; i < m_coordinate_list->size(); ++i)
|
||||
<< m_coordinate_list.size();
|
||||
for (unsigned i = 0; i < m_coordinate_list.size(); ++i)
|
||||
{
|
||||
if (!GetCoordinateOfNode(i).IsValid())
|
||||
{
|
||||
util::SimpleLogger().Write() << "coordinate " << i << " not valid";
|
||||
}
|
||||
BOOST_ASSERT(GetCoordinateOfNode(i).IsValid());
|
||||
}
|
||||
}
|
||||
util::SimpleLogger().Write(logDEBUG) << "Releasing exclusive lock";
|
||||
@ -412,7 +408,7 @@ class SharedDataFacade final : public BaseDataFacade
|
||||
// node and edge information access
|
||||
util::Coordinate GetCoordinateOfNode(const NodeID id) const override final
|
||||
{
|
||||
return m_coordinate_list->at(id);
|
||||
return m_coordinate_list[id];
|
||||
}
|
||||
|
||||
virtual void GetUncompressedGeometry(const EdgeID id,
|
||||
|
@ -22,7 +22,7 @@ namespace engine
|
||||
|
||||
// Implements complex queries on top of an RTree and builds PhantomNodes from it.
|
||||
//
|
||||
// Only holds a weak reference on the RTree!
|
||||
// Only holds a weak reference on the RTree and coordinates!
|
||||
template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
{
|
||||
using EdgeData = typename RTreeT::EdgeData;
|
||||
@ -31,9 +31,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
|
||||
public:
|
||||
GeospatialQuery(RTreeT &rtree_,
|
||||
std::shared_ptr<CoordinateList> coordinates_,
|
||||
const CoordinateList &coordinates_,
|
||||
DataFacadeT &datafacade_)
|
||||
: rtree(rtree_), coordinates(std::move(coordinates_)), datafacade(datafacade_)
|
||||
: rtree(rtree_), coordinates(coordinates_), datafacade(datafacade_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
double ratio;
|
||||
const auto current_perpendicular_distance =
|
||||
util::coordinate_calculation::perpendicularDistance(
|
||||
coordinates->at(data.u), coordinates->at(data.v), input_coordinate,
|
||||
coordinates[data.u], coordinates[data.v], input_coordinate,
|
||||
point_on_segment, ratio);
|
||||
|
||||
// Find the node-based-edge that this belongs to, and directly
|
||||
@ -442,7 +442,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
!segment.data.reverse_segment_id.enabled);
|
||||
|
||||
const double forward_edge_bearing = util::coordinate_calculation::bearing(
|
||||
coordinates->at(segment.data.u), coordinates->at(segment.data.v));
|
||||
coordinates[segment.data.u], coordinates[segment.data.v]);
|
||||
|
||||
const double backward_edge_bearing = (forward_edge_bearing + 180) > 360
|
||||
? (forward_edge_bearing - 180)
|
||||
@ -460,7 +460,7 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
|
||||
}
|
||||
|
||||
RTreeT &rtree;
|
||||
const std::shared_ptr<CoordinateList> coordinates;
|
||||
const CoordinateList &coordinates;
|
||||
DataFacadeT &datafacade;
|
||||
};
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ class StaticRTree
|
||||
};
|
||||
|
||||
typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
|
||||
std::shared_ptr<CoordinateListT> m_coordinate_list;
|
||||
const CoordinateListT& m_coordinate_list;
|
||||
|
||||
boost::iostreams::mapped_file_source m_leaves_region;
|
||||
// read-only view of leaves
|
||||
@ -132,6 +132,7 @@ class StaticRTree
|
||||
const std::string &tree_node_filename,
|
||||
const std::string &leaf_node_filename,
|
||||
const std::vector<CoordinateT> &coordinate_list)
|
||||
: m_coordinate_list(coordinate_list)
|
||||
{
|
||||
const uint64_t element_count = input_data_vector.size();
|
||||
std::vector<WrappedInputElement> input_wrapper_vector(element_count);
|
||||
@ -140,7 +141,7 @@ class StaticRTree
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<uint64_t>(0, element_count),
|
||||
[&input_data_vector, &input_wrapper_vector,
|
||||
&coordinate_list](const tbb::blocked_range<uint64_t> &range)
|
||||
this](const tbb::blocked_range<uint64_t> &range)
|
||||
{
|
||||
for (uint64_t element_counter = range.begin(), end = range.end();
|
||||
element_counter != end; ++element_counter)
|
||||
@ -151,11 +152,11 @@ class StaticRTree
|
||||
EdgeDataT const ¤t_element = input_data_vector[element_counter];
|
||||
|
||||
// Get Hilbert-Value for centroid in mercartor projection
|
||||
BOOST_ASSERT(current_element.u < coordinate_list.size());
|
||||
BOOST_ASSERT(current_element.v < coordinate_list.size());
|
||||
BOOST_ASSERT(current_element.u < m_coordinate_list.size());
|
||||
BOOST_ASSERT(current_element.v < m_coordinate_list.size());
|
||||
|
||||
Coordinate current_centroid = coordinate_calculation::centroid(
|
||||
coordinate_list[current_element.u], coordinate_list[current_element.v]);
|
||||
m_coordinate_list[current_element.u], m_coordinate_list[current_element.v]);
|
||||
current_centroid.lat =
|
||||
FixedLatitude(COORDINATE_PRECISION *
|
||||
web_mercator::latToY(toFloating(current_centroid.lat)));
|
||||
@ -194,7 +195,7 @@ class StaticRTree
|
||||
|
||||
// generate tree node that resemble the objects in leaf and store it for next level
|
||||
InitializeMBRectangle(current_node.minimum_bounding_rectangle, current_leaf.objects,
|
||||
current_leaf.object_count, coordinate_list);
|
||||
current_leaf.object_count, m_coordinate_list);
|
||||
current_node.child_is_on_disk = true;
|
||||
current_node.children[0] = tree_nodes_in_level.size();
|
||||
tree_nodes_in_level.emplace_back(current_node);
|
||||
@ -275,11 +276,10 @@ class StaticRTree
|
||||
|
||||
explicit StaticRTree(const boost::filesystem::path &node_file,
|
||||
const boost::filesystem::path &leaf_file,
|
||||
const std::shared_ptr<CoordinateListT> coordinate_list)
|
||||
const CoordinateListT& coordinate_list)
|
||||
: m_coordinate_list(coordinate_list)
|
||||
{
|
||||
// open tree node file and load into RAM.
|
||||
m_coordinate_list = coordinate_list;
|
||||
|
||||
if (!boost::filesystem::exists(node_file))
|
||||
{
|
||||
throw exception("ram index file does not exist");
|
||||
@ -305,9 +305,9 @@ class StaticRTree
|
||||
explicit StaticRTree(TreeNode *tree_node_ptr,
|
||||
const uint64_t number_of_nodes,
|
||||
const boost::filesystem::path &leaf_file,
|
||||
std::shared_ptr<CoordinateListT> coordinate_list)
|
||||
const CoordinateListT& coordinate_list)
|
||||
: m_search_tree(tree_node_ptr, number_of_nodes)
|
||||
, m_coordinate_list(std::move(coordinate_list))
|
||||
, m_coordinate_list(coordinate_list)
|
||||
{
|
||||
MapLeafNodesFile(leaf_file);
|
||||
}
|
||||
@ -355,14 +355,14 @@ class StaticRTree
|
||||
|
||||
// we don't need to project the coordinates here,
|
||||
// because we use the unprojected rectangle to test against
|
||||
const Rectangle bbox{std::min((*m_coordinate_list)[current_edge.u].lon,
|
||||
(*m_coordinate_list)[current_edge.v].lon),
|
||||
std::max((*m_coordinate_list)[current_edge.u].lon,
|
||||
(*m_coordinate_list)[current_edge.v].lon),
|
||||
std::min((*m_coordinate_list)[current_edge.u].lat,
|
||||
(*m_coordinate_list)[current_edge.v].lat),
|
||||
std::max((*m_coordinate_list)[current_edge.u].lat,
|
||||
(*m_coordinate_list)[current_edge.v].lat)};
|
||||
const Rectangle bbox{std::min(m_coordinate_list[current_edge.u].lon,
|
||||
m_coordinate_list[current_edge.v].lon),
|
||||
std::max(m_coordinate_list[current_edge.u].lon,
|
||||
m_coordinate_list[current_edge.v].lon),
|
||||
std::min(m_coordinate_list[current_edge.u].lat,
|
||||
m_coordinate_list[current_edge.v].lat),
|
||||
std::max(m_coordinate_list[current_edge.u].lat,
|
||||
m_coordinate_list[current_edge.v].lat)};
|
||||
|
||||
// use the _unprojected_ input rectangle here
|
||||
if (bbox.Intersects(search_rectangle))
|
||||
@ -481,8 +481,8 @@ class StaticRTree
|
||||
for (const auto i : irange(0u, current_leaf_node.object_count))
|
||||
{
|
||||
const auto ¤t_edge = current_leaf_node.objects[i];
|
||||
const auto projected_u = web_mercator::fromWGS84((*m_coordinate_list)[current_edge.u]);
|
||||
const auto projected_v = web_mercator::fromWGS84((*m_coordinate_list)[current_edge.v]);
|
||||
const auto projected_u = web_mercator::fromWGS84(m_coordinate_list[current_edge.u]);
|
||||
const auto projected_v = web_mercator::fromWGS84(m_coordinate_list[current_edge.v]);
|
||||
|
||||
FloatCoordinate projected_nearest;
|
||||
std::tie(std::ignore, projected_nearest) =
|
||||
|
@ -563,9 +563,9 @@ void Extractor::BuildRTree(std::vector<EdgeBasedNode> node_based_edge_list,
|
||||
node_based_edge_list.resize(new_size);
|
||||
|
||||
TIMER_START(construction);
|
||||
util::StaticRTree<EdgeBasedNode> rtree(node_based_edge_list, config.rtree_nodes_output_path,
|
||||
config.rtree_leafs_output_path,
|
||||
internal_to_external_node_map);
|
||||
util::StaticRTree<EdgeBasedNode, std::vector<QueryNode>> rtree(
|
||||
node_based_edge_list, config.rtree_nodes_output_path, config.rtree_leafs_output_path,
|
||||
internal_to_external_node_map);
|
||||
|
||||
TIMER_STOP(construction);
|
||||
util::SimpleLogger().Write() << "finished r-tree construction in " << TIMER_SEC(construction)
|
||||
|
@ -52,7 +52,7 @@ static const int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
|
||||
template <typename DataT> class LinearSearchNN
|
||||
{
|
||||
public:
|
||||
LinearSearchNN(const std::shared_ptr<std::vector<Coordinate>> &coords,
|
||||
LinearSearchNN(const std::vector<Coordinate> &coords,
|
||||
const std::vector<DataT> &edges)
|
||||
: coords(coords), edges(edges)
|
||||
{
|
||||
@ -67,9 +67,9 @@ template <typename DataT> class LinearSearchNN
|
||||
const DataT &rhs) {
|
||||
using web_mercator::fromWGS84;
|
||||
const auto lhs_result = coordinate_calculation::projectPointOnSegment(
|
||||
fromWGS84(coords->at(lhs.u)), fromWGS84(coords->at(lhs.v)), projected_input);
|
||||
fromWGS84(coords[lhs.u]), fromWGS84(coords[lhs.v]), projected_input);
|
||||
const auto rhs_result = coordinate_calculation::projectPointOnSegment(
|
||||
fromWGS84(coords->at(rhs.u)), fromWGS84(coords->at(rhs.v)), projected_input);
|
||||
fromWGS84(coords[rhs.u]), fromWGS84(coords[rhs.v]), projected_input);
|
||||
const auto lhs_squared_dist = coordinate_calculation::squaredEuclideanDistance(
|
||||
lhs_result.second, projected_input);
|
||||
const auto rhs_squared_dist = coordinate_calculation::squaredEuclideanDistance(
|
||||
@ -85,7 +85,7 @@ template <typename DataT> class LinearSearchNN
|
||||
}
|
||||
|
||||
private:
|
||||
const std::shared_ptr<std::vector<Coordinate>> &coords;
|
||||
const std::vector<Coordinate> &coords;
|
||||
const std::vector<TestData> &edges;
|
||||
};
|
||||
|
||||
@ -105,7 +105,7 @@ template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
|
||||
}
|
||||
};
|
||||
|
||||
RandomGraphFixture() : coords(std::make_shared<std::vector<Coordinate>>())
|
||||
RandomGraphFixture()
|
||||
{
|
||||
std::mt19937 g(RANDOM_SEED);
|
||||
|
||||
@ -116,10 +116,10 @@ template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
|
||||
{
|
||||
int lon = lon_udist(g);
|
||||
int lat = lat_udist(g);
|
||||
coords->emplace_back(Coordinate(FixedLongitude(lon), FixedLatitude(lat)));
|
||||
coords.emplace_back(Coordinate(FixedLongitude(lon), FixedLatitude(lat)));
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<> edge_udist(0, coords->size() - 1);
|
||||
std::uniform_int_distribution<> edge_udist(0, coords.size() - 1);
|
||||
|
||||
std::unordered_set<std::pair<unsigned, unsigned>, TupleHash> used_edges;
|
||||
|
||||
@ -138,7 +138,7 @@ template <unsigned NUM_NODES, unsigned NUM_EDGES> struct RandomGraphFixture
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<Coordinate>> coords;
|
||||
std::vector<Coordinate> coords;
|
||||
std::vector<TestData> edges;
|
||||
};
|
||||
|
||||
@ -146,12 +146,11 @@ struct GraphFixture
|
||||
{
|
||||
GraphFixture(const std::vector<std::pair<FloatLongitude, FloatLatitude>> &input_coords,
|
||||
const std::vector<std::pair<unsigned, unsigned>> &input_edges)
|
||||
: coords(std::make_shared<std::vector<Coordinate>>())
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < input_coords.size(); i++)
|
||||
{
|
||||
coords->emplace_back(input_coords[i].first, input_coords[i].second);
|
||||
coords.emplace_back(input_coords[i].first, input_coords[i].second);
|
||||
}
|
||||
|
||||
for (const auto &pair : input_edges)
|
||||
@ -169,7 +168,7 @@ struct GraphFixture
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<std::vector<Coordinate>> coords;
|
||||
std::vector<Coordinate> coords;
|
||||
std::vector<TestData> edges;
|
||||
};
|
||||
|
||||
@ -189,13 +188,13 @@ typedef RandomGraphFixture<10, 30> TestRandomGraphFixture_10_30;
|
||||
|
||||
template <typename RTreeT>
|
||||
void simple_verify_rtree(RTreeT &rtree,
|
||||
const std::shared_ptr<std::vector<Coordinate>> &coords,
|
||||
const std::vector<Coordinate> &coords,
|
||||
const std::vector<TestData> &edges)
|
||||
{
|
||||
for (const auto &e : edges)
|
||||
{
|
||||
const Coordinate &pu = coords->at(e.u);
|
||||
const Coordinate &pv = coords->at(e.v);
|
||||
const Coordinate &pu = coords[e.u];
|
||||
const Coordinate &pv = coords[e.v];
|
||||
auto result_u = rtree.Nearest(pu, 1);
|
||||
auto result_v = rtree.Nearest(pv, 1);
|
||||
BOOST_CHECK(result_u.size() == 1 && result_v.size() == 1);
|
||||
@ -248,7 +247,7 @@ void build_rtree(const std::string &prefix,
|
||||
nodes_path = prefix + ".ramIndex";
|
||||
leaves_path = prefix + ".fileIndex";
|
||||
|
||||
RTreeT r(fixture->edges, nodes_path, leaves_path, *fixture->coords);
|
||||
RTreeT r(fixture->edges, nodes_path, leaves_path, fixture->coords);
|
||||
}
|
||||
|
||||
template <typename RTreeT = TestStaticRTree, typename FixtureT>
|
||||
@ -261,7 +260,7 @@ void construction_test(const std::string &prefix, FixtureT *fixture)
|
||||
LinearSearchNN<TestData> lsnn(fixture->coords, fixture->edges);
|
||||
|
||||
simple_verify_rtree(rtree, fixture->coords, fixture->edges);
|
||||
sampling_verify_rtree(rtree, lsnn, *fixture->coords, 100);
|
||||
sampling_verify_rtree(rtree, lsnn, fixture->coords, 100);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(construct_tiny, TestRandomGraphFixture_10_30)
|
||||
|
Loading…
Reference in New Issue
Block a user