Fix StaticRTree benchmark
This commit is contained in:
		
							parent
							
								
									cdb1918973
								
							
						
					
					
						commit
						24090d4642
					
				@ -25,15 +25,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "../data_structures/original_edge_data.hpp"
 | 
					 | 
				
			||||||
#include "../data_structures/query_node.hpp"
 | 
					#include "../data_structures/query_node.hpp"
 | 
				
			||||||
#include "../data_structures/shared_memory_vector_wrapper.hpp"
 | 
					 | 
				
			||||||
#include "../data_structures/static_rtree.hpp"
 | 
					#include "../data_structures/static_rtree.hpp"
 | 
				
			||||||
#include "../data_structures/edge_based_node.hpp"
 | 
					#include "../data_structures/edge_based_node.hpp"
 | 
				
			||||||
 | 
					#include "../algorithms/geospatial_query.hpp"
 | 
				
			||||||
 | 
					#include "../util/timing_util.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <osrm/coordinate.hpp>
 | 
					#include <osrm/coordinate.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <random>
 | 
					#include <random>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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 = 13;
 | 
					constexpr unsigned RANDOM_SEED = 13;
 | 
				
			||||||
@ -45,6 +46,7 @@ constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
 | 
				
			|||||||
using RTreeLeaf = EdgeBasedNode;
 | 
					using RTreeLeaf = EdgeBasedNode;
 | 
				
			||||||
using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<FixedPointCoordinate>>;
 | 
					using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<FixedPointCoordinate>>;
 | 
				
			||||||
using BenchStaticRTree = StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, false>::vector, false>;
 | 
					using BenchStaticRTree = StaticRTree<RTreeLeaf, ShM<FixedPointCoordinate, false>::vector, false>;
 | 
				
			||||||
 | 
					using BenchQuery = GeospatialQuery<BenchStaticRTree>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FixedPointCoordinateListPtr LoadCoordinates(const boost::filesystem::path &nodes_file)
 | 
					FixedPointCoordinateListPtr LoadCoordinates(const boost::filesystem::path &nodes_file)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -65,7 +67,28 @@ FixedPointCoordinateListPtr LoadCoordinates(const boost::filesystem::path &nodes
 | 
				
			|||||||
    return coords;
 | 
					    return coords;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Benchmark(BenchStaticRTree &rtree, unsigned num_queries)
 | 
					template <typename QueryT>
 | 
				
			||||||
 | 
					void BenchmarkQuery(const std::vector<FixedPointCoordinate> &queries,
 | 
				
			||||||
 | 
					                    std::string name,
 | 
				
			||||||
 | 
					                    QueryT query)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    std::cout << "Running " << name << " with " << queries.size() << " coordinates: " << std::flush;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TIMER_START(query);
 | 
				
			||||||
 | 
					    for (const auto &q : queries)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        auto result = query(q);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    TIMER_STOP(query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::cout << "Took " << TIMER_SEC(query) << " seconds "
 | 
				
			||||||
 | 
					              << "(" << TIMER_MSEC(query) << "ms"
 | 
				
			||||||
 | 
					              << ")  ->  " << TIMER_MSEC(query) / queries.size() << " ms/query "
 | 
				
			||||||
 | 
					              << "(" << TIMER_MSEC(query) << "ms"
 | 
				
			||||||
 | 
					              << ")" << std::endl;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_queries)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    std::mt19937 mt_rand(RANDOM_SEED);
 | 
					    std::mt19937 mt_rand(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);
 | 
				
			||||||
@ -76,88 +99,33 @@ void Benchmark(BenchStaticRTree &rtree, unsigned num_queries)
 | 
				
			|||||||
        queries.emplace_back(FixedPointCoordinate(lat_udist(mt_rand), lon_udist(mt_rand)));
 | 
					        queries.emplace_back(FixedPointCoordinate(lat_udist(mt_rand), lon_udist(mt_rand)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    BenchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const FixedPointCoordinate &q)
 | 
				
			||||||
                   {
 | 
					                   {
 | 
				
			||||||
        const unsigned num_results = 5;
 | 
					                       return rtree.Nearest(q, 1);
 | 
				
			||||||
        std::cout << "#### IncrementalFindPhantomNodeForCoordinate : " << num_results
 | 
					                   });
 | 
				
			||||||
                  << " phantom nodes"
 | 
					    BenchmarkQuery(queries, "raw RTree queries (10 results)",
 | 
				
			||||||
                  << "\n";
 | 
					                   [&rtree](const FixedPointCoordinate &q)
 | 
				
			||||||
 | 
					 | 
				
			||||||
        TIMER_START(query_phantom);
 | 
					 | 
				
			||||||
        std::vector<PhantomNode> phantom_node_vector;
 | 
					 | 
				
			||||||
        for (const auto &q : queries)
 | 
					 | 
				
			||||||
                   {
 | 
					                   {
 | 
				
			||||||
            phantom_node_vector.clear();
 | 
					                       return rtree.Nearest(q, 10);
 | 
				
			||||||
            rtree.IncrementalFindPhantomNodeForCoordinate(q, phantom_node_vector, 3, num_results);
 | 
					                   });
 | 
				
			||||||
            phantom_node_vector.clear();
 | 
					 | 
				
			||||||
            rtree.IncrementalFindPhantomNodeForCoordinate(q, phantom_node_vector, 17, num_results);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        TIMER_STOP(query_phantom);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        std::cout << "Took " << TIMER_MSEC(query_phantom) << " msec for " << num_queries
 | 
					    BenchmarkQuery(queries, "big component alternative queries",
 | 
				
			||||||
                  << " queries."
 | 
					                   [&geo_query](const FixedPointCoordinate &q)
 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
        std::cout << TIMER_MSEC(query_phantom) / ((double)num_queries) << " msec/query."
 | 
					 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        std::cout << "#### LocateClosestEndPointForCoordinate"
 | 
					 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    TIMER_START(query_endpoint);
 | 
					 | 
				
			||||||
    FixedPointCoordinate result;
 | 
					 | 
				
			||||||
    for (const auto &q : queries)
 | 
					 | 
				
			||||||
                   {
 | 
					                   {
 | 
				
			||||||
        rtree.LocateClosestEndPointForCoordinate(q, result, 3);
 | 
					                       return geo_query.NearestPhantomNodeWithAlternativeFromBigComponent(q);
 | 
				
			||||||
    }
 | 
					                   });
 | 
				
			||||||
    TIMER_STOP(query_endpoint);
 | 
					    BenchmarkQuery(queries, "max distance 1000", [&geo_query](const FixedPointCoordinate &q)
 | 
				
			||||||
 | 
					 | 
				
			||||||
    std::cout << "Took " << TIMER_MSEC(query_endpoint) << " msec for " << num_queries << " queries."
 | 
					 | 
				
			||||||
              << "\n";
 | 
					 | 
				
			||||||
    std::cout << TIMER_MSEC(query_endpoint) / ((double)num_queries) << " msec/query."
 | 
					 | 
				
			||||||
              << "\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    std::cout << "#### FindPhantomNodeForCoordinate"
 | 
					 | 
				
			||||||
              << "\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    TIMER_START(query_node);
 | 
					 | 
				
			||||||
    for (const auto &q : queries)
 | 
					 | 
				
			||||||
                   {
 | 
					                   {
 | 
				
			||||||
        PhantomNode phantom;
 | 
					                       return geo_query.NearestPhantomNodesInRange(q, 1000);
 | 
				
			||||||
        rtree.FindPhantomNodeForCoordinate(q, phantom, 3);
 | 
					                   });
 | 
				
			||||||
    }
 | 
					    BenchmarkQuery(queries, "PhantomNode query (1 result)", [&geo_query](const FixedPointCoordinate &q)
 | 
				
			||||||
    TIMER_STOP(query_node);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    std::cout << "Took " << TIMER_MSEC(query_node) << " msec for " << num_queries << " queries."
 | 
					 | 
				
			||||||
              << "\n";
 | 
					 | 
				
			||||||
    std::cout << TIMER_MSEC(query_node) / ((double)num_queries) << " msec/query."
 | 
					 | 
				
			||||||
              << "\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                   {
 | 
					                   {
 | 
				
			||||||
        const unsigned num_results = 1;
 | 
					                       return geo_query.NearestPhantomNodes(q, 1);
 | 
				
			||||||
        std::cout << "#### IncrementalFindPhantomNodeForCoordinate : " << num_results
 | 
					                   });
 | 
				
			||||||
                  << " phantom nodes"
 | 
					    BenchmarkQuery(queries, "PhantomNode query (10 result)", [&geo_query](const FixedPointCoordinate &q)
 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        TIMER_START(query_phantom);
 | 
					 | 
				
			||||||
        std::vector<PhantomNode> phantom_node_vector;
 | 
					 | 
				
			||||||
        for (const auto &q : queries)
 | 
					 | 
				
			||||||
                   {
 | 
					                   {
 | 
				
			||||||
            phantom_node_vector.clear();
 | 
					                       return geo_query.NearestPhantomNodes(q, 10);
 | 
				
			||||||
            rtree.IncrementalFindPhantomNodeForCoordinate(q, phantom_node_vector, 3, num_results);
 | 
					                   });
 | 
				
			||||||
            phantom_node_vector.clear();
 | 
					 | 
				
			||||||
            rtree.IncrementalFindPhantomNodeForCoordinate(q, phantom_node_vector, 17, num_results);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        TIMER_STOP(query_phantom);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        std::cout << "Took " << TIMER_MSEC(query_phantom) << " msec for " << num_queries
 | 
					 | 
				
			||||||
                  << " queries."
 | 
					 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
        std::cout << TIMER_MSEC(query_phantom) / ((double)num_queries) << " msec/query."
 | 
					 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        std::cout << "#### LocateClosestEndPointForCoordinate"
 | 
					 | 
				
			||||||
                  << "\n";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char **argv)
 | 
					int main(int argc, char **argv)
 | 
				
			||||||
@ -176,8 +144,9 @@ int main(int argc, char **argv)
 | 
				
			|||||||
    auto coords = LoadCoordinates(nodesPath);
 | 
					    auto coords = LoadCoordinates(nodesPath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    BenchStaticRTree rtree(ramPath, filePath, coords);
 | 
					    BenchStaticRTree rtree(ramPath, filePath, coords);
 | 
				
			||||||
 | 
					    BenchQuery query(rtree, coords);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Benchmark(rtree, 10000);
 | 
					    Benchmark(rtree, query, 10000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user