Skip to content

Commit

Permalink
Merge pull request #186 from fonsecadeline/unavailable_days_for_all_v…
Browse files Browse the repository at this point in the history
…isits

Unavailable days considered for all visits
  • Loading branch information
fab-girard authored May 27, 2021
2 parents 303a6d5 + df822cf commit 2a9eee1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/heuristics/scheduling_heuristic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,6 @@ def compute_costs_for_route(route_data, set = nil)
# quantities are respected
((@same_point_day && @services_data[service_id][:group_capacity].all?{ |need, quantity| quantity <= route_data[:capacity_left][need] }) ||
(!@same_point_day && @services_data[service_id][:capacity].all?{ |need, quantity| quantity <= route_data[:capacity_left][need] })) &&
# service is available at this day
!@services_data[service_id][:raw].unavailable_days.include?(day) &&
(@services_data[service_id][:sticky_vehicles_ids].empty? || @services_data[service_id][:sticky_vehicles_ids].include?(vehicle_id))
}.each{ |service_id|
next if @services_data[service_id][:used_days] && !days_respecting_lapse(service_id, vehicle_id).include?(day)
Expand Down Expand Up @@ -840,7 +838,17 @@ def best_cost_according_to_tws(route_data, service_id, service_data, previous, o
}.compact.min_by{ |cost| cost[:back_to_depot] }
end

def compatible_days(service_id, day)
!@services_data[service_id][:raw].unavailable_days.include?(day)
end

def service_compatible_with_route(service_id, route_data)
compatible_days(service_id, route_data[:global_day_index])
end

def find_best_index(service_id, route_data, first_visit = true)
return nil unless service_compatible_with_route(service_id, route_data)

### find the best position in [route_data] to insert [service] ###
route = route_data[:stops]
service_data = @services_data[service_id]
Expand Down
20 changes: 20 additions & 0 deletions test/lib/heuristics/scheduling_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -899,5 +899,25 @@ def test_scheduling_wiht_unavailable_interval
result = OptimizerWrapper.wrapper_vrp('ortools', { services: { vrp: [:ortools] }}, TestHelper.create(vrp), nil)
assert_equal 5, result[:routes].size
end

def test_unavailable_days_in_scheduling
vrp = VRP.scheduling
vrp[:services].first[:visits_number] = 3
vrp[:services].first[:minimum_lapse] = 2
vrp[:services].first[:maximum_lapse] = 3
vrp[:configuration][:schedule][:range_indices][:end] = 6

[[[], [0, 2, 4]], [[2], [0, 4, 6]]].each{ |unavailable_indices, expectation|
vrp[:services].first[:unavailable_visit_day_indices] = unavailable_indices
result = OptimizerWrapper.wrapper_vrp('ortools', { services: { vrp: [:ortools] }}, TestHelper.create(vrp), nil)
days_with_service =
result[:routes].collect{ |r|
if r[:activities].any?{ |a| a[:original_service_id] == 'service_1' }
r[:vehicle_id].split('_').last.to_i
end
}.compact
assert_equal expectation, days_with_service, 'Service was not planned at expected days'
}
end
end
end

0 comments on commit 2a9eee1

Please sign in to comment.