From 0abd32fca3939437830f26a0d43a00d06d8427e7 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Thu, 22 Sep 2016 12:27:55 +0200 Subject: [PATCH] prefer first result --- features/step_definitions/trip.js | 16 ++++++++++++++-- features/testbot/trip.feature | 16 +++++++++------- include/engine/trip/trip_brute_force.hpp | 8 +++++--- include/engine/trip/trip_farthest_insertion.hpp | 2 +- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/features/step_definitions/trip.js b/features/step_definitions/trip.js index 57ce0795f..8de1fe7eb 100644 --- a/features/step_definitions/trip.js +++ b/features/step_definitions/trip.js @@ -1,6 +1,10 @@ var util = require('util'); module.exports = function () { + function add(a, b) { + return a + b; + } + this.When(/^I plan a trip I should get$/, (table, callback) => { var got; @@ -43,6 +47,7 @@ module.exports = function () { } var subTrips; + var trip_durations; if (res.statusCode === 200) { if (headers.has('trips')) { subTrips = json.trips.filter(t => !!t).map(t => t.legs).map(tl => Array.prototype.concat.apply([], tl.map((sl, i) => { @@ -52,6 +57,12 @@ module.exports = function () { return toAdd; }))); } + if(headers.has('durations')) { + var all_durations = json.trips.filter(t => !!t).map(t => t.legs).map(tl => Array.prototype.concat.apply([], tl.map(sl => { + return sl.duration; + }))); + trip_durations = all_durations.map( a => a.reduce(add, 0)); + } } var ok = true, @@ -62,7 +73,6 @@ module.exports = function () { if (si >= subTrips.length) { ok = false; } else { - ok = false; // TODO: Check all rotations of the round trip for (var ni=0; ni BruteForceTrip(const NodeIDIterator start, const auto component_size = std::distance(start, end); std::vector perm(start, end); - std::vector route; - route.reserve(component_size); + std::vector route = perm; EdgeWeight min_route_dist = INVALID_EDGE_WEIGHT; @@ -68,7 +67,10 @@ std::vector BruteForceTrip(const NodeIDIterator start, do { const auto new_distance = ReturnDistance(dist_table, perm, min_route_dist, component_size); - if (new_distance <= min_route_dist) + // we can use `<` instead of `<=` here, since all distances are `!=` INVALID_EDGE_WEIGHT + // In case we really sum up to invalid edge weight for all permutations, keeping the very + // first one is fine too. + if (new_distance < min_route_dist) { min_route_dist = new_distance; route = perm; diff --git a/include/engine/trip/trip_farthest_insertion.hpp b/include/engine/trip/trip_farthest_insertion.hpp index 038386a3b..b0a6fc427 100644 --- a/include/engine/trip/trip_farthest_insertion.hpp +++ b/include/engine/trip/trip_farthest_insertion.hpp @@ -119,7 +119,7 @@ std::vector FindRoute(const std::size_t &number_of_locations, // add the location to the current trip such that it results in the shortest total // tour - if (insert_candidate.first >= farthest_distance) + if (insert_candidate.first > farthest_distance) { farthest_distance = insert_candidate.first; next_node = *i;