Skip to content

Commit

Permalink
[OA] multi-trips with lapses
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsecadeline committed Feb 12, 2021
1 parent d25659d commit 58c7607
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Corresponding vehicle_id is returned within each service's skills if problem is partitioned with vehicle entity [#110](https://github.com/Mapotempo/optimizer-api/pull/110)
- Implementation of vehicle_trips relation : these vehicles' routes are successive [#123] (https://github.com/Mapotempo/optimizer-api/pull/123)
- Implementation of lapses within vehicle_trips relations : minimum duration between two consecutive trips [#123] (https://github.com/Mapotempo/optimizer-api/pull/123)

### Changed

Expand Down
5 changes: 4 additions & 1 deletion api/v01/entities/vrp_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ module VrpMisc
desc: 'Relations allow to define constraints explicitly between activities and/or vehicles.
It could be the following types: same_route, sequence, order, minimum_day_lapse, maximum_day_lapse,
shipment, meetup, minimum_duration_lapse, maximum_duration_lapse, vehicle_trips')
optional(:lapse, type: Integer, desc: 'Only used for relations implying a duration constraint : minimum/maximum day lapse, vehicle group durations...')
optional(:lapse, type: Integer, desc:
'Only used for relations implying a duration constraint.
Lapse expressed in days for minimum/maximum day lapse,
in seconds for vehicle_group_durations or 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')
Expand Down
14 changes: 14 additions & 0 deletions test/lib/interpreters/multi_trips_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,18 @@ def test_solve_vehicles_trips_duration
assert_operator routes_end[next_one - 1], :<=, routes_start[next_one]
}
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
2 changes: 2 additions & 0 deletions wrappers/ortools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ def solve(vrp, job, thread_proc = nil, &block)
}.uniq
next if current_linked_ids.empty? && current_linked_vehicles.empty?

relation.lapse ||= 0 if relation.type == 'vehicle_trips'

OrtoolsVrp::Relation.new(
type: relation.type.to_s,
linked_ids: current_linked_ids,
Expand Down

0 comments on commit 58c7607

Please sign in to comment.