Skip to content

Commit b68c52a

Browse files
author
Pierre Graber
committed
set a max value from and to depot to avoid getting unbalanced clusters with kmeans
1 parent 3099b9b commit b68c52a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/interpreters/split_clustering.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,20 @@ def add_duration_from_and_to_depot(vrp, data_items)
14731473
end
14741474
log "matrix computed in #{(Time.now - tic).round(2)} seconds"
14751475

1476+
max_time_from_depot = 0
1477+
max_time_to_depot = 0
1478+
1479+
time_matrix_from_depot.map{ |matrix|
1480+
matrix.map{ |time|
1481+
((time > max_time_from_depot) && (time != 2147483647)) ? max_time_from_depot = time : nil
1482+
}
1483+
}
1484+
time_matrix_to_depot.map{ |matrix|
1485+
matrix.map{ |time|
1486+
((time > max_time_to_depot) && (time != 2147483647)) ? max_time_to_depot = time : nil
1487+
}
1488+
}
1489+
14761490
v_index = {
14771491
from: vrp.vehicles.collect{ |v|
14781492
start_loc = v.start_point&.location
@@ -1488,8 +1502,10 @@ def add_duration_from_and_to_depot(vrp, data_items)
14881502
point[4][:duration_from_and_to_depot] = []
14891503

14901504
vrp.vehicles.each_with_index{ |_vehicle, v_i|
1491-
duration_from = time_matrix_from_depot[v_index[:from][v_i]][p_index] if v_index[:from][v_i]
1492-
duration_to = time_matrix_to_depot[p_index][v_index[:to][v_i]] if v_index[:to][v_i]
1505+
duration_from = [time_matrix_from_depot[v_index[:from][v_i]][p_index], max_time_from_depot * 10].min\
1506+
if v_index[:from][v_i]
1507+
duration_to = [time_matrix_to_depot[p_index][v_index[:to][v_i]], max_time_to_depot * 10].min if\
1508+
v_index[:to][v_i]
14931509

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

0 commit comments

Comments
 (0)