From 4eb716737c41721bcc16ba633f8487b97b2d9d39 Mon Sep 17 00:00:00 2001 From: fonsecadeline Date: Tue, 2 Feb 2021 09:31:38 +0100 Subject: [PATCH] [OA] multi-trips with lapses --- CHANGELOG.md | 2 +- api/v01/entities/vrp_input.rb | 2 +- test/lib/interpreters/multi_trips_test.rb | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 430c35939..ae85fffe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Added -- Implementation of `vehicle_trips` relation : these vehicles' routes are successive [#123] (https://github.com/Mapotempo/optimizer-api/pull/123) +- Implementation of `vehicle_trips` relation: the routes can be successive or with a minimum duration `lapse` in between [#123] (https://github.com/Mapotempo/optimizer-api/pull/123) ### Changed diff --git a/api/v01/entities/vrp_input.rb b/api/v01/entities/vrp_input.rb index 555d8e1c3..e9ae55a75 100644 --- a/api/v01/entities/vrp_input.rb +++ b/api/v01/entities/vrp_input.rb @@ -261,7 +261,7 @@ module VrpMisc shipment, meetup, minimum_duration_lapse, maximum_duration_lapse, vehicle_trips') optional(:lapse, type: Integer, values: ->(v) { v >= 0 }, - desc: 'Only used for relations implying a duration constraint : minimum/maximum day lapse, vehicle group durations...') + desc: 'Only used for relations implying a duration constraint. Lapse expressed in days for minimum/maximum day lapse, in seconds for vehicle_group_durations and vehicle_trips.') optional(:linked_ids, type: Array[String], allow_blank: false, desc: 'List of activities involved in the relation', coerce_with: ->(val) { val.is_a?(String) ? val.split(/,/) : val }) optional(:linked_vehicle_ids, type: Array[String], allow_blank: false, desc: 'List of vehicles involved in the relation', coerce_with: ->(val) { val.is_a?(String) ? val.split(/,/) : val }) optional(:periodicity, type: Integer, documentation: { hidden: true }, desc: 'In the case of planning optimization, number of weeks/months to consider at the same time/in each relation : vehicle group duration on weeks/months') diff --git a/test/lib/interpreters/multi_trips_test.rb b/test/lib/interpreters/multi_trips_test.rb index 35a578acc..2330d4c77 100644 --- a/test/lib/interpreters/multi_trips_test.rb +++ b/test/lib/interpreters/multi_trips_test.rb @@ -107,4 +107,18 @@ def test_vehicle_trips_with_lapse_0 second_route = result[:routes].find{ |r| r[:vehicle_id] == 'vehicle_1' } assert_operator first_route[:end_time], :<=, second_route[:start_time] end + + def test_lapse_between_trips + vrp = VRP.lat_lon_two_vehicles + # ensure one vehicle only is not enough : + vrp[:vehicles].each{ |vehicle| vehicle[:distance] = 100000 } + vrp[:relations] = [TestHelper.vehicle_trips_relation(vrp)] + + vrp[:relations].first[:lapse] = 3600 + result = OptimizerWrapper.wrapper_vrp('demo', { services: { vrp: [:ortools] }}, TestHelper.create(vrp), nil) + assert(result[:routes].all?{ |route| route[:activities].size > 2 }) + first_route_end = result[:routes][0][:activities].last[:begin_time] + last_route_start = result[:routes][1][:activities].first[:begin_time] + assert_operator first_route_end + 3600, :<=, last_route_start + end end