Skip to content

Commit

Permalink
set a max value from and to depot to avoid getting unbalanced cluster…
Browse files Browse the repository at this point in the history
…s with kmeans
  • Loading branch information
Pierre Graber committed May 11, 2023
1 parent 3099b9b commit b68c52a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/interpreters/split_clustering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,20 @@ def add_duration_from_and_to_depot(vrp, data_items)
end
log "matrix computed in #{(Time.now - tic).round(2)} seconds"

max_time_from_depot = 0
max_time_to_depot = 0

time_matrix_from_depot.map{ |matrix|
matrix.map{ |time|
((time > max_time_from_depot) && (time != 2147483647)) ? max_time_from_depot = time : nil
}
}
time_matrix_to_depot.map{ |matrix|
matrix.map{ |time|
((time > max_time_to_depot) && (time != 2147483647)) ? max_time_to_depot = time : nil
}
}

v_index = {
from: vrp.vehicles.collect{ |v|
start_loc = v.start_point&.location
Expand All @@ -1488,8 +1502,10 @@ def add_duration_from_and_to_depot(vrp, data_items)
point[4][:duration_from_and_to_depot] = []

vrp.vehicles.each_with_index{ |_vehicle, v_i|
duration_from = time_matrix_from_depot[v_index[:from][v_i]][p_index] if v_index[:from][v_i]
duration_to = time_matrix_to_depot[p_index][v_index[:to][v_i]] if v_index[:to][v_i]
duration_from = [time_matrix_from_depot[v_index[:from][v_i]][p_index], max_time_from_depot * 10].min\
if v_index[:from][v_i]
duration_to = [time_matrix_to_depot[p_index][v_index[:to][v_i]], max_time_to_depot * 10].min if\
v_index[:to][v_i]

# TODO: investigate why division by vehicle.router_options[:speed_multiplier]
# detoriarates the performance of periodic
Expand Down

0 comments on commit b68c52a

Please sign in to comment.