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
use crate::construction::heuristics::InsertionContext;
use crate::models::problem::ProblemObjective;
use crate::solver::search::LocalOperator;
use crate::solver::RefinementContext;
use rosomaxa::prelude::*;
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 HeuristicOperator for LocalSearch {
type Context = RefinementContext;
type Objective = ProblemObjective;
type Solution = InsertionContext;
fn search(&self, heuristic_ctx: &Self::Context, solution: &Self::Solution) -> Self::Solution {
let refinement_ctx = heuristic_ctx;
let insertion_ctx = solution;
if let Some(new_insertion_ctx) = self.operator.explore(refinement_ctx, insertion_ctx) {
new_insertion_ctx
} else {
insertion_ctx.deep_copy()
}
}
}