Skip to content

Commit 4f7ddec

Browse files
committed
insert-eject: iterate over nearest insertions only
Not optimal at 10 min (8 instances): c1_10_6: 100 (best: 99, diff: +1) c1_10_7: 98 (best: 97, diff: +1) c1_10_8: 93 (best: 92, diff: +1) c2_10_3: 29 (best: 28, diff: +1) c2_10_6: 30 (best: 29, diff: +1) c2_10_7: 30 (best: 29, diff: +1) c2_10_8: 29 (best: 28, diff: +1) c2_10_9: 29 (best: 28, diff: +1) Not optimal at 60 min (5 instances): c1_10_6: 100 (best: 99, diff: +1) c1_10_8: 93 (best: 92, diff: +1) c2_10_7: 30 (best: 29, diff: +1) c2_10_8: 29 (best: 28, diff: +1) c2_10_9: 29 (best: 28, diff: +1) Not optimal at 300 min (3 instances): c1_10_8: 93 (best: 92, diff: +1) c2_10_8: 29 (best: 28, diff: +1) c2_10_9: 29 (best: 28, diff: +1)
1 parent 176bdb7 commit 4f7ddec

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

src/eama_solver.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,19 @@ insert_eject(struct solution *s)
225225

226226
int64_t p_best = INT64_MAX;
227227
struct modification opt_insertion = modification_new(INSERT, NULL, s->w);
228+
struct modification insertions[MAX_N_CUSTOMERS * 2];
229+
int n_insertions = solution_collect_near_insertions(
230+
s, s->w, options.n_near, insertions, MAX_N_CUSTOMERS * 2);
228231
struct customer *ejection[MAX_N_CUSTOMERS];
229232
int ejection_size = 0;
230233
struct customer *opt_ejection[MAX_N_CUSTOMERS];
231234
int opt_ejection_size = 0;
232235

233236
for (int i = 0; i < s->n_routes; i++) {
234237
struct route *v_route = s->routes[i];
235-
struct customer *v;
236-
/* iterate over all possible insert positions in v_route */
237-
rlist_foreach_entry(v, &v_route->list, in_route) {
238-
if (v == depot_head(v_route))
239-
continue;
240-
struct modification m = modification_new(INSERT, v, s->w);
241-
if (!modification_applicable(m))
238+
for (int j = 0; j < n_insertions; j++) {
239+
struct modification m = insertions[j];
240+
if (m.v->route != v_route)
242241
continue;
243242
modification_apply(m);
244243

@@ -253,8 +252,8 @@ insert_eject(struct solution *s)
253252
ejection, &ejection_size, &p_best);
254253
while(!fiber_is_dead(f)) {
255254
opt_insertion = m;
256-
for (int j = 0; j < ejection_size; j++)
257-
opt_ejection[j] = ejection[j];
255+
for (int k = 0; k < ejection_size; k++)
256+
opt_ejection[k] = ejection[k];
258257
opt_ejection_size = ejection_size;
259258
fiber_call(f);
260259
}

src/solution.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,41 @@ solution_find_optimal_insertion(struct solution *s, struct customer *w,
552552
return opt_modification;
553553
}
554554

555+
int
556+
solution_collect_near_insertions(struct solution *s, struct customer *w,
557+
int n_near, struct modification *mods,
558+
int max_mods)
559+
{
560+
assert(is_ejected(w));
561+
if (!solution_global_initialized)
562+
solution_global_init();
563+
564+
int count = 0;
565+
customer *v;
566+
int limit = MIN(n_near, p.n_customers);
567+
for (int i = 0; i < limit; i++) {
568+
int id = neighbours_sorted[w->id][i];
569+
assert(id != 0);
570+
v = s->meta->idx[id];
571+
struct modification m = modification_new(INSERT, v, w);
572+
if (!modification_applicable(m))
573+
continue;
574+
assert(count < max_mods);
575+
mods[count++] = m;
576+
}
577+
578+
for (int i = 0; i < s->n_routes; i++) {
579+
v = depot_tail(s->routes[i]);
580+
struct modification m = modification_new(INSERT, v, w);
581+
if (!modification_applicable(m))
582+
continue;
583+
assert(count < max_mods);
584+
mods[count++] = m;
585+
}
586+
587+
return count;
588+
}
589+
555590
struct customer *
556591
solution_find_customer_by_id(struct solution *s, int id)
557592
{

src/solution.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ struct modification
9595
solution_find_optimal_insertion(struct solution *s, struct customer *w,
9696
double alpha, double beta);
9797

98+
int
99+
solution_collect_near_insertions(struct solution *s, struct customer *w,
100+
int n_near, struct modification *mods,
101+
int max_mods);
102+
98103
struct customer *
99104
solution_find_customer_by_id(struct solution *s, int id);
100105

0 commit comments

Comments
 (0)