Skip to content

Commit b0b719a

Browse files
authored
Fix TSP when order locations are set (#503)
This PR fixes uninitialized depot pred/succ when order locations are set. There was also an issue when computing the distance cost with the exclusive scan for the order location case. We are now using the correct number of nodes for both cases. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Simplified internal route copying mechanism by removing explicit parameters. * Adjusted sliding TSP local search algorithm to consider a different set of orders during optimization. * Modified memory allocation strategy for routing computations. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 282c52b commit b0b719a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

cpp/src/routing/local_search/sliding_tsp.cu

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ __global__ void execute_sliding_moves_tsp(
275275
s_route.copy_from(route);
276276
__syncthreads();
277277

278-
s_route.copy_to_tsp_route(sol.problem.order_info.depot_included);
278+
s_route.copy_to_tsp_route();
279279

280280
__shared__ i_t sh_overlaps;
281281

@@ -471,7 +471,7 @@ void compute_cumulative_distances(solution_t<i_t, f_t, REQUEST>& sol,
471471
n_temp_storage_bytes,
472472
distances_ptr,
473473
distances_ptr,
474-
n_nodes + 1,
474+
n_nodes + 2,
475475
sol.sol_handle->get_stream());
476476
477477
if (n_temp_storage_bytes > 0) {
@@ -484,7 +484,7 @@ void compute_cumulative_distances(solution_t<i_t, f_t, REQUEST>& sol,
484484
temp_storage_bytes,
485485
distances_ptr,
486486
distances_ptr,
487-
n_nodes + 1,
487+
n_nodes + 2,
488488
sol.sol_handle->get_stream());
489489
}
490490
@@ -504,7 +504,7 @@ bool local_search_t<i_t, f_t, REQUEST>::perform_sliding_tsp(
504504
sol.compute_max_active();
505505
moved_regions_.resize(sol.get_n_routes() * sol.get_max_active_nodes_for_all_routes(),
506506
sol.sol_handle->get_stream());
507-
auto n_nodes = sol.get_num_orders();
507+
auto n_nodes = sol.problem_ptr->order_info.get_num_depot_excluded_orders();
508508
size_t temp_storage_bytes = 0;
509509
resize_temp_storage<i_t, f_t, REQUEST>(sol, move_candidates, n_nodes, temp_storage_bytes);
510510

cpp/src/routing/route/route.cuh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,11 @@ class route_t {
245245
return get_node(*n_nodes).time_dim.forward_feasible(this->vehicle_info());
246246
}
247247

248-
DI void copy_to_tsp_route(bool depot_included)
248+
DI void copy_to_tsp_route()
249249
{
250250
dimensions.requests.tsp_requests.start = get_node(0).node_info();
251251
dimensions.requests.tsp_requests.end = get_node(*n_nodes).node_info();
252+
252253
for (i_t tid = threadIdx.x; tid < *n_nodes; tid += blockDim.x) {
253254
if (get_node(tid).node_info().is_depot()) { continue; }
254255
dimensions.requests.tsp_requests.pred[get_node(tid).node_info().node()] =
@@ -257,10 +258,10 @@ class route_t {
257258
get_node(tid + 1).node_info();
258259
}
259260

260-
if (depot_included) {
261-
dimensions.requests.tsp_requests.pred[0] = get_node(*n_nodes - 1).node_info();
262-
dimensions.requests.tsp_requests.succ[0] = get_node(1).node_info();
263-
}
261+
dimensions.requests.tsp_requests.pred[dimensions.requests.tsp_requests.end.node()] =
262+
get_node(*n_nodes - 1).node_info();
263+
dimensions.requests.tsp_requests.succ[dimensions.requests.tsp_requests.start.node()] =
264+
get_node(1).node_info();
264265
}
265266

266267
// insert a single node to the route

0 commit comments

Comments
 (0)