Skip to content

Commit

Permalink
Routes and cluster_threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Braktar committed Mar 23, 2022
1 parent c9d798c commit 907b4a2
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 124 deletions.
20 changes: 20 additions & 0 deletions optimizer_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,26 @@ def self.zip_cluster(vrp, cluster_threshold, force_cluster)
new_services = Array.new(new_size)
clusterer.clusters.each_with_index do |cluster, i|
new_services[i] = vrp.services[cluster.data_items[0][0]]
cluster_ids = cluster.data_items.map{ |arr| vrp.services[arr[0]].id }
route_index = vrp.routes.index{ |route| route.mission_ids & cluster_ids }
if route_index
ref_id = vrp.routes[route_index].mission_ids.find{ |mission_id|
cluster_ids.include?(mission_id)
}
vrp.routes.each{ |route|
route.mission_ids.delete_if{ |mission_id|
cluster_ids.include?(mission_id) unless mission_id == ref_id
}
}
vrp.routes[route_index].mission_ids.map!{ |mission_id|
if cluster_ids.include?(mission_id)
new_services[i].id
else
mission_id
end
}
end

new_services[i].activity.duration =
cluster.data_items.map{ |di| vrp.services[di[0]].activity.duration }.reduce(&:+)
next unless force_cluster
Expand Down
155 changes: 31 additions & 124 deletions test/fixtures/pud_initial_routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -656,10 +656,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_1",
Expand All @@ -677,10 +674,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_2",
Expand All @@ -698,10 +692,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_3",
Expand All @@ -719,10 +710,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_4",
Expand All @@ -740,10 +728,7 @@
"point_id": "point_2",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_5",
Expand All @@ -761,10 +746,7 @@
"point_id": "point_2",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_6",
Expand All @@ -782,10 +764,7 @@
"point_id": "point_0",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_7",
Expand All @@ -803,10 +782,7 @@
"point_id": "point_0",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_8",
Expand All @@ -824,10 +800,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_9",
Expand All @@ -845,10 +818,7 @@
"point_id": "point_0",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_10",
Expand All @@ -866,10 +836,7 @@
"point_id": "point_2",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_11",
Expand All @@ -887,10 +854,7 @@
"point_id": "point_2",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_12",
Expand All @@ -908,10 +872,7 @@
"point_id": "point_2",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_13",
Expand All @@ -929,10 +890,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_14",
Expand All @@ -950,10 +908,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_15",
Expand All @@ -971,10 +926,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_16",
Expand All @@ -992,10 +944,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_17",
Expand All @@ -1013,10 +962,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_18",
Expand All @@ -1034,10 +980,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_19",
Expand All @@ -1055,10 +998,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_20",
Expand All @@ -1076,10 +1016,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_21",
Expand All @@ -1097,10 +1034,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_22",
Expand All @@ -1118,10 +1052,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_23",
Expand All @@ -1139,10 +1070,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_24",
Expand All @@ -1160,10 +1088,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_25",
Expand All @@ -1181,10 +1106,7 @@
"point_id": "point_13",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_26",
Expand All @@ -1202,10 +1124,7 @@
"point_id": "point_6",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_27",
Expand All @@ -1223,10 +1142,7 @@
"point_id": "point_6",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_28",
Expand All @@ -1244,10 +1160,7 @@
"point_id": "point_6",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_29",
Expand All @@ -1265,10 +1178,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
},
{
"id": "shipment_30",
Expand All @@ -1286,10 +1196,7 @@
"point_id": "point_7",
"setup_duration": 2700
},
"maximum_inroute_duration": 6300,
"skills": [
"external"
]
"maximum_inroute_duration": 6300
}
],
"relations": [],
Expand Down
Loading

0 comments on commit 907b4a2

Please sign in to comment.