From 3a696e9a2b0d56d5469759da82752732b784068f Mon Sep 17 00:00:00 2001 From: halilsen Date: Wed, 20 Jan 2021 11:55:06 +0100 Subject: [PATCH 1/2] Fix: eliminate negatif infeasible quantities --- test/test_helper.rb | 1 + test/wrapper_test.rb | 11 +++++++++++ wrappers/wrapper.rb | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 61643d608..7133bf4ad 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -194,6 +194,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 6ec5614d9..d00940488 100644 --- a/wrappers/wrapper.rb +++ b/wrappers/wrapper.rb @@ -670,7 +670,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 From d46832131d0c6c5e9a2c8d6692fbcf43653f6f0c Mon Sep 17 00:00:00 2001 From: halilsen Date: Wed, 20 Jan 2021 15:03:32 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6592b6c9f..60f707b01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ ## [Unreleased] +### Added + + +### Changed + + +### Removed + + +### Fixed + +- Infeasibility detection of services with negative quantity [#111](https://github.com/Mapotempo/optimizer-api/pull/111) + ## [v0.1.5] - 2021-01-05 ### Added