diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a65989f3..3537aee94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +15,15 @@ - Bump OR-Tools v7.8 [#107](https://github.com/Mapotempo/optimizer-api/pull/107) - VROOM were previously always called synchronously, it is now reserved to a set of effective `router_mode` (:car, :truck_medium) within a limit of points (<200). [#107](https://github.com/Mapotempo/optimizer-api/pull/107) +### Removed + + ### Fixed - `unassigned` output were in some cases returning the key `shipment_id` instead of `pickup_shipment_id` and `delivery_shipment_id` [#107](https://github.com/Mapotempo/optimizer-api/pull/107) - Uniformize route content and always return `original_vehicle_id` [#107](https://github.com/Mapotempo/optimizer-api/pull/107) +- Infeasibility detection of services with negative quantity [#111](https://github.com/Mapotempo/optimizer-api/pull/111) + ## [v0.1.5] - 2021-01-05 diff --git a/test/test_helper.rb b/test/test_helper.rb index 664cc0de3..17c05bc34 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -202,6 +202,7 @@ def self.vehicle_and_days_partitions module VRP # rubocop: disable Metrics/ModuleLength, Style/CommentedKeyword def self.toy { + units: [{ id: 'u1' }], points: [{ id: 'p1', location: { diff --git a/test/wrapper_test.rb b/test/wrapper_test.rb index fc9299ccd..a45ea6b3c 100644 --- a/test/wrapper_test.rb +++ b/test/wrapper_test.rb @@ -2820,6 +2820,17 @@ def test_impossible_service_too_long assert_empty OptimizerWrapper.config[:services][:demo].detect_unfeasible_services(TestHelper.create(vrp)) end + def test_impossible_service_with_negative_quantity + vrp = VRP.toy + vrp[:services].first[:quantities] = [{ unit_id: 'u1', value: -5 }] + vrp[:vehicles].first[:capacities] = [{ unit_id: 'u1', limit: 5 }] + assert_empty OptimizerWrapper.config[:services][:demo].detect_unfeasible_services(TestHelper.create(vrp)) + + vrp[:services].first[:quantities].first[:value] = -6 + result = OptimizerWrapper.config[:services][:demo].detect_unfeasible_services(TestHelper.create(vrp)) + assert_equal(1, result.count{ |un| un[:reason] == 'Service quantity greater than any vehicle capacity' }) + end + def test_feasible_if_tardiness_allowed vrp = VRP.basic diff --git a/wrappers/wrapper.rb b/wrappers/wrapper.rb index bc1acc53e..d81aa4d27 100644 --- a/wrappers/wrapper.rb +++ b/wrappers/wrapper.rb @@ -750,7 +750,7 @@ def detect_unfeasible_services(vrp) vrp.services.each{ |service| service.quantities.each{ |qty| - if vehicle_max_capacities[qty.unit_id] && qty.value && vehicle_max_capacities[qty.unit_id] < qty.value + if vehicle_max_capacities[qty.unit_id] && qty.value && vehicle_max_capacities[qty.unit_id] < qty.value.abs add_unassigned(unfeasible, vrp, service, 'Service quantity greater than any vehicle capacity') break end