1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use super::*;
use crate::construction::heuristics::InsertionContext;
use crate::solver::RefinementContext;
pub struct RandomJobRemoval {
limit: JobRemovalLimit,
}
impl RandomJobRemoval {
pub fn new(limit: JobRemovalLimit) -> Self {
Self { limit }
}
}
impl Default for RandomJobRemoval {
fn default() -> Self {
Self::new(JobRemovalLimit::default())
}
}
impl Ruin for RandomJobRemoval {
fn run(&self, _refinement_ctx: &RefinementContext, mut insertion_ctx: InsertionContext) -> InsertionContext {
if insertion_ctx.solution.routes.is_empty() {
return insertion_ctx;
}
let affected = get_removal_chunk_size(&insertion_ctx, &self.limit);
(0..affected).for_each(|_| {
let solution = &mut insertion_ctx.solution;
if let Some((route_index, job)) = select_seed_job(&solution.routes, &insertion_ctx.random) {
if !solution.locked.contains(&job) {
solution.routes.get_mut(route_index).unwrap().route_mut().tour.remove(&job);
solution.required.push(job);
}
}
});
insertion_ctx
}
}