diff --git a/models/vrp.rb b/models/vrp.rb index ba35c1646..a0a66847e 100644 --- a/models/vrp.rb +++ b/models/vrp.rb @@ -728,10 +728,35 @@ def check_configuration(configuration, periodic) check_periodic_consistency(configuration) if periodic end + def max_split_candidate(configuration) + empties_or_fills = @hash[:services].to_a.count{ |service| + service[:quantities].to_a.any?{ |qty| qty[:fill] || qty[:empty] } + } + depot_ids = @hash[:vehicles].flat_map{ |vehicle| [vehicle[:start_point_id], vehicle[:end_point_id]] }.compact.uniq + ship_candidates = @hash[:shipments].to_a.count{ |shipment| + depot_ids.include?(shipment[:pickup][:point_id]) || depot_ids.include?(shipment[:delivery][:point_id]) + } + + configuration[:schedule].nil? && + configuration[:preprocessing][:max_split_size] && + @hash[:vehicles].size > 1 && + @hash[:shipments].to_a.size == ship_candidates && + (ship_candidates + @hash[:services].size - empties_or_fills) > configuration[:preprocessing][:max_split_size] + end + def check_clustering_parameters(configuration) + if @hash[:relations].to_a.any?{ |relation| relation[:type] == 'vehicle_trips' } + if configuration[:preprocessing][:partitions].to_a.size.positive? || + max_split_candidate(configuration) + raise OptimizerWrapper::DiscordantProblemError.new( + 'Clustering is not able to deal with vehicle_trips relation for now' + ) + end + end + return unless configuration[:preprocessing][:partitions]&.any?{ |partition| partition[:entity].to_sym == :work_day - } + } && configuration[:schedule] if @hash[:services].any?{ |s| if configuration[:schedule][:range_indices][:end] <= 6 diff --git a/test/models/vrp_consistency_test.rb b/test/models/vrp_consistency_test.rb index a507ec93a..09664d614 100644 --- a/test/models/vrp_consistency_test.rb +++ b/test/models/vrp_consistency_test.rb @@ -330,5 +330,32 @@ def test_vehicle_trips_with_force_start vrp = TestHelper.create(vrp) end end + + def test_vehicle_trips_uncompatible_with_clustering + vrp = VRP.lat_lon_two_vehicles + vrp[:relations] = [TestHelper.vehicle_trips_relation(vrp)] + vrp[:configuration][:preprocessing] = { partitions: TestHelper.vehicle_and_days_partitions } + assert_raises OptimizerWrapper::DiscordantProblemError do + TestHelper.create(vrp) + end + + vrp[:configuration][:preprocessing] = nil + TestHelper.create(vrp) # this should not raise + + vrp[:configuration][:preprocessing] = { max_split_size: 13 } + TestHelper.create(vrp) # this should not raise + vrp[:shipments] = [{ + id: 'shipment_0', + pickup: { + point_id: 'point_0' + }, + delivery: { + point_id: 'point_1' + } + }] + assert_raises OptimizerWrapper::DiscordantProblemError do + TestHelper.create(vrp) + end + end end end