Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: eliminate negatif infeasible quantities #111

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
11 changes: 11 additions & 0 deletions test/wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion wrappers/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down