From 3061c8b854abca0840652f1cb9d88c55cee47e8f Mon Sep 17 00:00:00 2001 From: Huyen Chau Nguyen Date: Wed, 19 Aug 2015 10:04:36 +0200 Subject: [PATCH] solve merge conflicts --- algorithms/tarjan_scc.hpp | 6 +-- data_structures/matrix_graph_wrapper.hpp | 4 +- plugins/round_trip.hpp | 63 ++++++++++++------------ server/api_grammar.hpp | 1 - 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/algorithms/tarjan_scc.hpp b/algorithms/tarjan_scc.hpp index 05bbb0422..8444d785a 100644 --- a/algorithms/tarjan_scc.hpp +++ b/algorithms/tarjan_scc.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TINY_COMPONENTS_HPP -#define TINY_COMPONENTS_HPP +#ifndef TARJAN_SCC_HPP +#define TARJAN_SCC_HPP #include "../typedefs.h" #include "../data_structures/deallocating_vector.hpp" @@ -209,4 +209,4 @@ template class TarjanSCC unsigned get_component_id(const NodeID node) const { return components_index[node]; } }; -#endif /* TINY_COMPONENTS_HPP */ +#endif /* TARJAN_SCC_HPP */ diff --git a/data_structures/matrix_graph_wrapper.hpp b/data_structures/matrix_graph_wrapper.hpp index 3bf9259ec..7e91e8b33 100644 --- a/data_structures/matrix_graph_wrapper.hpp +++ b/data_structures/matrix_graph_wrapper.hpp @@ -38,7 +38,7 @@ public: MatrixGraphWrapper(std::vector table, const unsigned number_of_nodes) : table_(table), number_of_nodes_(number_of_nodes) {}; - unsigned GetNumberOfNodes() { + unsigned GetNumberOfNodes() const { return number_of_nodes_; } @@ -53,7 +53,7 @@ public: return edges; } - unsigned GetTarget(const unsigned edge) { + unsigned GetTarget(const unsigned edge) const { return edge; } diff --git a/plugins/round_trip.hpp b/plugins/round_trip.hpp index 0670af3d4..a1a955f9f 100644 --- a/plugins/round_trip.hpp +++ b/plugins/round_trip.hpp @@ -31,13 +31,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugin_base.hpp" #include "../algorithms/object_encoder.hpp" -#include "../algorithms/tiny_components.hpp" +#include "../algorithms/tarjan_scc.hpp" #include "../routing_algorithms/tsp_nearest_neighbour.hpp" #include "../routing_algorithms/tsp_farthest_insertion.hpp" #include "../routing_algorithms/tsp_brute_force.hpp" #include "../data_structures/query_edge.hpp" #include "../data_structures/search_engine.hpp" #include "../data_structures/matrix_graph_wrapper.hpp" +#include "../data_structures/restriction.hpp" +#include "../data_structures/restriction_map.hpp" #include "../descriptors/descriptor_base.hpp" #include "../descriptors/json_descriptor.hpp" #include "../util/json_renderer.hpp" @@ -103,21 +105,21 @@ template class RoundTripPlugin final : public BasePlugin void SplitUnaccessibleLocations(PhantomNodeArray & phantom_node_vector, std::vector & result_table, - std::vector> & components) { + std::vector> & components) { // Run TarjanSCC const auto number_of_locations = phantom_node_vector.size(); auto wrapper = std::make_shared>(result_table, number_of_locations); - auto empty_restriction = RestrictionMap(std::vector()); - std::vector empty_vector; - auto scc = TarjanSCC>(wrapper, empty_restriction, empty_vector); + // auto empty_restriction = RestrictionMap(std::vector()); + // std::vector empty_vector; + auto scc = TarjanSCC>(wrapper); scc.run(); - for (int j = 0; j < scc.get_number_of_components(); ++j){ - components.push_back(std::vector()); + for (size_t j = 0; j < scc.get_number_of_components(); ++j){ + components.push_back(std::vector()); } - for (int i = 0; i < number_of_locations; ++i) { + for (size_t i = 0; i < number_of_locations; ++i) { components[scc.get_component_id(i)].push_back(i); } } @@ -147,7 +149,7 @@ template class RoundTripPlugin final : public BasePlugin void ComputeRoute(const PhantomNodeArray & phantom_node_vector, const RouteParameters & route_parameters, - std::vector & trip, + const std::vector & trip, InternalRouteResult & min_route) { // given he final trip, compute total distance and return the route and location permutation PhantomNodes viapoint; @@ -165,7 +167,7 @@ template class RoundTripPlugin final : public BasePlugin void ComputeRoute(const PhantomNodeArray & phantom_node_vector, const RouteParameters & route_parameters, - std::vector> & trip, + std::vector> & trip, std::vector & route) { for (const auto & curr_trip : trip) { InternalRouteResult curr_route; @@ -193,10 +195,12 @@ template class RoundTripPlugin final : public BasePlugin return 400; } - + const constexpr std::size_t BF_MAX_FEASABLE = 10; + auto number_of_locations = phantom_node_vector.size(); BOOST_ASSERT_MSG(result_table->size() > 0, "Distance Table is empty."); + //check if locations are in different strongly connected components (SCC) - const auto maxint = std::numeric_limits::max(); + const auto maxint = INVALID_EDGE_WEIGHT; if (*std::max_element(std::begin(*result_table), std::end(*result_table)) == maxint) { //TODO DELETE @@ -207,45 +211,43 @@ template class RoundTripPlugin final : public BasePlugin TIMER_START(tsp); // Compute all SCC - std::vector> components; + std::vector> components; SplitUnaccessibleLocations(phantom_node_vector, *result_table, components); - // std::vector> res_route (components.size()-1); - std::vector> res_route; - const constexpr std::size_t BF_MAX_FEASABLE = 14; + // std::vector> res_route (components.size()-1); + std::vector> res_route; //run TSP computation for every SCC for(auto k = 0; k < components.size(); ++k) { if (components[k].size() > 1) { - std::vector scc_route; + std::vector scc_route; scc_route.reserve(components[k].size()); // Compute the TSP with the given algorithm if (route_parameters.tsp_algo == "BF" && route_parameters.coordinates.size() < BF_MAX_FEASABLE) { SimpleLogger().Write() << "Running SCC BF"; - osrm::tsp::BruteForceTSP(components[k], phantom_node_vector, *result_table, scc_route); + osrm::tsp::BruteForceTSP(components[k], number_of_locations, *result_table, scc_route); res_route.push_back(scc_route); } else if (route_parameters.tsp_algo == "NN") { SimpleLogger().Write() << "Running SCC NN"; - osrm::tsp::NearestNeighbourTSP(components[k], phantom_node_vector, *result_table, scc_route); + osrm::tsp::NearestNeighbourTSP(components[k], number_of_locations, *result_table, scc_route); res_route.push_back(scc_route); } else if (route_parameters.tsp_algo == "FI") { SimpleLogger().Write() << "Running SCC FI"; - osrm::tsp::FarthestInsertionTSP(components[k], phantom_node_vector, *result_table, scc_route); + osrm::tsp::FarthestInsertionTSP(components[k], number_of_locations, *result_table, scc_route); res_route.push_back(scc_route); } else{ SimpleLogger().Write() << "Running SCC FI"; - osrm::tsp::FarthestInsertionTSP(components[k], phantom_node_vector, *result_table, scc_route); + osrm::tsp::FarthestInsertionTSP(components[k], number_of_locations, *result_table, scc_route); res_route.push_back(scc_route); } } } - SimpleLogger().Write() << "DONE"; std::vector route; ComputeRoute(phantom_node_vector, route_parameters, res_route, route); TIMER_STOP(tsp); SetRuntimeOutput(TIMER_MSEC(tsp), json_result); - + SimpleLogger().Write() << "Computed roundtrip in " << TIMER_MSEC(tsp) << "ms"; // SimpleLogger().Write() << "Route is"; // for (auto x : res_route) { // for (auto y : x) @@ -260,8 +262,7 @@ template class RoundTripPlugin final : public BasePlugin } SetDistanceOutput(dist, json_result); } else { //run TSP computation for all locations - auto number_of_locations = phantom_node_vector.size(); - std::vector res_route; + std::vector res_route; res_route.reserve(number_of_locations); // Compute the TSP with the given algorithm @@ -269,22 +270,21 @@ template class RoundTripPlugin final : public BasePlugin // TODO patrick nach userfreundlichkeit fragen, BF vs bf usw if (route_parameters.tsp_algo == "BF" && route_parameters.coordinates.size() < BF_MAX_FEASABLE) { SimpleLogger().Write() << "Running BF"; - res_route = osrm::tsp::BruteForceTSP(phantom_node_vector, *result_table, res_route); + osrm::tsp::BruteForceTSP(number_of_locations, *result_table, res_route); } else if (route_parameters.tsp_algo == "NN") { SimpleLogger().Write() << "Running NN"; - osrm::tsp::NearestNeighbourTSP(phantom_node_vector, *result_table, res_route); + osrm::tsp::NearestNeighbourTSP(number_of_locations, *result_table, res_route); } else if (route_parameters.tsp_algo == "FI") { SimpleLogger().Write() << "Running FI"; - osrm::tsp::FarthestInsertionTSP(phantom_node_vector, *result_table, res_route); + osrm::tsp::FarthestInsertionTSP(number_of_locations, *result_table, res_route); } else { SimpleLogger().Write() << "Running FI"; - osrm::tsp::FarthestInsertionTSP(phantom_node_vector, *result_table, res_route); - // osrm::tsp::NearestNeighbourTSP(phantom_node_vector, *result_table, res_route); + osrm::tsp::FarthestInsertionTSP(number_of_locations, *result_table, res_route); } // TODO asserts numer of result blablabla size // TODO std::is_permutation // TODO boost range - SimpleLogger().Write() << "DONE"; + InternalRouteResult min_route; @@ -299,6 +299,7 @@ template class RoundTripPlugin final : public BasePlugin //TODO TIMER im LOGGER SetRuntimeOutput(TIMER_MSEC(tsp), json_result); + SimpleLogger().Write() << "Computed roundtrip in " << TIMER_MSEC(tsp) << "ms"; SetLocPermutationOutput(res_route, json_result); //TODO MEHR ASSERTIONS! :O SetDistanceOutput(min_route.shortest_path_length, json_result); diff --git a/server/api_grammar.hpp b/server/api_grammar.hpp index c93518a34..8013b8243 100644 --- a/server/api_grammar.hpp +++ b/server/api_grammar.hpp @@ -99,7 +99,6 @@ template struct APIGrammar : qi::grammar service, zoom, output, string, jsonp, checksum, location, hint, timestamp, stringwithDot, stringwithPercent, language, instruction, geometry, cmp, alt_route, u, uturns, old_API, num_results, matching_beta, gps_precision, classify, locs, stringforPolyline, tsp_algo; - uturns, old_API, num_results, matching_beta, gps_precision, classify, tsp_algo; HandlerT *handler; };