diff --git a/test/wrapper_test.rb b/test/wrapper_test.rb index b94072d9c..5f168b011 100644 --- a/test/wrapper_test.rb +++ b/test/wrapper_test.rb @@ -3042,6 +3042,23 @@ def test_assert_applicable_for_vroom_if_initial_routes assert_empty OptimizerWrapper.config[:services][:vroom].inapplicable_solve?(vrp) end + def test_assert_can_handle_empty_quantities + problem = VRP.basic + problem[:relations] = [{ + type: :shipment, + linked_ids: ['service_1', 'service_2'] + }] + problem[:units] << { id: 'vol' } + problem[:vehicles].first[:capacities] = [{ unit_id: 'kg', limit: 2 }, { unit_id: 'vol', limit: 1 }] + problem[:services][0][:quantities] = [{ unit_id: 'kg', value: 1 }] + problem[:services][1][:quantities] = [{ unit_id: 'kg', value: -1 }] + problem[:services][2][:quantities] = [{ unit_id: 'vol', value: 1 }] + vrp = TestHelper.create(problem) + + OptimizerWrapper.config[:services][:vroom].inapplicable_solve?(vrp) + OptimizerWrapper.config[:services][:ortools].inapplicable_solve?(vrp) + end + def test_assert_inapplicable_relations problem = VRP.basic problem[:relations] = [{ @@ -3069,6 +3086,8 @@ def test_assert_inapplicable_relations }] vrp = TestHelper.create(problem) + assert_includes OptimizerWrapper.config[:services][:vroom].inapplicable_solve?(vrp), + :assert_no_overall_duration assert_includes OptimizerWrapper.config[:services][:vroom].inapplicable_solve?(vrp), :assert_no_relations_except_simple_shipments refute_includes OptimizerWrapper.config[:services][:ortools].inapplicable_solve?(vrp), diff --git a/wrappers/vroom.rb b/wrappers/vroom.rb index 6ca1a6b80..bc7d6f797 100644 --- a/wrappers/vroom.rb +++ b/wrappers/vroom.rb @@ -62,6 +62,7 @@ def solver_constraints :assert_vehicles_no_late_multiplier_or_single_vehicle, :assert_vehicles_no_overload_multiplier, :assert_vehicles_start_or_end, + :assert_no_overall_duration, # Mission constraints :assert_no_activity_with_position, diff --git a/wrappers/wrapper.rb b/wrappers/wrapper.rb index 1da4ec9c3..7f41d42f0 100644 --- a/wrappers/wrapper.rb +++ b/wrappers/wrapper.rb @@ -147,15 +147,15 @@ def assert_one_sticky_at_most(vrp) def assert_no_relations_except_simple_shipments(vrp) vrp.relations.all?{ |r| - return true if r.linked_ids.empty? && r.linked_vehicle_ids.empty? - return false unless r.type == :shipment && r.linked_ids.size == 2 + next true if r.linked_ids.empty? && r.linked_vehicle_ids.empty? + next false unless r.type == :shipment && r.linked_ids.size == 2 quantities = Hash.new {} vrp.units.each{ |unit| quantities[unit.id] = [] } r.linked_services.first.quantities.each{ |q| quantities[q.unit.id] << q.value } r.linked_services.last.quantities.each{ |q| quantities[q.unit.id] << q.value } quantities.all?{ |_unit, values| - [0, 2].include?(values.size) && values.first >= 0 && values.first == -values.last + values.empty? || (values.size == 2 && values.first >= 0 && values.first == -values.last) } } end