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
use crate::construction::heuristics::InsertionContext;
use crate::solver::mutation::{LocalOperator, Mutation};
use crate::solver::RefinementContext;
use std::sync::Arc;
pub struct LocalSearch {
operator: Arc<dyn LocalOperator + Send + Sync>,
}
impl LocalSearch {
pub fn new(operator: Arc<dyn LocalOperator + Send + Sync>) -> Self {
Self { operator }
}
}
impl Mutation for LocalSearch {
fn mutate(&self, refinement_ctx: &RefinementContext, insertion_ctx: &InsertionContext) -> InsertionContext {
if let Some(new_insertion_ctx) = self.operator.explore(refinement_ctx, insertion_ctx) {
new_insertion_ctx
} else {
insertion_ctx.deep_copy()
}
}
}