Skip to content

Commit f95c6b3

Browse files
committed
time windows
1 parent 1f0e3b8 commit f95c6b3

2 files changed

Lines changed: 39 additions & 29 deletions

File tree

‎Samples/REST Services/MIO/mio.html‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,28 +220,36 @@
220220
fleet_data: {
221221
// in this sample we have 4 vehicles,
222222
// 2 vehicles for each depot (we have 2 depots)
223-
vehicle_locations: [[0, 0], [0, 0], [1, 1], [1, 1]], // [start location in array Depot, stop location in array Depot]
224-
vehicle_ids: vehicles.map(vehicle => vehicle.name), // ["CarA", "CarB", "CarC", "CarD"], // the id for each vehicle
223+
vehicle_locations: vehicles.map(vehicle => vehicle.start_end_location_ids), // [start location in array Depot, stop location in array Depot]
224+
vehicle_ids: vehicles.map(vehicle => vehicle.name), // the id for each vehicle
225225
vehicle_types: vehicles.map(vehicle => vehicle.vehicle_type_id), // cost_matrix_data & travel_time_matrix_data data id "1"
226226
capacities: [vehicles.map(vehicle => vehicle.capacity)], // the capacity for each vehicle
227-
//vehicle_time_windows: [[8, 17], [8, 17], [8, 17], [10, 20], [10, 20]], // the time in seconds
228-
//vehicle_break_time_windows: [[[12, 14], [12, 14], [12, 14], [12, 14], [12, 14]]], // the time in seconds
229-
//vehicle_break_durations: [vehicles.map(vehicle => convertHoursToSeconds(vehicle.break_duration))] // the time in seconds
227+
vehicle_time_windows: vehicles.map(vehicle => {
228+
const workingHours = vehicle.working_hours;
229+
return workingHours.map(convertHoursToSeconds);
230+
}), // the time in seconds
231+
vehicle_break_time_windows: [vehicles.map(vehicle => {
232+
const breakHours = vehicle.break_time_window;
233+
return breakHours.map(convertHoursToSeconds);
234+
})], // the time in seconds
235+
vehicle_break_durations: [vehicles.map(vehicle => convertHoursToSeconds(vehicle.break_duration))] // the time in seconds
230236
},
231237
task_data: {
232238
task_locations: Array.from({ length: stopslength }, (_, index) => depotslength + index), // the index in array Stops. the first 2 stops are the depots and does not count as tasks
233239
demand: [stops.map(stop => stop.properties.demand)], // the demand for each task/stop
234-
// task_time_windows: [stops.map(stop => {
235-
// const openingHours = stop.properties.opening_hours;
236-
// return openingHours.map(convertHoursToSeconds);
237-
// })], // the time in seconds
240+
task_time_windows: stops.map(stop => {
241+
const openingHours = stop.properties.opening_hours;
242+
return openingHours.map(convertHoursToSeconds);
243+
}), // the time in seconds
238244
service_times: stops.map(stop => convertHoursToSeconds(stop.properties.service_time)) // the time in seconds
239245
}
240246
},
241247
client_version: "custom"
242248
}
243249
};
244250

251+
console.log(optimizerBody);
252+
245253
// URL for making calls to the NVIDIA optimizer service.
246254
var optimizerUrl = 'https://api.nvcf.nvidia.com/v2/nvcf/exec/functions/4bb2668d-c877-4b89-aabf-1630ed9b32c3/versions/471b94dc-931e-4aa1-99f4-935f5f352737';
247255

@@ -268,6 +276,8 @@
268276
// Get the data from the response.
269277
var data = await optimizerResponse.json();
270278

279+
console.log(data);
280+
271281
// Wait until the optimization is complete
272282
while (data.percentComplete < 100) {
273283

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
[
22
{
3-
"id": 11,
3+
"id": 1,
44
"name": "Car A",
5-
"start_depot_id": 11,
6-
"end_depot_id": 11,
5+
"start_end_location_ids": [ 0, 0 ],
76
"capacity": 75,
87
"vehicle_type_id": 1,
9-
"color": "red",
10-
"break_duration": 0
8+
"break_duration": 0,
9+
"break_time_window": [ 12, 14 ],
10+
"working_hours": [ 8, 17 ]
1111
},
1212
{
13-
"id": 22,
13+
"id": 2,
1414
"name": "Car B",
15-
"start_depot_id": 11,
16-
"end_depot_id": 11,
15+
"start_end_location_ids": [ 0, 0 ],
1716
"capacity": 75,
1817
"vehicle_type_id": 1,
19-
"color": "blue",
20-
"break_duration": 0
18+
"break_duration": 0,
19+
"break_time_window": [ 12, 14 ],
20+
"working_hours": [ 8, 17 ]
2121
},
2222
{
23-
"id": 33,
23+
"id": 3,
2424
"name": "Car C",
25-
"start_depot_id": 22,
26-
"end_depot_id": 22,
25+
"start_end_location_ids": [ 1, 1 ],
2726
"capacity": 75,
2827
"vehicle_type_id": 1,
29-
"color": "green",
30-
"break_duration": 0
28+
"break_duration": 0,
29+
"break_time_window": [ 12, 14 ],
30+
"working_hours": [ 8, 17 ]
3131
},
3232
{
33-
"id": 44,
33+
"id": 4,
3434
"name": "Car D",
35-
"start_depot_id": 22,
36-
"end_depot_id": 22,
35+
"start_end_location_ids": [ 1, 1 ],
3736
"capacity": 75,
3837
"vehicle_type_id": 1,
39-
"color": "yellow",
40-
"break_duration": 0
38+
"break_duration": 0,
39+
"break_time_window": [ 12, 14 ],
40+
"working_hours": [ 8, 17 ]
4141
}
4242
]

0 commit comments

Comments
 (0)