rename all names with round_trip, trip or tsp to trip to standardize the naming

This commit is contained in:
Huyen Chau Nguyen 2015-08-20 16:07:56 +02:00
parent 8429a1e792
commit e6eea67eeb
11 changed files with 59 additions and 163 deletions

View File

@ -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; }

View File

@ -78,10 +78,10 @@ struct RouteParameters
void setCompressionFlag(const bool flag);
void addCoordinate(const boost::fusion::vector<double, double> &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<std::string> hints;
std::vector<unsigned> timestamps;
std::vector<bool> uturns;

View File

@ -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"

View File

@ -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 DataFacadeT> class RoundTripPlugin final : public BasePlugin
std::vector<std::vector<NodeID>> 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 DataFacadeT> 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 DataFacadeT> 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 DataFacadeT> class RoundTripPlugin final : public BasePlugin
};
#endif // ROUND_TRIP_HPP
#endif // TRIP_HPP

View File

@ -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<EdgeWeight> & dist_table,
// computes the route by computing all permutations and selecting the shortest
template <typename NodeIDIterator>
std::vector<NodeID> BruteForceTSP(const NodeIDIterator start,
std::vector<NodeID> BruteForceTrip(const NodeIDIterator start,
const NodeIDIterator end,
const std::size_t number_of_locations,
const DistTableWrapper<EdgeWeight> & dist_table) {
@ -99,6 +99,6 @@ std::vector<NodeID> BruteForceTSP(const NodeIDIterator start,
return route;
}
} //end namespace tsp
} //end namespace trip
} //end namespace osrm
#endif // TSP_BRUTE_FORCE_HPP
#endif // Trip_BRUTE_FORCE_HPP

View File

@ -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 <osrm/json_container.hpp>
@ -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<NodeID> FindRoute(const std::size_t & number_of_locations,
}
template <typename NodeIDIterator>
std::vector<NodeID> FarthestInsertionTSP(const NodeIDIterator & start,
const NodeIDIterator & end,
const std::size_t number_of_locations,
const DistTableWrapper<EdgeWeight> & dist_table) {
std::vector<NodeID> FarthestInsertionTrip(const NodeIDIterator & start,
const NodeIDIterator & end,
const std::size_t number_of_locations,
const DistTableWrapper<EdgeWeight> & dist_table) {
//////////////////////////////////////////////////////////////////////////////////////////////////
// START FARTHEST INSERTION HERE
// 1. start at a random round trip of 2 locations
@ -192,7 +191,7 @@ std::vector<NodeID> FarthestInsertionTSP(const NodeIDIterator & start,
}
} //end namespace tsp
} //end namespace trip
} //end namespace osrm
#endif // TSP_FARTHEST_INSERTION_HPP
#endif // TRIP_FARTHEST_INSERTION_HPP

View File

@ -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 <typename NodeIDIterator>
std::vector<NodeID> NearestNeighbourTSP(const NodeIDIterator & start,
const NodeIDIterator & end,
const std::size_t number_of_locations,
const DistTableWrapper<EdgeWeight> & dist_table) {
std::vector<NodeID> NearestNeighbourTrip(const NodeIDIterator & start,
const NodeIDIterator & end,
const std::size_t number_of_locations,
const DistTableWrapper<EdgeWeight> & dist_table) {
//////////////////////////////////////////////////////////////////////////////////////////////////
// START GREEDY NEAREST NEIGHBOUR HERE
// 1. grab a random location and mark as starting point
@ -117,6 +117,6 @@ std::vector<NodeID> NearestNeighbourTSP(const NodeIDIterator & start,
return route;
}
} //end namespace tsp
} //end namespace trip
} //end namespace osrm
#endif // TSP_NEAREST_NEIGHBOUR_HPP
#endif // TRIP_NEAREST_NEIGHBOUR_HPP

View File

@ -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<unsigned> & location,
void TabuSearchTrip(std::vector<unsigned> & location,
const PhantomNodeArray & phantom_node_vector,
const std::vector<EdgeWeight> & dist_table,
InternalRouteResult & min_route,
@ -60,7 +60,7 @@ void TabuSearchTSP(std::vector<unsigned> & location,
}
void TabuSearchTSP(const PhantomNodeArray & phantom_node_vector,
void TabuSearchTrip(const PhantomNodeArray & phantom_node_vector,
const std::vector<EdgeWeight> & dist_table,
InternalRouteResult & min_route,
std::vector<int> & min_loc_permutation) {
@ -70,4 +70,4 @@ void TabuSearchTSP(const PhantomNodeArray & phantom_node_vector,
}
}
#endif // TSP_BRUTE_FORCE_HPP
#endif // TRIP_BRUTE_FORCE_HPP

View File

@ -42,7 +42,7 @@ template <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
*(query) >> -(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 <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
qi::bool_[boost::bind(&HandlerT::setClassify, handler, ::_1)];
locs = (-qi::lit('&')) >> 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 <typename Iterator, class HandlerT> struct APIGrammar : qi::grammar<Ite
qi::rule<Iterator> api_call, query;
qi::rule<Iterator, std::string()> 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;
};

View File

@ -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 <osrm/json_container.hpp>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <iostream>
#include "../util/simple_logger.hpp"
namespace osrm
{
namespace tsp
{
inline void PrintDistTable(const std::vector<EdgeWeight> & 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<EdgeWeight> & 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<int> location_ids){
SimpleLogger().Write() << "LOC ORDER";
for (auto x : location_ids) {
SimpleLogger().Write() << x;
}
}
int ReturnDistanceFI(const std::vector<EdgeWeight> & dist_table, std::list<int> 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

View File

@ -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 <boost/test/unit_test.hpp>
#include <boost/test/test_case_template.hpp>
@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
BOOST_AUTO_TEST_SUITE(tsp)
BOOST_AUTO_TEST_SUITE(trip)
// BOOST_AUTO_TEST_CASE(check_distance_computation)
// {