Skip to content

Commit

Permalink
Use raw vehicle in periodic heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsecadeline committed May 28, 2021
1 parent 37c7312 commit c334b48
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 115 deletions.
16 changes: 3 additions & 13 deletions lib/heuristics/concerns/scheduling_data_initialisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,14 @@ module SchedulingDataInitialization
def generate_route_structure(vrp)
vrp.vehicles.each{ |vehicle|
capacity = compute_capacities(vehicle[:capacities], true)
vrp.units.reject{ |unit| capacity.has_key?(unit[:id]) }.each{ |unit| capacity[unit[:id]] = 0.0 }
vrp.units.reject{ |unit| capacity.key?(unit[:id]) }.each{ |unit| capacity[unit[:id]] = 0.0 }
@candidate_routes[vehicle.original_id][vehicle.global_day_index] = {
vehicle: vehicle,
vehicle_id: vehicle.id,
global_day_index: vehicle.global_day_index,
tw_start: (vehicle.timewindow.start < 84600) ? vehicle.timewindow.start : vehicle.timewindow.start - vehicle.global_day_index * 86400,
tw_end: (vehicle.timewindow.end < 84600) ? vehicle.timewindow.end : vehicle.timewindow.end - vehicle.global_day_index * 86400,
start_point_id: vehicle.start_point&.id,
end_point_id: vehicle.end_point&.id,
tw_start: vehicle.timewindow.start % 84600,
tw_end: vehicle.timewindow.end % 84600,
duration: vehicle.duration || (vehicle.timewindow.end - vehicle.timewindow.start),
matrix_id: vehicle.matrix_id,
stops: [],
capacity: capacity,
capacity_left: Marshal.load(Marshal.dump(capacity)),
maximum_ride_time: vehicle.maximum_ride_time,
maximum_ride_distance: vehicle.maximum_ride_distance,
router_dimension: vehicle.router_dimension.to_sym,
cost_fixed: vehicle.cost_fixed,
available_ids: [],
completed: false,
}
Expand Down
16 changes: 10 additions & 6 deletions lib/heuristics/concerns/scheduling_end_phase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ def empty_underfilled

all_empty = false

next if route_data[:stops].sum{ |stop| @services_data[stop[:id]][:raw].exclusion_cost || 0 } >= route_data[:cost_fixed]
next if route_data[:stops].sum{ |stop|
@services_data[stop[:id]][:raw].exclusion_cost.to_f
} >= route_data[:vehicle].cost_fixed

smth_removed = true
locally_removed = route_data[:stops].collect{ |stop|
Expand All @@ -248,7 +250,7 @@ def empty_underfilled
[stop[:id], stop[:number_in_sequence]]
}
route_data[:stops] = []
route_data[:capacity].each{ |unit, qty|
route_data[:vehicle].capacities.each{ |unit, qty|
route_data[:capacity_left][unit] = qty
}
removed += locally_removed
Expand Down Expand Up @@ -345,7 +347,7 @@ def collect_empty_routes
empty_routes << {
vehicle_id: vehicle_id,
day: day,
stores: [route_data[:start_point_id], route_data[:end_point_id]],
stores: [route_data[:vehicle].start_point&.id, route_data[:vehicle].end_point&.id],
time_range: route_data[:tw_end] - route_data[:tw_start]
}
}
Expand Down Expand Up @@ -409,7 +411,9 @@ def generate_new_routes(still_removed)
if insertion_costs.flatten.empty?
keep_inserting = false
empty_routes.delete_if{ |tab| tab[:vehicle_id] == best_route[:vehicle_id] && tab[:day] == best_route[:day] }
if route_data[:stops].empty? || route_data[:stops].sum{ |stop| @services_data[stop[:id]][:raw].exclusion_cost || 0 } < route_data[:cost_fixed]
if route_data[:stops].empty? ||
route_data[:stops].sum{ |stop| @services_data[stop[:id]][:raw].exclusion_cost || 0 } <
route_data[:vehicle].cost_fixed
route_data[:stops] = []
previous_vehicle_filled_info = {
stores: best_route[:stores],
Expand All @@ -420,7 +424,7 @@ def generate_new_routes(still_removed)
route_data[:stops].each{ |stop|
@ids_to_renumber |= [stop[:id]]
still_removed.delete(still_removed.find{ |removed| removed.first == stop[:id] })
@output_tool&.add_single_visit(route_data[:global_day_index], @services_data[stop[:id]][:used_days], stop[:id], @services_data[stop[:id]][:raw].visits_number)
@output_tool&.add_single_visit(route_data[:vehicle].global_day_index, @services_data[stop[:id]][:used_days], stop[:id], @services_data[stop[:id]][:raw].visits_number)
@uninserted.delete(@uninserted.find{ |_id, data| data[:original_id] == stop[:id] }[0])
}
end
Expand All @@ -431,7 +435,7 @@ def generate_new_routes(still_removed)
end
end
else
empty_routes.delete_if{ |tab| tab[:vehicle_id] == best_route[:vehicle_id] && tab[:day] == best_route[:day] }
empty_routes.delete_if{ |tab| tab[:vehicle_id] == best_route[:vehicle].id && tab[:day] == best_route[:day] }
end
end

Expand Down
Loading

0 comments on commit c334b48

Please sign in to comment.