From e6eea67eeb4734149253a54a227db29e0295bd17 Mon Sep 17 00:00:00 2001 From: Huyen Chau Nguyen Date: Thu, 20 Aug 2015 16:07:56 +0200 Subject: [PATCH] rename all names with round_trip, trip or tsp to trip to standardize the naming --- data_structures/route_parameters.cpp | 4 +- include/osrm/route_parameters.hpp | 6 +- library/osrm_impl.cpp | 2 +- plugins/{round_trip.hpp => trip.hpp} | 34 +++--- ...p_brute_force.hpp => trip_brute_force.hpp} | 12 +- ...ertion.hpp => trip_farthest_insertion.hpp} | 19 ++-- ...ighbour.hpp => trip_nearest_neighbour.hpp} | 18 +-- ...p_tabu_search.hpp => trip_tabu_search.hpp} | 12 +- server/api_grammar.hpp | 8 +- tools/tsp_logs.hpp | 103 ------------------ unit_tests/routing_algorithms/tsp.cpp | 4 +- 11 files changed, 59 insertions(+), 163 deletions(-) rename plugins/{round_trip.hpp => trip.hpp} (92%) rename routing_algorithms/{tsp_brute_force.hpp => trip_brute_force.hpp} (94%) rename routing_algorithms/{tsp_farthest_insertion.hpp => trip_farthest_insertion.hpp} (94%) rename routing_algorithms/{tsp_nearest_neighbour.hpp => trip_nearest_neighbour.hpp} (90%) rename routing_algorithms/{tsp_tabu_search.hpp => trip_tabu_search.hpp} (90%) delete mode 100644 tools/tsp_logs.hpp diff --git a/data_structures/route_parameters.cpp b/data_structures/route_parameters.cpp index 31e91c1fa..e48d246eb 100644 --- a/data_structures/route_parameters.cpp +++ b/data_structures/route_parameters.cpp @@ -122,9 +122,9 @@ void RouteParameters::setLanguage(const std::string &language_string) language = language_string; } -void RouteParameters::setTSPAlgo(const std::string &tsp_algo_string) +void RouteParameters::setTripAlgo(const std::string &trip_algo_string) { - tsp_algo = tsp_algo_string; + trip_algo = trip_algo_string; } void RouteParameters::setGeometryFlag(const bool flag) { geometry = flag; } diff --git a/include/osrm/route_parameters.hpp b/include/osrm/route_parameters.hpp index 94ed3a336..5f5e09f80 100644 --- a/include/osrm/route_parameters.hpp +++ b/include/osrm/route_parameters.hpp @@ -78,10 +78,10 @@ struct RouteParameters void setCompressionFlag(const bool flag); void addCoordinate(const boost::fusion::vector &received_coordinates); - + void getCoordinatesFromGeometry(const std::string geometry_string); - void setTSPAlgo(const std::string &tsp_algo); + void setTripAlgo(const std::string &trip_algo); short zoom_level; bool print_instructions; @@ -99,7 +99,7 @@ struct RouteParameters std::string output_format; std::string jsonp_parameter; std::string language; - std::string tsp_algo; + std::string trip_algo; std::vector hints; std::vector timestamps; std::vector uturns; diff --git a/library/osrm_impl.cpp b/library/osrm_impl.cpp index 8057069eb..075c65f79 100644 --- a/library/osrm_impl.cpp +++ b/library/osrm_impl.cpp @@ -41,7 +41,7 @@ class named_mutex; #include "../plugins/locate.hpp" #include "../plugins/nearest.hpp" #include "../plugins/timestamp.hpp" -#include "../plugins/round_trip.hpp" +#include "../plugins/trip.hpp" #include "../plugins/viaroute.hpp" #include "../plugins/match.hpp" #include "../server/data_structures/datafacade_base.hpp" diff --git a/plugins/round_trip.hpp b/plugins/trip.hpp similarity index 92% rename from plugins/round_trip.hpp rename to plugins/trip.hpp index 5cbff46a7..f2cc89dca 100644 --- a/plugins/round_trip.hpp +++ b/plugins/trip.hpp @@ -25,16 +25,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ROUND_TRIP_HPP -#define ROUND_TRIP_HPP +#ifndef TRIP_HPP +#define TRIP_HPP #include "plugin_base.hpp" #include "../algorithms/object_encoder.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 "../routing_algorithms/trip_nearest_neighbour.hpp" +#include "../routing_algorithms/trip_farthest_insertion.hpp" +#include "../routing_algorithms/trip_brute_force.hpp" #include "../data_structures/query_edge.hpp" #include "../data_structures/search_engine.hpp" #include "../data_structures/matrix_graph_wrapper.hpp" @@ -258,8 +258,8 @@ template class RoundTripPlugin final : public BasePlugin std::vector> route_result; route_result.reserve(scc.GetNumberOfComponents()); - TIMER_START(tsp); - //run TSP computation for every SCC + TIMER_START(trip); + //run Trip computation for every SCC for (std::size_t k = 0; k < scc.GetNumberOfComponents(); ++k) { const auto component_size = scc.range[k+1] - scc.range[k]; @@ -270,22 +270,22 @@ template class RoundTripPlugin final : public BasePlugin NodeIDIterator start = std::begin(scc.component) + scc.range[k]; NodeIDIterator end = std::begin(scc.component) + scc.range[k+1]; - // Compute the TSP with the given algorithm - if (route_parameters.tsp_algo == "BF" && route_parameters.coordinates.size() < BF_MAX_FEASABLE) { + // Compute the Trip with the given algorithm + if (route_parameters.trip_algo == "BF" && route_parameters.coordinates.size() < BF_MAX_FEASABLE) { SimpleLogger().Write() << "Running brute force"; - scc_route = osrm::tsp::BruteForceTSP(start, end, number_of_locations, result_table); + scc_route = osrm::trip::BruteForceTrip(start, end, number_of_locations, result_table); route_result.push_back(scc_route); - } else if (route_parameters.tsp_algo == "NN") { + } else if (route_parameters.trip_algo == "NN") { SimpleLogger().Write() << "Running nearest neighbour"; - scc_route = osrm::tsp::NearestNeighbourTSP(start, end, number_of_locations, result_table); + scc_route = osrm::trip::NearestNeighbourTrip(start, end, number_of_locations, result_table); route_result.push_back(scc_route); - } else if (route_parameters.tsp_algo == "FI") { + } else if (route_parameters.trip_algo == "FI") { SimpleLogger().Write() << "Running farthest insertion"; - scc_route = osrm::tsp::FarthestInsertionTSP(start, end, number_of_locations, result_table); + scc_route = osrm::trip::FarthestInsertionTrip(start, end, number_of_locations, result_table); route_result.push_back(scc_route); } else{ SimpleLogger().Write() << "Running farthest insertion"; - scc_route = osrm::tsp::FarthestInsertionTSP(start, end, number_of_locations, result_table); + scc_route = osrm::trip::FarthestInsertionTrip(start, end, number_of_locations, result_table); route_result.push_back(scc_route); } @@ -311,7 +311,7 @@ template class RoundTripPlugin final : public BasePlugin ComputeRoute(phantom_node_vector, route_parameters, route_result[r], comp_route[r]); } - TIMER_STOP(tsp); + TIMER_STOP(trip); // prepare JSON output @@ -342,4 +342,4 @@ template class RoundTripPlugin final : public BasePlugin }; -#endif // ROUND_TRIP_HPP +#endif // TRIP_HPP diff --git a/routing_algorithms/tsp_brute_force.hpp b/routing_algorithms/trip_brute_force.hpp similarity index 94% rename from routing_algorithms/tsp_brute_force.hpp rename to routing_algorithms/trip_brute_force.hpp index e02ac3252..24319d583 100644 --- a/routing_algorithms/tsp_brute_force.hpp +++ b/routing_algorithms/trip_brute_force.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TSP_BRUTE_FORCE_HPP -#define TSP_BRUTE_FORCE_HPP +#ifndef Trip_BRUTE_FORCE_HPP +#define Trip_BRUTE_FORCE_HPP #include "../data_structures/search_engine.hpp" @@ -49,7 +49,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace osrm { -namespace tsp +namespace trip { // computes the distance of a given permutation @@ -71,7 +71,7 @@ EdgeWeight ReturnDistance(const DistTableWrapper & dist_table, // computes the route by computing all permutations and selecting the shortest template -std::vector BruteForceTSP(const NodeIDIterator start, +std::vector BruteForceTrip(const NodeIDIterator start, const NodeIDIterator end, const std::size_t number_of_locations, const DistTableWrapper & dist_table) { @@ -99,6 +99,6 @@ std::vector BruteForceTSP(const NodeIDIterator start, return route; } -} //end namespace tsp +} //end namespace trip } //end namespace osrm -#endif // TSP_BRUTE_FORCE_HPP \ No newline at end of file +#endif // Trip_BRUTE_FORCE_HPP \ No newline at end of file diff --git a/routing_algorithms/tsp_farthest_insertion.hpp b/routing_algorithms/trip_farthest_insertion.hpp similarity index 94% rename from routing_algorithms/tsp_farthest_insertion.hpp rename to routing_algorithms/trip_farthest_insertion.hpp index 9ffc44544..2368192fb 100644 --- a/routing_algorithms/tsp_farthest_insertion.hpp +++ b/routing_algorithms/trip_farthest_insertion.hpp @@ -25,14 +25,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TSP_FARTHEST_INSERTION_HPP -#define TSP_FARTHEST_INSERTION_HPP +#ifndef TRIP_FARTHEST_INSERTION_HPP +#define TRIP_FARTHEST_INSERTION_HPP #include "../data_structures/search_engine.hpp" #include "../util/string_util.hpp" #include "../util/dist_table_wrapper.hpp" -#include "../tools/tsp_logs.hpp" #include @@ -47,7 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace osrm { -namespace tsp +namespace trip { // given a route and a new location, find the best place of insertion and @@ -150,10 +149,10 @@ std::vector FindRoute(const std::size_t & number_of_locations, } template -std::vector FarthestInsertionTSP(const NodeIDIterator & start, - const NodeIDIterator & end, - const std::size_t number_of_locations, - const DistTableWrapper & dist_table) { +std::vector FarthestInsertionTrip(const NodeIDIterator & start, + const NodeIDIterator & end, + const std::size_t number_of_locations, + const DistTableWrapper & dist_table) { ////////////////////////////////////////////////////////////////////////////////////////////////// // START FARTHEST INSERTION HERE // 1. start at a random round trip of 2 locations @@ -192,7 +191,7 @@ std::vector FarthestInsertionTSP(const NodeIDIterator & start, } -} //end namespace tsp +} //end namespace trip } //end namespace osrm -#endif // TSP_FARTHEST_INSERTION_HPP \ No newline at end of file +#endif // TRIP_FARTHEST_INSERTION_HPP \ No newline at end of file diff --git a/routing_algorithms/tsp_nearest_neighbour.hpp b/routing_algorithms/trip_nearest_neighbour.hpp similarity index 90% rename from routing_algorithms/tsp_nearest_neighbour.hpp rename to routing_algorithms/trip_nearest_neighbour.hpp index 0f42b4514..510e87436 100644 --- a/routing_algorithms/tsp_nearest_neighbour.hpp +++ b/routing_algorithms/trip_nearest_neighbour.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TSP_NEAREST_NEIGHBOUR_HPP -#define TSP_NEAREST_NEIGHBOUR_HPP +#ifndef TRIP_NEAREST_NEIGHBOUR_HPP +#define TRIP_NEAREST_NEIGHBOUR_HPP #include "../data_structures/search_engine.hpp" @@ -46,13 +46,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace osrm { -namespace tsp +namespace trip { template -std::vector NearestNeighbourTSP(const NodeIDIterator & start, - const NodeIDIterator & end, - const std::size_t number_of_locations, - const DistTableWrapper & dist_table) { +std::vector NearestNeighbourTrip(const NodeIDIterator & start, + const NodeIDIterator & end, + const std::size_t number_of_locations, + const DistTableWrapper & dist_table) { ////////////////////////////////////////////////////////////////////////////////////////////////// // START GREEDY NEAREST NEIGHBOUR HERE // 1. grab a random location and mark as starting point @@ -117,6 +117,6 @@ std::vector NearestNeighbourTSP(const NodeIDIterator & start, return route; } -} //end namespace tsp +} //end namespace trip } //end namespace osrm -#endif // TSP_NEAREST_NEIGHBOUR_HPP \ No newline at end of file +#endif // TRIP_NEAREST_NEIGHBOUR_HPP \ No newline at end of file diff --git a/routing_algorithms/tsp_tabu_search.hpp b/routing_algorithms/trip_tabu_search.hpp similarity index 90% rename from routing_algorithms/tsp_tabu_search.hpp rename to routing_algorithms/trip_tabu_search.hpp index 4db7dc470..02e063a0e 100644 --- a/routing_algorithms/tsp_tabu_search.hpp +++ b/routing_algorithms/trip_tabu_search.hpp @@ -25,8 +25,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TSP_BRUTE_FORCE_HPP -#define TSP_BRUTE_FORCE_HPP +#ifndef TRIP_BRUTE_FORCE_HPP +#define TRIP_BRUTE_FORCE_HPP #include "../data_structures/search_engine.hpp" @@ -48,10 +48,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace osrm { -namespace tsp +namespace trip { -void TabuSearchTSP(std::vector & location, +void TabuSearchTrip(std::vector & location, const PhantomNodeArray & phantom_node_vector, const std::vector & dist_table, InternalRouteResult & min_route, @@ -60,7 +60,7 @@ void TabuSearchTSP(std::vector & location, } -void TabuSearchTSP(const PhantomNodeArray & phantom_node_vector, +void TabuSearchTrip(const PhantomNodeArray & phantom_node_vector, const std::vector & dist_table, InternalRouteResult & min_route, std::vector & min_loc_permutation) { @@ -70,4 +70,4 @@ void TabuSearchTSP(const PhantomNodeArray & phantom_node_vector, } } -#endif // TSP_BRUTE_FORCE_HPP \ No newline at end of file +#endif // TRIP_BRUTE_FORCE_HPP \ No newline at end of file diff --git a/server/api_grammar.hpp b/server/api_grammar.hpp index 8013b8243..e775c2e88 100644 --- a/server/api_grammar.hpp +++ b/server/api_grammar.hpp @@ -42,7 +42,7 @@ template struct APIGrammar : qi::grammar> -(uturns); query = ('?') >> (+(zoom | output | jsonp | checksum | location | hint | timestamp | u | cmp | language | instruction | geometry | alt_route | old_API | num_results | - matching_beta | gps_precision | classify | tsp_algo | locs)); + matching_beta | gps_precision | classify | trip_algo | locs)); zoom = (-qi::lit('&')) >> qi::lit('z') >> '=' >> qi::short_[boost::bind(&HandlerT::setZoomLevel, handler, ::_1)]; @@ -85,8 +85,8 @@ template struct APIGrammar : qi::grammar> qi::lit("locs") >> '=' >> stringforPolyline[boost::bind(&HandlerT::getCoordinatesFromGeometry, handler, ::_1)]; - tsp_algo = (-qi::lit('&')) >> qi::lit("tsp_algo") >> '=' >> - string[boost::bind(&HandlerT::setTSPAlgo, handler, ::_1)]; + trip_algo = (-qi::lit('&')) >> qi::lit("trip_algo") >> '=' >> + string[boost::bind(&HandlerT::setTripAlgo, handler, ::_1)]; string = +(qi::char_("a-zA-Z")); stringwithDot = +(qi::char_("a-zA-Z0-9_.-")); @@ -98,7 +98,7 @@ template struct APIGrammar : qi::grammar api_call, query; qi::rule 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, locs, stringforPolyline, trip_algo; HandlerT *handler; }; diff --git a/tools/tsp_logs.hpp b/tools/tsp_logs.hpp deleted file mode 100644 index fcc9af096..000000000 --- a/tools/tsp_logs.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - -Copyright (c) 2015, Project OSRM contributors -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or -other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#ifndef TSP_LOGS_HPP -#define TSP_LOGS_HPP - - -#include "../data_structures/search_engine.hpp" -#include "../util/string_util.hpp" - -#include - -#include - -#include -#include -#include -#include -#include -#include "../util/simple_logger.hpp" - - -namespace osrm -{ -namespace tsp -{ - - -inline void PrintDistTable(const std::vector & dist_table, const int number_of_locations) { - int j = 0; - for (auto i = dist_table.begin(); i != dist_table.end(); ++i){ - if (j % number_of_locations == 0) { - std::cout << std::endl; - } - std::cout << std::setw(6) << *i << " "; - ++j; - } - std::cout << std::endl; -} - -bool CheckSymmetricTable(const std::vector & dist_table, const int number_of_locations) { - bool is_quadratic = true; - for (int i = 0; i < number_of_locations; ++i) { - for(int j = 0; j < number_of_locations; ++j) { - int a = *(dist_table.begin() + (i * number_of_locations) + j); - int b = *(dist_table.begin() + (j * number_of_locations) + i); - if (a !=b) { - is_quadratic = false; - } - } - } - return is_quadratic; -} - -void LogRoute(std::vector location_ids){ - SimpleLogger().Write() << "LOC ORDER"; - for (auto x : location_ids) { - SimpleLogger().Write() << x; - } -} - -int ReturnDistanceFI(const std::vector & dist_table, std::list current_trip, const int number_of_locations) { - int route_dist = 0; - - // compute length and stop if length is longer than route already found - for (auto i = current_trip.begin(); i != std::prev(current_trip.end()); ++i) { - //get distance from location i to location i+1 - route_dist += *(dist_table.begin() + (*i * number_of_locations) + *std::next(i)); - } - //get distance from last location to first location - route_dist += *(dist_table.begin() + (*std::prev(current_trip.end()) * number_of_locations) + current_trip.front()); - - return route_dist; -} - - -} -} -#endif // TSP_LOGS_HPP \ No newline at end of file diff --git a/unit_tests/routing_algorithms/tsp.cpp b/unit_tests/routing_algorithms/tsp.cpp index 0c6a52462..fde22295c 100644 --- a/unit_tests/routing_algorithms/tsp.cpp +++ b/unit_tests/routing_algorithms/tsp.cpp @@ -25,7 +25,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../../routing_algorithms/tsp_brute_force.hpp" +#include "../../routing_algorithms/trip_brute_force.hpp" #include #include @@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -BOOST_AUTO_TEST_SUITE(tsp) +BOOST_AUTO_TEST_SUITE(trip) // BOOST_AUTO_TEST_CASE(check_distance_computation) // {