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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::construction::heuristics::InsertionContext;
use crate::solver::RefinementContext;
use std::sync::Arc;
mod local;
pub use self::local::*;
mod recreate;
pub use self::recreate::*;
mod ruin;
pub use self::ruin::*;
mod utils;
pub(crate) use self::utils::*;
mod decompose_search;
pub use self::decompose_search::DecomposeSearch;
mod infeasible_search;
pub use self::infeasible_search::InfeasibleSearch;
mod local_search;
pub use self::local_search::LocalSearch;
mod ruin_recreate;
pub use self::ruin_recreate::RuinAndRecreate;
pub trait Mutation {
fn mutate(&self, refinement_ctx: &RefinementContext, insertion_ctx: &InsertionContext) -> InsertionContext;
}
pub struct WeightedMutation {
mutations: Vec<Arc<dyn Mutation + Send + Sync>>,
weights: Vec<usize>,
}
impl WeightedMutation {
pub fn new(mutations: Vec<Arc<dyn Mutation + Send + Sync>>, weights: Vec<usize>) -> Self {
Self { mutations, weights }
}
}
impl Mutation for WeightedMutation {
fn mutate(&self, refinement_ctx: &RefinementContext, insertion_ctx: &InsertionContext) -> InsertionContext {
let index = insertion_ctx.environment.random.weighted(self.weights.as_slice());
self.mutations[index].mutate(refinement_ctx, insertion_ctx)
}
}