Skip to content

Commit 3f2118f

Browse files
committed
Compute all insertions at the start and update modified routes
1 parent 75ffb3a commit 3f2118f

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

src/algorithms/local_search/local_search.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,29 +316,31 @@ void LocalSearch<Route,
316316
double regret_coeff) {
317317

318318
bool job_added;
319+
320+
std::vector<std::vector<RouteInsertion>> route_job_insertions;
319321

320-
do {
321-
std::vector<std::vector<RouteInsertion>> route_job_insertions;
322-
323-
for (std::size_t i = 0; i < routes.size(); ++i) {
322+
for (std::size_t i = 0; i < routes.size(); ++i) {
324323
//TODO: tweak such that the vectors don't include all jobs
325324
route_job_insertions.push_back(std::vector<RouteInsertion>(_input.jobs.size(), empty_insert));
326325

327326
const auto v = routes[i];
328327
for (const auto j : _sol_state.unassigned) {
329-
const auto& current_job = _input.jobs[j];
330-
if (current_job.type == JOB_TYPE::DELIVERY) {
331-
continue;
332-
}
333-
route_job_insertions[i][j] = compute_best_insertion(_input, j, v, _sol[v]);
328+
const auto& current_job = _input.jobs[j];
329+
if (current_job.type == JOB_TYPE::DELIVERY) {
330+
continue;
331+
}
332+
route_job_insertions[i][j] = compute_best_insertion(_input, j, v, _sol[v]);
334333
}
335-
}
334+
}
335+
336+
do {
336337

337338
Priority best_priority = 0;
338339
RouteInsertion best_insertion = empty_insert;
339340
double best_cost = std::numeric_limits<double>::max();
340341
Index best_job_rank = 0;
341342
Index best_route = 0;
343+
std::size_t best_route_idx = 0;
342344

343345
for (const auto j : _sol_state.unassigned) {
344346
const auto& current_job = _input.jobs[j];
@@ -388,6 +390,7 @@ void LocalSearch<Route,
388390
best_route = routes[i];
389391
best_insertion = route_job_insertions[i][j];
390392
best_cost = eval;
393+
best_route_idx = i;
391394
}
392395
}
393396
}
@@ -419,7 +422,14 @@ void LocalSearch<Route,
419422
_sol_state.unassigned.end());
420423
_sol_state.unassigned.erase(best_job_rank + 1);
421424
}
422-
425+
//Update route/job insertions for best_route
426+
for (const auto j : _sol_state.unassigned) {
427+
const auto& current_job = _input.jobs[j];
428+
if (current_job.type == JOB_TYPE::DELIVERY) {
429+
continue;
430+
}
431+
route_job_insertions[best_route_idx][j] = compute_best_insertion(_input, j, best_route, _sol[best_route]);
432+
}
423433
#ifndef NDEBUG
424434
// Update cost after addition.
425435
_sol_state.update_route_cost(_sol[best_route].route, best_route);

0 commit comments

Comments
 (0)