Skip to content

Commit

Permalink
clustering not allowed with vehicle_trips
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsecadeline committed Jan 29, 2021
1 parent 34d2538 commit 651a1a7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
27 changes: 26 additions & 1 deletion models/vrp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions test/models/vrp_consistency_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 651a1a7

Please sign in to comment.