Skip to main content

vrp_core/solver/search/recreate/
recreate_with_perturbation.rs

1use crate::construction::heuristics::InsertionContext;
2use crate::construction::heuristics::*;
3use crate::solver::search::recreate::Recreate;
4use crate::solver::search::ConfigurableRecreate;
5use crate::solver::RefinementContext;
6use rosomaxa::prelude::{Noise, Random};
7use std::sync::Arc;
8
9/// A recreate method which perturbs the cost by a factor to introduce randomization.
10pub struct RecreateWithPerturbation {
11    recreate: ConfigurableRecreate,
12}
13
14impl RecreateWithPerturbation {
15    /// Creates a new instance of `RecreateWithPerturbation`.
16    pub fn new(noise: Noise, random: Arc<dyn Random>) -> Self {
17        Self {
18            recreate: ConfigurableRecreate::new(
19                Box::<AllJobSelector>::default(),
20                Box::<AllRouteSelector>::default(),
21                LegSelection::Stochastic(random.clone()),
22                ResultSelection::Concrete(Box::new(NoiseResultSelector::new(noise))),
23                Default::default(),
24            ),
25        }
26    }
27
28    /// Creates a new instance of `RecreateWithPerturbation` with default values.
29    pub fn new_with_defaults(random: Arc<dyn Random>) -> Self {
30        Self::new(Noise::new_with_ratio(0.05, (-0.25, 0.25), random.clone()), random)
31    }
32}
33
34impl Recreate for RecreateWithPerturbation {
35    fn run(&self, refinement_ctx: &RefinementContext, insertion_ctx: InsertionContext) -> InsertionContext {
36        self.recreate.run(refinement_ctx, insertion_ctx)
37    }
38}