diff --git a/rosomaxa/src/algorithms/gsom/network.rs b/rosomaxa/src/algorithms/gsom/network.rs index 5378de0c4..3dd770c78 100644 --- a/rosomaxa/src/algorithms/gsom/network.rs +++ b/rosomaxa/src/algorithms/gsom/network.rs @@ -34,7 +34,7 @@ where min_max_weights: MinMaxWeights, nodes: NodeHashMap, storage_factory: F, - random: Arc, + random: Arc, } /// GSOM network configuration. @@ -61,12 +61,7 @@ where F: StorageFactory, { /// Creates a new instance of `Network`. - pub fn new( - roots: [I; 4], - config: NetworkConfig, - random: Arc, - storage_factory: F, - ) -> Self { + pub fn new(roots: [I; 4], config: NetworkConfig, random: Arc, storage_factory: F) -> Self { let dimension = roots[0].weights().len(); assert!(roots.iter().all(|r| r.weights().len() == dimension)); diff --git a/rosomaxa/src/evolution/config.rs b/rosomaxa/src/evolution/config.rs index 6149e2586..caf45b0ee 100644 --- a/rosomaxa/src/evolution/config.rs +++ b/rosomaxa/src/evolution/config.rs @@ -238,8 +238,8 @@ where max_time: Option, min_cv: Option<(String, usize, f64, bool, K)>, target_proximity: Option<(Vec, f64)>, - ) -> Result + Send + Sync>, GenericError> { - let terminations: Vec + Send + Sync>> = match ( + ) -> Result>, GenericError> { + let terminations: Vec>> = match ( max_generations, max_time, &min_cv, @@ -250,7 +250,7 @@ where vec![Box::new(MaxGeneration::new(3000)), Box::new(MaxTime::new(300.))] } _ => { - let mut terminations: Vec + Send + Sync>> = vec![]; + let mut terminations: Vec>> = vec![]; if let Some(limit) = max_generations { (logger)(format!("configured to use max-generations: {limit}").as_str()); @@ -270,16 +270,15 @@ where .as_str(), ); - let variation: Box + Send + Sync> = - match interval_type.as_str() { - "sample" => { - Box::new(MinVariation::::new_with_sample(value, threshold, is_global, key)) - } - "period" => { - Box::new(MinVariation::::new_with_period(value, threshold, is_global, key)) - } - _ => return Err(format!("unknown variation interval type: {interval_type}").into()), - }; + let variation: Box> = match interval_type.as_str() { + "sample" => { + Box::new(MinVariation::::new_with_sample(value, threshold, is_global, key)) + } + "period" => { + Box::new(MinVariation::::new_with_period(value, threshold, is_global, key)) + } + _ => return Err(format!("unknown variation interval type: {interval_type}").into()), + }; terminations.push(variation) } diff --git a/rosomaxa/src/example.rs b/rosomaxa/src/example.rs index d89e32530..b06db2a4e 100644 --- a/rosomaxa/src/example.rs +++ b/rosomaxa/src/example.rs @@ -138,7 +138,7 @@ impl HeuristicObjective for VectorObjective { } impl Shuffled for VectorObjective { - fn get_shuffled(&self, _: &(dyn Random + Send + Sync)) -> Self { + fn get_shuffled(&self, _: &(dyn Random)) -> Self { self.clone() } } diff --git a/rosomaxa/src/hyper/dynamic_selective.rs b/rosomaxa/src/hyper/dynamic_selective.rs index fe1cf390d..849bf3625 100644 --- a/rosomaxa/src/hyper/dynamic_selective.rs +++ b/rosomaxa/src/hyper/dynamic_selective.rs @@ -187,7 +187,7 @@ where struct SearchAgent<'a, C, O, S> { slot_machines: HashMap>, tracker: HeuristicTracker, - random: Arc, + random: Arc, } impl<'a, C, O, S> SearchAgent<'a, C, O, S> diff --git a/rosomaxa/src/lib.rs b/rosomaxa/src/lib.rs index b837c48e7..533ec0c76 100644 --- a/rosomaxa/src/lib.rs +++ b/rosomaxa/src/lib.rs @@ -296,7 +296,7 @@ pub fn get_default_population( objective: Arc, environment: Arc, selection_size: usize, -) -> Box + Send + Sync> +) -> Box> where O: HeuristicObjective + Shuffled + 'static, S: HeuristicSolution + RosomaxaWeighted + 'static, diff --git a/rosomaxa/src/population/elitism.rs b/rosomaxa/src/population/elitism.rs index 21be61b8f..7f94d3133 100644 --- a/rosomaxa/src/population/elitism.rs +++ b/rosomaxa/src/population/elitism.rs @@ -26,7 +26,7 @@ where S: HeuristicSolution, { objective: Arc, - random: Arc, + random: Arc, selection_size: usize, max_population_size: usize, individuals: Vec, @@ -39,7 +39,7 @@ where /// Provides way to get a new objective by shuffling existing one. pub trait Shuffled { /// Returns a new objective, potentially shuffled. - fn get_shuffled(&self, random: &(dyn Random + Send + Sync)) -> Self; + fn get_shuffled(&self, random: &(dyn Random)) -> Self; } impl HeuristicPopulation for Elitism @@ -113,12 +113,7 @@ where S: HeuristicSolution, { /// Creates a new instance of `Elitism`. - pub fn new( - objective: Arc, - random: Arc, - max_population_size: usize, - selection_size: usize, - ) -> Self { + pub fn new(objective: Arc, random: Arc, max_population_size: usize, selection_size: usize) -> Self { Self::new_with_dedup( objective, random, @@ -147,7 +142,7 @@ where /// Creates a new instance of `Elitism` with custom deduplication function. pub fn new_with_dedup( objective: Arc, - random: Arc, + random: Arc, max_population_size: usize, selection_size: usize, dedup_fn: DedupFn, diff --git a/rosomaxa/src/population/rosomaxa.rs b/rosomaxa/src/population/rosomaxa.rs index 8fe2caeba..e5a81eb86 100644 --- a/rosomaxa/src/population/rosomaxa.rs +++ b/rosomaxa/src/population/rosomaxa.rs @@ -338,11 +338,7 @@ where network.smooth(1); } - fn fill_populations( - network: &IndividualNetwork, - coordinates: &mut Vec, - random: &(dyn Random + Send + Sync), - ) { + fn fill_populations(network: &IndividualNetwork, coordinates: &mut Vec, random: &(dyn Random)) { coordinates.clear(); coordinates.extend(network.iter().filter_map(|(coordinate, node)| { if node.storage.population.size() > 0 { @@ -455,7 +451,7 @@ where S: HeuristicSolution + RosomaxaWeighted, { node_size: usize, - random: Arc, + random: Arc, objective: Arc, } diff --git a/rosomaxa/src/termination/min_variation.rs b/rosomaxa/src/termination/min_variation.rs index 87ed831cb..af87f9a08 100644 --- a/rosomaxa/src/termination/min_variation.rs +++ b/rosomaxa/src/termination/min_variation.rs @@ -145,7 +145,7 @@ where C: HeuristicContext + Stateful, O: HeuristicObjective, S: HeuristicSolution, - K: Hash + Eq + Clone, + K: Hash + Eq + Clone + Send + Sync, { type Context = C; type Objective = O; diff --git a/rosomaxa/src/termination/mod.rs b/rosomaxa/src/termination/mod.rs index c17a52bd2..e9d8f044a 100644 --- a/rosomaxa/src/termination/mod.rs +++ b/rosomaxa/src/termination/mod.rs @@ -4,7 +4,7 @@ use crate::prelude::*; /// A trait which specifies criteria when metaheuristic should stop searching for improved solution. -pub trait Termination { +pub trait Termination: Send + Sync { /// A heuristic objective function type. type Context: HeuristicContext; @@ -37,7 +37,7 @@ where O: HeuristicObjective, S: HeuristicSolution, { - terminations: Vec + Send + Sync>>, + terminations: Vec>>, } impl CompositeTermination @@ -47,7 +47,7 @@ where S: HeuristicSolution, { /// Creates a new instance of `CompositeTermination`. - pub fn new(terminations: Vec + Send + Sync>>) -> Self { + pub fn new(terminations: Vec>>) -> Self { Self { terminations } } } diff --git a/rosomaxa/src/utils/environment.rs b/rosomaxa/src/utils/environment.rs index e758445e8..7a11e363e 100644 --- a/rosomaxa/src/utils/environment.rs +++ b/rosomaxa/src/utils/environment.rs @@ -17,10 +17,10 @@ pub trait Quota: Send + Sync { #[derive(Clone)] pub struct Environment { /// A wrapper on random generator. - pub random: Arc, + pub random: Arc, /// A global execution quota. - pub quota: Option>, + pub quota: Option>, /// Keeps data parallelism settings. pub parallelism: Parallelism, @@ -36,15 +36,15 @@ impl Environment { /// Creates an instance of `Environment` using optional time quota and defaults. pub fn new_with_time_quota(max_time: Option) -> Self { Self { - quota: max_time.map::, _>(|time| Arc::new(TimeQuota::new(time as f64))), + quota: max_time.map::, _>(|time| Arc::new(TimeQuota::new(time as f64))), ..Self::default() } } /// Creates an instance of `Environment`. pub fn new( - random: Arc, - quota: Option>, + random: Arc, + quota: Option>, parallelism: Parallelism, logger: InfoLogger, is_experimental: bool, diff --git a/rosomaxa/src/utils/iterators.rs b/rosomaxa/src/utils/iterators.rs index 4301fd7c8..6e604bfb6 100644 --- a/rosomaxa/src/utils/iterators.rs +++ b/rosomaxa/src/utils/iterators.rs @@ -47,12 +47,12 @@ pub struct SelectionSamplingIterator { needed: usize, size: usize, iterator: I, - random: Arc, + random: Arc, } impl SelectionSamplingIterator { /// Creates a new instance of `SelectionSamplingIterator`. - pub fn new(iterator: I, amount: usize, random: Arc) -> Self { + pub fn new(iterator: I, amount: usize, random: Arc) -> Self { assert!(amount > 0); Self { // NOTE relying on lower bound size hint! @@ -93,7 +93,7 @@ impl Iterator for SelectionSamplingIterator { pub fn create_range_sampling_iter( iterator: I, sample_size: usize, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), ) -> impl Iterator { let iterator_size = iterator.size_hint().0 as f64; let sample_count = (iterator_size / sample_size as f64).max(1.) - 1.; @@ -131,7 +131,7 @@ pub trait SelectionSamplingSearch: Iterator { fn sample_search<'a, T, R, FM, FI, FC>( self, sample_size: usize, - random: Arc, + random: Arc, mut map_fn: FM, index_fn: FI, compare_fn: FC, diff --git a/rosomaxa/src/utils/noise.rs b/rosomaxa/src/utils/noise.rs index 3386a795d..09e76509c 100644 --- a/rosomaxa/src/utils/noise.rs +++ b/rosomaxa/src/utils/noise.rs @@ -9,19 +9,19 @@ pub struct Noise { probability: f64, range: (f64, f64), is_addition: bool, - random: Arc, + random: Arc, } impl Noise { /// Creates a new instance of `Noise` which will add some noise in given range /// to the target value: `value = value + value * sample_from(range)` - pub fn new_with_addition(probability: f64, range: (f64, f64), random: Arc) -> Self { + pub fn new_with_addition(probability: f64, range: (f64, f64), random: Arc) -> Self { Self { probability, range, is_addition: true, random } } /// Creates a new instance of `Noise` which will apply noise by multiplying target value /// by value from given range: `value = value * sample_from(range)` - pub fn new_with_ratio(probability: f64, range: (f64, f64), random: Arc) -> Self { + pub fn new_with_ratio(probability: f64, range: (f64, f64), random: Arc) -> Self { Self { probability, range, is_addition: false, random } } @@ -48,7 +48,7 @@ impl Noise { } /// Returns random generator. - pub fn random(&self) -> &(dyn Random + Send + Sync) { + pub fn random(&self) -> &(dyn Random) { self.random.as_ref() } } diff --git a/rosomaxa/src/utils/random.rs b/rosomaxa/src/utils/random.rs index 26678bb50..cbbc05b49 100644 --- a/rosomaxa/src/utils/random.rs +++ b/rosomaxa/src/utils/random.rs @@ -19,7 +19,7 @@ pub trait DistributionSampler { } /// Provides the way to use randomized values in generic way. -pub trait Random { +pub trait Random: Send + Sync { /// Produces integral random value, uniformly distributed on the closed interval [min, max] fn uniform_int(&self, min: i32, max: i32) -> i32; @@ -43,11 +43,11 @@ pub trait Random { /// Provides way to sample from different distributions. #[derive(Clone)] -pub struct DefaultDistributionSampler(Arc); +pub struct DefaultDistributionSampler(Arc); impl DefaultDistributionSampler { /// Creates a new instance of `DefaultDistributionSampler`. - pub fn new(random: Arc) -> Self { + pub fn new(random: Arc) -> Self { Self(random) } } diff --git a/rosomaxa/tests/helpers/utils/mod.rs b/rosomaxa/tests/helpers/utils/mod.rs index 82a0d6188..5520be8dd 100644 --- a/rosomaxa/tests/helpers/utils/mod.rs +++ b/rosomaxa/tests/helpers/utils/mod.rs @@ -1,6 +1,6 @@ use crate::utils::{DefaultRandom, Random}; use std::sync::Arc; -pub fn create_test_random() -> Arc { +pub fn create_test_random() -> Arc { Arc::new(DefaultRandom::default()) } diff --git a/rosomaxa/tests/unit/example_test.rs b/rosomaxa/tests/unit/example_test.rs index d3f2dd9a2..f20844b24 100644 --- a/rosomaxa/tests/unit/example_test.rs +++ b/rosomaxa/tests/unit/example_test.rs @@ -1,10 +1,6 @@ use super::*; -fn just_noise( - probability: f64, - range: (f64, f64), - random: Arc, -) -> VectorHeuristicOperatorMode { +fn just_noise(probability: f64, range: (f64, f64), random: Arc) -> VectorHeuristicOperatorMode { VectorHeuristicOperatorMode::JustNoise(Noise::new_with_ratio(probability, range, random)) } @@ -12,7 +8,7 @@ fn dimen_noise( probability: f64, range: (f64, f64), dimen: usize, - random: Arc, + random: Arc, ) -> VectorHeuristicOperatorMode { let dimen = vec![dimen].into_iter().collect(); VectorHeuristicOperatorMode::DimensionNoise(Noise::new_with_ratio(probability, range, random), dimen) diff --git a/rosomaxa/tests/unit/hyper/dynamic_selective_test.rs b/rosomaxa/tests/unit/hyper/dynamic_selective_test.rs index 09fbbfa08..89296470f 100644 --- a/rosomaxa/tests/unit/hyper/dynamic_selective_test.rs +++ b/rosomaxa/tests/unit/hyper/dynamic_selective_test.rs @@ -8,7 +8,7 @@ use std::time::Duration; fn can_estimate_median() { struct DelayableHeuristicOperator { delay_range: Range, - random: Arc, + random: Arc, } impl HeuristicSearchOperator for DelayableHeuristicOperator { type Context = VectorContext; diff --git a/vrp-cli/src/commands/solve.rs b/vrp-cli/src/commands/solve.rs index 9380f9255..4f4dbebf0 100644 --- a/vrp-cli/src/commands/solve.rs +++ b/vrp-cli/src/commands/solve.rs @@ -67,7 +67,7 @@ struct LocationWriter(pub Box>) -> Result< #[allow(clippy::type_complexity)] type FormatMap<'a> = HashMap<&'a str, (ProblemReader, InitSolutionReader, SolutionWriter, LocationWriter)>; -fn add_scientific(formats: &mut FormatMap, matches: &ArgMatches, random: Arc) { +fn add_scientific(formats: &mut FormatMap, matches: &ArgMatches, random: Arc) { if cfg!(feature = "scientific-format") { use vrp_scientific::common::read_init_solution; use vrp_scientific::lilim::{LilimProblem, LilimSolution}; @@ -119,7 +119,7 @@ fn add_scientific(formats: &mut FormatMap, matches: &ArgMatches, random: Arc) { +fn add_pragmatic(formats: &mut FormatMap, random: Arc) { use vrp_pragmatic::format::problem::{deserialize_problem, PragmaticProblem}; use vrp_pragmatic::format::solution::read_init_solution as read_init_pragmatic; @@ -156,7 +156,7 @@ fn add_pragmatic(formats: &mut FormatMap, random: Arc) ); } -fn get_formats<'a>(matches: &ArgMatches, random: Arc) -> FormatMap<'a> { +fn get_formats<'a>(matches: &ArgMatches, random: Arc) -> FormatMap<'a> { let mut formats = FormatMap::default(); add_scientific(&mut formats, matches, random.clone()); @@ -533,9 +533,9 @@ fn check_pragmatic_solution_with_args(matches: &ArgMatches) -> GenericResult<()> } /// Creates interruption quota. -pub fn create_interruption_quota(max_time: Option) -> Arc { +pub fn create_interruption_quota(max_time: Option) -> Arc { struct InterruptionQuota { - inner: Option>, + inner: Option>, should_interrupt: Arc, } @@ -546,7 +546,7 @@ pub fn create_interruption_quota(max_time: Option) -> Arc, _>(|time| Arc::new(TimeQuota::new(time as f64))); + let inner = max_time.map::, _>(|time| Arc::new(TimeQuota::new(time as f64))); let should_interrupt = Arc::new(AtomicBool::new(false)); // NOTE ignore error which happens in unit tests diff --git a/vrp-cli/src/extensions/solve/config.rs b/vrp-cli/src/extensions/solve/config.rs index 74d7ae745..be32373eb 100644 --- a/vrp-cli/src/extensions/solve/config.rs +++ b/vrp-cli/src/extensions/solve/config.rs @@ -570,10 +570,7 @@ fn configure_from_termination( builder } -fn create_recreate_method( - method: &RecreateMethod, - environment: Arc, -) -> (Arc, usize) { +fn create_recreate_method(method: &RecreateMethod, environment: Arc) -> (Arc, usize) { let random = environment.random.clone(); match method { RecreateMethod::Cheapest { weight } => (Arc::new(RecreateWithCheapest::new(random)), *weight), @@ -637,7 +634,7 @@ fn create_operator( fn create_operator_probability( probability: &OperatorProbabilityType, - random: Arc, + random: Arc, ) -> TargetHeuristicProbability { match probability { OperatorProbabilityType::Scalar { scalar } => create_scalar_operator_probability(*scalar, random), @@ -665,7 +662,7 @@ fn create_ruin_method( problem: &Arc, environment: Arc, method: &RuinMethod, -) -> (Arc, f64) { +) -> (Arc, f64) { let limits = RemovalLimits::new(problem.as_ref()); let get_limits = |min: usize, max: usize| RemovalLimits { removed_activities_range: min..max, @@ -700,11 +697,11 @@ fn create_ruin_method( fn create_local_search( times: &MinMaxConfig, inners: &[LocalOperatorType], - random: Arc, -) -> Arc { + random: Arc, +) -> Arc { let operators = inners .iter() - .map::<(Arc, usize), _>(|op| match op { + .map::<(Arc, usize), _>(|op| match op { LocalOperatorType::SwapStar { weight } => (Arc::new(ExchangeSwapStar::new(random.clone(), 200)), *weight), LocalOperatorType::InterRouteBest { weight, noise } => { (Arc::new(ExchangeInterRouteBest::new(noise.probability, noise.min, noise.max)), *weight) diff --git a/vrp-core/examples/common/routing.rs b/vrp-core/examples/common/routing.rs index 800f50914..3a9c12f10 100644 --- a/vrp-core/examples/common/routing.rs +++ b/vrp-core/examples/common/routing.rs @@ -3,7 +3,7 @@ use vrp_core::prelude::*; /// Gets a routing matrix for 5 unique locations. -pub fn define_routing_data() -> GenericResult { +pub fn define_routing_data() -> GenericResult { // define distance/duration matrix (use the same data for both) // as we have five locations, we need to define 5x5 matrix, flatten to 1 dimension: #[rustfmt::skip] diff --git a/vrp-core/examples/custom_constraint.rs b/vrp-core/examples/custom_constraint.rs index b14c83d25..fc5020691 100644 --- a/vrp-core/examples/custom_constraint.rs +++ b/vrp-core/examples/custom_constraint.rs @@ -49,7 +49,7 @@ impl FeatureConstraint for HardwareConstraint { } /// Specifies a CVRP problem variant: 4 delivery jobs with demand=1 and 2 vehicles with capacity=2 in each. -fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { // create 4 jobs when second and forth have fridge requirement let single_jobs = (1..=4) .map(|idx| { @@ -99,7 +99,7 @@ fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_goal(transport: Arc) -> GenericResult { let minimize_unassigned = MinimizeUnassignedBuilder::new("min-unassigned").build()?; let capacity_feature = CapacityFeatureBuilder::::new("capacity").build()?; let transport_feature = TransportFeatureBuilder::new("min-distance") diff --git a/vrp-core/examples/custom_objective.rs b/vrp-core/examples/custom_objective.rs index fdb2d38ce..f9ad16254 100644 --- a/vrp-core/examples/custom_objective.rs +++ b/vrp-core/examples/custom_objective.rs @@ -81,7 +81,7 @@ fn calculate_solution_fitness(solution_ctx: &SolutionContext) -> Cost { /// Specifies four delivery jobs with demand=1 (two of them are with top priority) and a single vehicle /// with capacity=2 which doesn't need to return to the depot. -fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { // create 4 jobs where two are having top prio let single_jobs = (1..=4) .map(|idx| { @@ -114,7 +114,7 @@ fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_goal(transport: Arc) -> GenericResult { let minimize_unassigned = MinimizeUnassignedBuilder::new("min-unassigned").build()?; let capacity_feature = CapacityFeatureBuilder::::new("capacity").build()?; let transport_feature = TransportFeatureBuilder::new("min-distance") diff --git a/vrp-core/examples/cvrp.rs b/vrp-core/examples/cvrp.rs index 8cfb33b98..a3a81ac62 100644 --- a/vrp-core/examples/cvrp.rs +++ b/vrp-core/examples/cvrp.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use vrp_core::prelude::*; /// Specifies a CVRP problem variant: 4 delivery jobs with demand=1 and 4 vehicles with capacity=2 in each. -fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { // create 4 jobs with location indices from 1 to 4 let single_jobs = (1..=4) .map(|idx| { @@ -59,7 +59,7 @@ fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_goal(transport: Arc) -> GenericResult { // configure features needed to model CVRP let minimize_unassigned = MinimizeUnassignedBuilder::new("min-unassigned").build()?; let capacity_feature = CapacityFeatureBuilder::::new("capacity").build()?; diff --git a/vrp-core/examples/pdptw.rs b/vrp-core/examples/pdptw.rs index c0c4e2897..309c095df 100644 --- a/vrp-core/examples/pdptw.rs +++ b/vrp-core/examples/pdptw.rs @@ -19,7 +19,7 @@ use vrp_core::models::common::TimeWindow; use vrp_core::prelude::*; /// Specifies a PDPTW problem variant: two PUDO (pick up/drop off) jobs with demand=1 and 1 vehicle with capacity 1 -fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { // build two PUDO (pick up/drop off) jobs with demand=1 and permissive time windows (just to show API usage) let pudos = (1..=2) .map(|idx| { @@ -72,7 +72,7 @@ fn define_problem(goal: GoalContext, transport: Arc) -> GenericResult { +fn define_goal(transport: Arc) -> GenericResult { // configure features needed to model PDPTW let minimize_unassigned = MinimizeUnassignedBuilder::new("min-unassigned").build()?; let capacity_feature = CapacityFeatureBuilder::::new("capacity").build()?; diff --git a/vrp-core/src/construction/clustering/dbscan/mod.rs b/vrp-core/src/construction/clustering/dbscan/mod.rs index 9d350539a..f627d0aa9 100644 --- a/vrp-core/src/construction/clustering/dbscan/mod.rs +++ b/vrp-core/src/construction/clustering/dbscan/mod.rs @@ -16,7 +16,7 @@ use std::sync::Arc; /// Creates clusters of jobs using DBSCAN algorithm. pub fn create_job_clusters( problem: &Problem, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), min_points: Option, epsilon: Option, ) -> Vec> { diff --git a/vrp-core/src/construction/clustering/vicinity/estimations.rs b/vrp-core/src/construction/clustering/vicinity/estimations.rs index 266307920..4f36f8726 100644 --- a/vrp-core/src/construction/clustering/vicinity/estimations.rs +++ b/vrp-core/src/construction/clustering/vicinity/estimations.rs @@ -96,7 +96,7 @@ pub(crate) fn get_clusters( /// Gets jobs dissimilarities. pub(crate) fn get_jobs_dissimilarities( jobs: &[Job], - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), config: &ClusterConfig, ) -> HashMap { jobs.iter() @@ -121,7 +121,7 @@ pub(crate) fn get_jobs_dissimilarities( fn get_dissimilarities( outer: &Job, inner: &Job, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), config: &ClusterConfig, ) -> Vec { let min_shared_time = config.threshold.min_shared_time.unwrap_or(0.); diff --git a/vrp-core/src/construction/enablers/conditional_job.rs b/vrp-core/src/construction/enablers/conditional_job.rs index 75f0b8c20..e88022610 100644 --- a/vrp-core/src/construction/enablers/conditional_job.rs +++ b/vrp-core/src/construction/enablers/conditional_job.rs @@ -3,7 +3,7 @@ use crate::models::problem::Job; use std::collections::HashSet; /// Defines how jobs are moved in solution context. Index of original affected route context is passed. -pub trait JobContextTransition { +pub trait JobContextTransition: Send + Sync { /// Returns true if job is moved from required to ignored. fn remove_from_required(&self, solution_ctx: &SolutionContext, route_index: Option, job: &Job) -> bool; @@ -20,10 +20,10 @@ pub trait JobContextTransition { /// A concrete implementation of `JobContextTransition` which allows to use lambdas. pub struct ConcreteJobContextTransition where - FRemoveRequired: Fn(&SolutionContext, Option, &Job) -> bool, - FPromoteRequired: Fn(&SolutionContext, Option, &Job) -> bool, - FRemoveLocked: Fn(&SolutionContext, Option, &Job) -> bool, - FPromoteLocked: Fn(&SolutionContext, Option, &Job) -> bool, + FRemoveRequired: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, + FPromoteRequired: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, + FRemoveLocked: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, + FPromoteLocked: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, { /// A function which removes job from required list. pub remove_required: FRemoveRequired, @@ -38,10 +38,10 @@ where impl JobContextTransition for ConcreteJobContextTransition where - FRemoveRequired: Fn(&SolutionContext, Option, &Job) -> bool, - FPromoteRequired: Fn(&SolutionContext, Option, &Job) -> bool, - FRemoveLocked: Fn(&SolutionContext, Option, &Job) -> bool, - FPromoteLocked: Fn(&SolutionContext, Option, &Job) -> bool, + FRemoveRequired: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, + FPromoteRequired: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, + FRemoveLocked: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, + FPromoteLocked: Fn(&SolutionContext, Option, &Job) -> bool + Send + Sync, { fn remove_from_required(&self, solution_ctx: &SolutionContext, route_index: Option, job: &Job) -> bool { (self.remove_required)(solution_ctx, route_index, job) @@ -64,7 +64,7 @@ where pub fn process_conditional_jobs( solution_ctx: &mut SolutionContext, route_index: Option, - context_transition: &(dyn JobContextTransition + Send + Sync), + context_transition: &(dyn JobContextTransition), ) { // analyzed required/ignored let ignored: HashSet = solution_ctx diff --git a/vrp-core/src/construction/enablers/departure_time.rs b/vrp-core/src/construction/enablers/departure_time.rs index 75916ac00..80f781909 100644 --- a/vrp-core/src/construction/enablers/departure_time.rs +++ b/vrp-core/src/construction/enablers/departure_time.rs @@ -12,8 +12,8 @@ use std::cmp::Ordering; /// Tries to move forward route's departure time. pub fn advance_departure_time( route_ctx: &mut RouteContext, - activity: &(dyn ActivityCost + Send + Sync), - transport: &(dyn TransportCost + Send + Sync), + activity: &(dyn ActivityCost), + transport: &(dyn TransportCost), consider_whole_tour: bool, ) { if let Some(new_departure_time) = try_advance_departure_time(route_ctx, transport, consider_whole_tour) { @@ -24,8 +24,8 @@ pub fn advance_departure_time( /// Tries to move backward route's departure time. pub fn recede_departure_time( route_ctx: &mut RouteContext, - activity: &(dyn ActivityCost + Send + Sync), - transport: &(dyn TransportCost + Send + Sync), + activity: &(dyn ActivityCost), + transport: &(dyn TransportCost), ) { if let Some(new_departure_time) = try_recede_departure_time(route_ctx) { update_route_departure(route_ctx, activity, transport, new_departure_time); @@ -34,7 +34,7 @@ pub fn recede_departure_time( fn try_advance_departure_time( route_ctx: &RouteContext, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), optimize_whole_tour: bool, ) -> Option { let route = route_ctx.route(); diff --git a/vrp-core/src/construction/enablers/multi_trip.rs b/vrp-core/src/construction/enablers/multi_trip.rs index 962b3986b..cbb9094fb 100644 --- a/vrp-core/src/construction/enablers/multi_trip.rs +++ b/vrp-core/src/construction/enablers/multi_trip.rs @@ -12,7 +12,7 @@ use std::iter::once; use std::sync::Arc; /// Specifies multi trip extension behavior. -pub trait MultiTrip { +pub trait MultiTrip: Send + Sync { /// Gets an actual route intervals. fn get_route_intervals(&self) -> &RouteIntervals; @@ -40,7 +40,7 @@ pub fn create_multi_trip_feature( name: &str, violation_code: ViolationCode, policy: MarkerInsertionPolicy, - multi_trip: Arc, + multi_trip: Arc, ) -> Result { FeatureBuilder::default() .with_name(name) @@ -52,7 +52,7 @@ pub fn create_multi_trip_feature( struct MultiTripConstraint { code: ViolationCode, policy: MarkerInsertionPolicy, - multi_trip: Arc, + multi_trip: Arc, } impl FeatureConstraint for MultiTripConstraint { @@ -103,19 +103,19 @@ impl FeatureConstraint for MultiTripConstraint { } impl MultiTripConstraint { - fn new(code: ViolationCode, policy: MarkerInsertionPolicy, multi_trip: Arc) -> Self { + fn new(code: ViolationCode, policy: MarkerInsertionPolicy, multi_trip: Arc) -> Self { Self { code, policy, multi_trip } } } struct MultiTripState { - multi_trip: Arc, - context_transition: Box, + multi_trip: Arc, + context_transition: Box, code: ViolationCode, } impl MultiTripState { - pub fn new(code: ViolationCode, multi_trip: Arc) -> Self { + pub fn new(code: ViolationCode, multi_trip: Arc) -> Self { let context_transition = Box::new(ConcreteJobContextTransition { remove_required: { let multi_trip = multi_trip.clone(); diff --git a/vrp-core/src/construction/enablers/reserved_time.rs b/vrp-core/src/construction/enablers/reserved_time.rs index d04e96d4c..343e5fa28 100644 --- a/vrp-core/src/construction/enablers/reserved_time.rs +++ b/vrp-core/src/construction/enablers/reserved_time.rs @@ -101,15 +101,12 @@ impl ActivityCost for DynamicActivityCost { /// Provides way to calculate transport costs which might contain reserved time. pub struct DynamicTransportCost { reserved_times_fn: ReservedTimesFn, - inner: Arc, + inner: Arc, } impl DynamicTransportCost { /// Creates a new instance of `DynamicTransportCost`. - pub fn new( - reserved_times_index: ReservedTimesIndex, - inner: Arc, - ) -> Result { + pub fn new(reserved_times_index: ReservedTimesIndex, inner: Arc) -> Result { Ok(Self { reserved_times_fn: create_reserved_times_fn(reserved_times_index)?, inner }) } } diff --git a/vrp-core/src/construction/enablers/schedule_update.rs b/vrp-core/src/construction/enablers/schedule_update.rs index 5f30e3e36..a3ed39367 100644 --- a/vrp-core/src/construction/enablers/schedule_update.rs +++ b/vrp-core/src/construction/enablers/schedule_update.rs @@ -12,8 +12,8 @@ custom_tour_state!(LimitDuration typeof Duration); /// Updates route schedule data. pub fn update_route_schedule( route_ctx: &mut RouteContext, - activity: &(dyn ActivityCost + Send + Sync), - transport: &(dyn TransportCost + Send + Sync), + activity: &(dyn ActivityCost), + transport: &(dyn TransportCost), ) { update_schedules(route_ctx, activity, transport); update_states(route_ctx, activity, transport); @@ -23,8 +23,8 @@ pub fn update_route_schedule( /// Updates route departure to the new one. pub fn update_route_departure( route_ctx: &mut RouteContext, - activity: &(dyn ActivityCost + Send + Sync), - transport: &(dyn TransportCost + Send + Sync), + activity: &(dyn ActivityCost), + transport: &(dyn TransportCost), new_departure_time: Timestamp, ) { let start = route_ctx.route_mut().tour.get_mut(0).unwrap(); @@ -33,11 +33,7 @@ pub fn update_route_departure( update_route_schedule(route_ctx, activity, transport); } -fn update_schedules( - route_ctx: &mut RouteContext, - activity: &(dyn ActivityCost + Send + Sync), - transport: &(dyn TransportCost + Send + Sync), -) { +fn update_schedules(route_ctx: &mut RouteContext, activity: &(dyn ActivityCost), transport: &(dyn TransportCost)) { let init = { let start = route_ctx.route().tour.start().unwrap(); (start.place.location, start.schedule.departure) @@ -59,11 +55,7 @@ fn update_schedules( }); } -fn update_states( - route_ctx: &mut RouteContext, - activity: &(dyn ActivityCost + Send + Sync), - transport: &(dyn TransportCost + Send + Sync), -) { +fn update_states(route_ctx: &mut RouteContext, activity: &(dyn ActivityCost), transport: &(dyn TransportCost)) { // update latest arrival and waiting states of non-terminate (jobs) activities let actor = route_ctx.route().actor.clone(); let init = ( @@ -117,7 +109,7 @@ fn update_states( route_ctx.state_mut().set_waiting_time_states(waiting_times); } -fn update_statistics(route_ctx: &mut RouteContext, transport: &(dyn TransportCost + Send + Sync)) { +fn update_statistics(route_ctx: &mut RouteContext, transport: &(dyn TransportCost)) { let (route, state) = route_ctx.as_mut(); let start = route.tour.start().unwrap(); diff --git a/vrp-core/src/construction/enablers/travel_info.rs b/vrp-core/src/construction/enablers/travel_info.rs index 212329215..80d504be2 100644 --- a/vrp-core/src/construction/enablers/travel_info.rs +++ b/vrp-core/src/construction/enablers/travel_info.rs @@ -7,7 +7,7 @@ use crate::models::solution::{Activity, Route}; pub fn calculate_travel( route_ctx: &RouteContext, activity_ctx: &ActivityContext, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), ) -> ((Distance, Distance), (Duration, Duration)) { let route = route_ctx.route(); let prev = activity_ctx.prev; @@ -33,7 +33,7 @@ pub fn calculate_travel( pub fn calculate_travel_delta( route_ctx: &RouteContext, activity_ctx: &ActivityContext, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), ) -> (Distance, Duration) { // NOTE accept some code duplication between methods in that module as they are called often, // generalization might require some redundancy in calculations @@ -65,7 +65,7 @@ fn calculate_travel_leg( first: &Activity, second: &Activity, departure: Timestamp, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), ) -> (Distance, Duration) { let first_to_second_dis = transport.distance(route, first.place.location, second.place.location, TravelTime::Departure(departure)); diff --git a/vrp-core/src/construction/features/fast_service.rs b/vrp-core/src/construction/features/fast_service.rs index bbda5acce..c41197964 100644 --- a/vrp-core/src/construction/features/fast_service.rs +++ b/vrp-core/src/construction/features/fast_service.rs @@ -12,8 +12,8 @@ pub struct FastServiceFeatureBuilder { violation_code: Option, demand_type_fn: Option, is_filtered_job_fn: Option, - transport: Option>, - activity: Option>, + transport: Option>, + activity: Option>, } impl FastServiceFeatureBuilder { @@ -54,13 +54,13 @@ impl FastServiceFeatureBuilder { } /// Sets transport costs to estimate distance. - pub fn set_transport(mut self, transport: Arc) -> Self { + pub fn set_transport(mut self, transport: Arc) -> Self { self.transport = Some(transport); self } /// Sets activity costs to estimate job start/end time. - pub fn set_activity(mut self, activity: Arc) -> Self { + pub fn set_activity(mut self, activity: Arc) -> Self { self.activity = Some(activity); self } @@ -110,8 +110,8 @@ custom_tour_state!(MultiJobRanges typeof MultiJobRanges); struct FastServiceObjective { demand_type_fn: DemandTypeFn, is_filtered_job_fn: IsFilteredJobFn, - transport: Arc, - activity: Arc, + transport: Arc, + activity: Arc, } impl FeatureObjective for FastServiceObjective { @@ -167,8 +167,8 @@ impl FastServiceObjective { fn new( demand_type_fn: DemandTypeFn, is_filtered_job_fn: IsFilteredJobFn, - transport: Arc, - activity: Arc, + transport: Arc, + activity: Arc, ) -> Self { Self { demand_type_fn, is_filtered_job_fn, transport, activity } } diff --git a/vrp-core/src/construction/features/reachable.rs b/vrp-core/src/construction/features/reachable.rs index c54fc61ad..58d441a61 100644 --- a/vrp-core/src/construction/features/reachable.rs +++ b/vrp-core/src/construction/features/reachable.rs @@ -9,14 +9,14 @@ use std::sync::Arc; /// Creates a feature to check reachability of the jobs. It is a hard constraint. pub fn create_reachable_feature( name: &str, - transport: Arc, + transport: Arc, code: ViolationCode, ) -> Result { FeatureBuilder::default().with_name(name).with_constraint(ReachableConstraint { transport, code }).build() } struct ReachableConstraint { - transport: Arc, + transport: Arc, code: ViolationCode, } diff --git a/vrp-core/src/construction/features/recharge.rs b/vrp-core/src/construction/features/recharge.rs index fc801c195..0e454398c 100644 --- a/vrp-core/src/construction/features/recharge.rs +++ b/vrp-core/src/construction/features/recharge.rs @@ -17,7 +17,7 @@ use std::sync::Arc; pub struct RechargeFeatureBuilder { name: String, violation_code: Option, - transport: Option>, + transport: Option>, belongs_to_route_fn: Option bool + Send + Sync>>, is_recharge_single_fn: Option, distance_limit_fn: Option, @@ -43,7 +43,7 @@ impl RechargeFeatureBuilder { } /// Sets transport costs to estimate distance. - pub fn set_transport(mut self, transport: Arc) -> Self { + pub fn set_transport(mut self, transport: Arc) -> Self { self.transport = Some(transport); self } @@ -171,7 +171,7 @@ custom_activity_state!(RechargeDistance typeof Distance); struct RechargeableMultiTrip { route_intervals: RouteIntervals, - transport: Arc, + transport: Arc, code: ViolationCode, distance_limit_fn: RechargeDistanceLimitFn, recharge_single_fn: RechargeSingleFn, diff --git a/vrp-core/src/construction/features/tour_limits.rs b/vrp-core/src/construction/features/tour_limits.rs index abe5eca69..24dd0b5f2 100644 --- a/vrp-core/src/construction/features/tour_limits.rs +++ b/vrp-core/src/construction/features/tour_limits.rs @@ -33,7 +33,7 @@ pub fn create_activity_limit_feature( /// This is a hard constraint. pub fn create_travel_limit_feature( name: &str, - transport: Arc, + transport: Arc, distance_code: ViolationCode, duration_code: ViolationCode, tour_distance_limit_fn: TravelLimitFn, @@ -86,7 +86,7 @@ impl FeatureConstraint for ActivityLimitConstraint { } struct TravelLimitConstraint { - transport: Arc, + transport: Arc, tour_distance_limit_fn: TravelLimitFn, tour_duration_limit_fn: TravelLimitFn, distance_code: ViolationCode, diff --git a/vrp-core/src/construction/features/transport.rs b/vrp-core/src/construction/features/transport.rs index 22993256f..de10683fd 100644 --- a/vrp-core/src/construction/features/transport.rs +++ b/vrp-core/src/construction/features/transport.rs @@ -17,8 +17,8 @@ use crate::models::solution::Activity; /// Provides a way to build different flavors of time window feature. pub struct TransportFeatureBuilder { name: String, - transport: Option>, - activity: Option>, + transport: Option>, + activity: Option>, code: Option, is_constrained: bool, } @@ -44,14 +44,14 @@ impl TransportFeatureBuilder { } /// Sets transport costs to estimate distance. - pub fn set_transport_cost(mut self, transport: Arc) -> Self { + pub fn set_transport_cost(mut self, transport: Arc) -> Self { self.transport = Some(transport); self } /// Sets activity costs to estimate job start/end time. /// If omitted, then [SimpleActivityCost] is used by default. - pub fn set_activity_cost(mut self, activity: Arc) -> Self { + pub fn set_activity_cost(mut self, activity: Arc) -> Self { self.activity = Some(activity); self } @@ -117,9 +117,7 @@ impl TransportFeatureBuilder { ) } - fn get_costs( - &mut self, - ) -> GenericResult<(Arc, Arc)> { + fn get_costs(&mut self) -> GenericResult<(Arc, Arc)> { let transport = self.transport.take().ok_or_else(|| GenericError::from("transport must be set"))?; let activity = self.activity.take().unwrap_or_else(|| Arc::new(SimpleActivityCost::default())); @@ -129,8 +127,8 @@ impl TransportFeatureBuilder { fn create_feature( name: &str, - transport: Arc, - activity: Arc, + transport: Arc, + activity: Arc, time_window_code: ViolationCode, is_constrained: bool, fitness_fn: Box f64 + Send + Sync>, @@ -154,8 +152,8 @@ fn create_feature( } struct TransportConstraint { - transport: Arc, - activity: Arc, + transport: Arc, + activity: Arc, time_window_code: ViolationCode, } @@ -281,8 +279,8 @@ impl FeatureConstraint for TransportConstraint { } struct TransportObjective { - activity: Arc, - transport: Arc, + activity: Arc, + transport: Arc, fitness_fn: Box f64 + Send + Sync>, } @@ -365,12 +363,12 @@ impl FeatureObjective for TransportObjective { } struct TransportState { - transport: Arc, - activity: Arc, + transport: Arc, + activity: Arc, } impl TransportState { - fn new(transport: Arc, activity: Arc) -> Self { + fn new(transport: Arc, activity: Arc) -> Self { Self { transport, activity } } } diff --git a/vrp-core/src/construction/heuristics/evaluators.rs b/vrp-core/src/construction/heuristics/evaluators.rs index f3b44029f..ae0a5df41 100644 --- a/vrp-core/src/construction/heuristics/evaluators.rs +++ b/vrp-core/src/construction/heuristics/evaluators.rs @@ -21,7 +21,7 @@ pub struct EvaluationContext<'a> { /// A leg selection mode. pub leg_selection: &'a LegSelection, /// A result selector. - pub result_selector: &'a (dyn ResultSelector + Send + Sync), + pub result_selector: &'a (dyn ResultSelector), } /// Specifies allowed insertion position in route for the job. diff --git a/vrp-core/src/construction/heuristics/insertions.rs b/vrp-core/src/construction/heuristics/insertions.rs index a88487eec..2aaae871b 100644 --- a/vrp-core/src/construction/heuristics/insertions.rs +++ b/vrp-core/src/construction/heuristics/insertions.rs @@ -256,10 +256,10 @@ impl InsertionHeuristic { pub fn process( &self, mut insertion_ctx: InsertionContext, - job_selector: &(dyn JobSelector + Send + Sync), - route_selector: &(dyn RouteSelector + Send + Sync), + job_selector: &(dyn JobSelector), + route_selector: &(dyn RouteSelector), leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionContext { prepare_insertion_ctx(&mut insertion_ctx); diff --git a/vrp-core/src/construction/heuristics/metrics.rs b/vrp-core/src/construction/heuristics/metrics.rs index b3de67bac..803c58f24 100644 --- a/vrp-core/src/construction/heuristics/metrics.rs +++ b/vrp-core/src/construction/heuristics/metrics.rs @@ -266,7 +266,7 @@ fn get_values_from_route_state<'a>( } /// Gets medoid location of given route context. -fn get_medoid(route_ctx: &RouteContext, transport: &(dyn TransportCost + Send + Sync)) -> Option { +fn get_medoid(route_ctx: &RouteContext, transport: &(dyn TransportCost)) -> Option { let profile = &route_ctx.route().actor.vehicle.profile; let locations = route_ctx.route().tour.all_activities().map(|activity| activity.place.location).collect::>(); locations diff --git a/vrp-core/src/construction/heuristics/selectors.rs b/vrp-core/src/construction/heuristics/selectors.rs index 3f10f27f9..cd7c0c77b 100644 --- a/vrp-core/src/construction/heuristics/selectors.rs +++ b/vrp-core/src/construction/heuristics/selectors.rs @@ -14,7 +14,7 @@ use std::sync::Arc; /// On each insertion step, selects a list of routes where jobs can be inserted. /// It is up to implementation to decide whether list consists of all possible routes or just some subset. -pub trait RouteSelector { +pub trait RouteSelector: Send + Sync { /// This method is called before select. It allows to apply some changes on mutable context /// before immutable borrowing could happen within select method. /// Default implementation simply shuffles existing routes. @@ -46,7 +46,7 @@ impl RouteSelector for AllRouteSelector { /// On each insertion step, selects a list of jobs to be inserted. /// It is up to implementation to decide whether list consists of all jobs or just some subset. -pub trait JobSelector { +pub trait JobSelector: Send + Sync { /// This method is called before select. It allows to apply some changes on mutable context /// before immutable borrowing could happen within select method. /// Default implementation simply shuffles jobs in required collection. @@ -67,7 +67,7 @@ pub struct AllJobSelector {} impl JobSelector for AllJobSelector {} /// Evaluates insertion. -pub trait InsertionEvaluator { +pub trait InsertionEvaluator: Send + Sync { /// Evaluates insertion of a single job into given collection of routes. fn evaluate_job( &self, @@ -75,7 +75,7 @@ pub trait InsertionEvaluator { job: &Job, routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult; /// Evaluates insertion of multiple jobs into given route. @@ -85,7 +85,7 @@ pub trait InsertionEvaluator { route_ctx: &RouteContext, jobs: &[&Job], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult; /// Evaluates insertion of a job collection into given collection of routes. @@ -95,7 +95,7 @@ pub trait InsertionEvaluator { jobs: &[&Job], routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult; } @@ -123,7 +123,7 @@ impl PositionInsertionEvaluator { jobs: &[&Job], routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> Vec { if Self::is_fold_jobs(insertion_ctx) { parallel_collect(jobs, |job| self.evaluate_job(insertion_ctx, job, routes, leg_selection, result_selector)) @@ -146,7 +146,7 @@ impl InsertionEvaluator for PositionInsertionEvaluator { job: &Job, routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { let eval_ctx = EvaluationContext { goal: &insertion_ctx.problem.goal, job, leg_selection, result_selector }; @@ -161,7 +161,7 @@ impl InsertionEvaluator for PositionInsertionEvaluator { route_ctx: &RouteContext, jobs: &[&Job], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { jobs.iter().fold(InsertionResult::make_failure(), |acc, job| { let eval_ctx = EvaluationContext { goal: &insertion_ctx.problem.goal, job, leg_selection, result_selector }; @@ -175,7 +175,7 @@ impl InsertionEvaluator for PositionInsertionEvaluator { jobs: &[&Job], routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { if Self::is_fold_jobs(insertion_ctx) { map_reduce( @@ -196,7 +196,7 @@ impl InsertionEvaluator for PositionInsertionEvaluator { } /// Insertion result selector. -pub trait ResultSelector { +pub trait ResultSelector: Send + Sync { /// Selects one insertion result from two to promote as best. fn select_insertion( &self, @@ -318,18 +318,18 @@ impl ResultSelector for FarthestResultSelector { /// A result selector strategy inspired by "Slack Induction by String Removals for Vehicle /// Routing Problems", Jan Christiaens, Greet Vanden Berghe. pub struct BlinkResultSelector { - random: Arc, + random: Arc, ratio: f64, } impl BlinkResultSelector { /// Creates an instance of `BlinkResultSelector`. - pub fn new(ratio: f64, random: Arc) -> Self { + pub fn new(ratio: f64, random: Arc) -> Self { Self { random, ratio } } /// Creates an instance of `BlinkResultSelector` with default values. - pub fn new_with_defaults(random: Arc) -> Self { + pub fn new_with_defaults(random: Arc) -> Self { Self::new(0.01, random) } } @@ -371,19 +371,19 @@ pub enum ResultSelection { Stochastic(ResultSelectorProvider), /// Returns concrete instance of result selector to be used. - Concrete(Box), + Concrete(Box), } /// Provides way to access one of built-in result selectors non-deterministically. pub struct ResultSelectorProvider { - inners: Vec>, + inners: Vec>, weights: Vec, - random: Arc, + random: Arc, } impl ResultSelectorProvider { /// Creates a new instance of `StochasticResultSelectorFn` - pub fn new_default(random: Arc) -> Self { + pub fn new_default(random: Arc) -> Self { Self { inners: vec![ Box::::default(), @@ -397,7 +397,7 @@ impl ResultSelectorProvider { } /// Returns random result selector from the list. - pub fn pick(&self) -> &(dyn ResultSelector + Send + Sync) { + pub fn pick(&self) -> &(dyn ResultSelector) { self.inners[self.random.weighted(self.weights.as_slice())].as_ref() } } @@ -406,7 +406,7 @@ impl ResultSelectorProvider { #[derive(Clone)] pub enum LegSelection { /// Stochastic mode: depending on route size, not all legs could be selected. - Stochastic(Arc), + Stochastic(Arc), /// Exhaustive mode: all legs are selected. Exhaustive, } @@ -447,12 +447,7 @@ impl LegSelection { } /// Returns a sample data for stochastic mode. - fn get_sample_data( - &self, - route_ctx: &RouteContext, - job: &Job, - skip: usize, - ) -> Option<(usize, Arc)> { + fn get_sample_data(&self, route_ctx: &RouteContext, job: &Job, skip: usize) -> Option<(usize, Arc)> { match self { Self::Stochastic(random) => { let gen_usize = |min: i32, max: i32| random.uniform_int(min, max) as usize; diff --git a/vrp-core/src/models/domain.rs b/vrp-core/src/models/domain.rs index 012fe4787..39c1f14b3 100644 --- a/vrp-core/src/models/domain.rs +++ b/vrp-core/src/models/domain.rs @@ -23,10 +23,10 @@ pub struct Problem { pub goal: Arc, /// Specifies activity costs. - pub activity: Arc, + pub activity: Arc, /// Specifies transport costs. - pub transport: Arc, + pub transport: Arc, /// Specifies index for storing extra parameters of arbitrary type. pub extras: Arc, @@ -131,8 +131,8 @@ pub struct ProblemBuilder { #[allow(clippy::type_complexity)] group_key_fn: Option]) -> Box>>, goal: Option>, - activity: Option>, - transport: Option>, + activity: Option>, + transport: Option>, extras: Option>, } @@ -184,14 +184,14 @@ impl ProblemBuilder { /// Adds a transport distance/duration estimation logic. A typical implementation will normally /// wrap routing distance/duration matrices. /// A required field. - pub fn with_transport_cost(mut self, transport: Arc) -> Self { + pub fn with_transport_cost(mut self, transport: Arc) -> Self { self.transport = Some(transport); self } /// Adds an activity service time estimation logic. /// An optional field: [SimpleActivityCost] will be used by default. - pub fn with_activity_cost(mut self, activity: Arc) -> Self { + pub fn with_activity_cost(mut self, activity: Arc) -> Self { self.activity = Some(activity); self } diff --git a/vrp-core/src/models/goal.rs b/vrp-core/src/models/goal.rs index 3ab46a1fb..8e5d2c673 100644 --- a/vrp-core/src/models/goal.rs +++ b/vrp-core/src/models/goal.rs @@ -441,7 +441,7 @@ impl HeuristicObjective for GoalContext { } impl Shuffled for GoalContext { - fn get_shuffled(&self, random: &(dyn Random + Send + Sync)) -> Self { + fn get_shuffled(&self, random: &(dyn Random)) -> Self { const RANDOM_ALTERNATIVE_PROBABILITY: f64 = 0.05; const RANDOM_SHUFFLE_PROBABILITY: f64 = 0.001; @@ -465,7 +465,7 @@ impl GoalContext { Self { goal, ..self.clone() } } - fn get_shuffled(&self, random: &(dyn Random + Send + Sync)) -> Self { + fn get_shuffled(&self, random: &(dyn Random)) -> Self { let instance = self.clone(); let mut layers = self.goal.layers.clone(); diff --git a/vrp-core/src/models/problem/builders.rs b/vrp-core/src/models/problem/builders.rs index b38a98317..3003381db 100644 --- a/vrp-core/src/models/problem/builders.rs +++ b/vrp-core/src/models/problem/builders.rs @@ -135,7 +135,7 @@ impl JobPlaceBuilder { pub struct MultiBuilder { jobs: Vec>, dimens: Dimensions, - permutator: Option>, + permutator: Option>, } impl MultiBuilder { @@ -159,7 +159,7 @@ impl MultiBuilder { /// Sets a permutation logic which tells allowed order of sub-jobs assignment. /// If omitted, sub-jobs can be assigned only in the order of addition. - pub fn permutation(mut self, permutation: impl JobPermutation + Send + Sync + 'static) -> Self { + pub fn permutation(mut self, permutation: impl JobPermutation + 'static) -> Self { self.permutator = Some(Box::new(permutation)); self } diff --git a/vrp-core/src/models/problem/costs.rs b/vrp-core/src/models/problem/costs.rs index b562ef5f1..901905c20 100644 --- a/vrp-core/src/models/problem/costs.rs +++ b/vrp-core/src/models/problem/costs.rs @@ -19,7 +19,7 @@ pub enum TravelTime { } /// Provides the way to get cost information for specific activities done by specific actor. -pub trait ActivityCost { +pub trait ActivityCost: Send + Sync { /// Returns cost to perform activity. fn cost(&self, route: &Route, activity: &Activity, arrival: Timestamp) -> Cost { let actor = route.actor.as_ref(); @@ -53,7 +53,7 @@ impl ActivityCost for SimpleActivityCost { } /// Provides the way to get routing information for specific locations and actor. -pub trait TransportCost { +pub trait TransportCost: Send + Sync { /// Returns time-dependent transport cost between two locations for given actor. fn cost(&self, route: &Route, from: Location, to: Location, travel_time: TravelTime) -> Cost { let actor = route.actor.as_ref(); @@ -160,9 +160,7 @@ impl TransportFallback for NoFallback { /// Creates time agnostic or time aware routing costs based on matrix data passed. /// Panics at runtime if given route path is not present in matrix data. -pub fn create_matrix_transport_cost( - costs: Vec, -) -> Result, GenericError> { +pub fn create_matrix_transport_cost(costs: Vec) -> GenericResult> { create_matrix_transport_cost_with_fallback(costs, NoFallback) } @@ -171,7 +169,7 @@ pub fn create_matrix_transport_cost( pub fn create_matrix_transport_cost_with_fallback( costs: Vec, fallback: T, -) -> Result, GenericError> { +) -> GenericResult> { if costs.is_empty() { return Err("no matrix data found".into()); } diff --git a/vrp-core/src/models/problem/jobs.rs b/vrp-core/src/models/problem/jobs.rs index 03a96bfe1..4d958f9ea 100644 --- a/vrp-core/src/models/problem/jobs.rs +++ b/vrp-core/src/models/problem/jobs.rs @@ -112,7 +112,7 @@ pub struct Multi { /// Dimensions which contains extra work requirements. pub dimens: Dimensions, /// Permutation generator. - permutator: Box, + permutator: Box, } impl Debug for Multi { @@ -126,7 +126,7 @@ impl Debug for Multi { /// Defines a trait to work with multi job's permutations. Essentially, it specifies valid combinations /// of sub-jobs inside multi-job. -pub trait JobPermutation { +pub trait JobPermutation: Send + Sync { // TODO fix all implementations to support returning reference /// Returns a valid permutation. fn get(&self) -> Vec>; @@ -171,7 +171,7 @@ impl Multi { pub fn new_shared_with_permutator( jobs: Vec>, dimens: Dimensions, - permutator: Box, + permutator: Box, ) -> Arc { Self::bind(Self { jobs, dimens, permutator }) } @@ -236,7 +236,7 @@ pub struct Jobs { impl Jobs { /// Creates a new [`Jobs`]. - pub fn new(fleet: &Fleet, jobs: Vec, transport: &(dyn TransportCost + Send + Sync)) -> Jobs { + pub fn new(fleet: &Fleet, jobs: Vec, transport: &(dyn TransportCost)) -> Jobs { Jobs { jobs: jobs.clone(), index: create_index(fleet, jobs, transport) } } @@ -302,11 +302,7 @@ pub fn get_job_locations(job: &Job) -> impl Iterator> + } /// Creates job index. -fn create_index( - fleet: &Fleet, - jobs: Vec, - transport: &(dyn TransportCost + Send + Sync), -) -> HashMap { +fn create_index(fleet: &Fleet, jobs: Vec, transport: &(dyn TransportCost)) -> HashMap { let avg_profile_costs = get_avg_profile_costs(fleet); fleet.profiles.iter().fold(HashMap::new(), |mut acc, profile| { @@ -351,7 +347,7 @@ fn create_index( fn get_cost_between_locations( profile: &Profile, costs: &Costs, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), from: Location, to: Location, ) -> LowPrecisionCost { @@ -370,7 +366,7 @@ fn get_cost_between_locations( fn get_cost_between_job_and_location( profile: &Profile, costs: &Costs, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), job: &Job, to: Location, ) -> LowPrecisionCost { @@ -385,7 +381,7 @@ fn get_cost_between_job_and_location( fn get_cost_between_jobs( profile: &Profile, costs: &Costs, - transport: &(dyn TransportCost + Send + Sync), + transport: &(dyn TransportCost), lhs: &Job, rhs: &Job, ) -> LowPrecisionCost { diff --git a/vrp-core/src/models/solution/registry.rs b/vrp-core/src/models/solution/registry.rs index 85ecdabd3..967feda00 100644 --- a/vrp-core/src/models/solution/registry.rs +++ b/vrp-core/src/models/solution/registry.rs @@ -12,12 +12,12 @@ pub struct Registry { available: HashMap>>, index: HashMap, usize>, all: Vec>, - random: Arc, + random: Arc, } impl Registry { /// Creates a new instance of `Registry` - pub fn new(fleet: &Fleet, random: Arc) -> Self { + pub fn new(fleet: &Fleet, random: Arc) -> Self { let index = fleet .groups .iter() diff --git a/vrp-core/src/solver/heuristic.rs b/vrp-core/src/solver/heuristic.rs index bed47d784..a43211a14 100644 --- a/vrp-core/src/solver/heuristic.rs +++ b/vrp-core/src/solver/heuristic.rs @@ -214,7 +214,7 @@ impl Input for InsertionContext { /// Creates a heuristic operator probability which uses `is_hit` method from passed random object. pub fn create_scalar_operator_probability( scalar_probability: f64, - random: Arc, + random: Arc, ) -> TargetHeuristicProbability { (Box::new(move |_, _| random.is_hit(scalar_probability)), PhantomData) } @@ -224,7 +224,7 @@ pub fn create_context_operator_probability( jobs_threshold: usize, routes_threshold: usize, phases: Vec<(SelectionPhase, f64)>, - random: Arc, + random: Arc, ) -> TargetHeuristicProbability { let phases = phases.into_iter().collect::>(); ( @@ -272,7 +272,7 @@ mod builder { environment: Arc, ) -> InitialOperators { let random = environment.random.clone(); - let wrap = |recreate: Arc| Box::new(RecreateInitialOperator::new(recreate)); + let wrap = |recreate: Arc| Box::new(RecreateInitialOperator::new(recreate)); let mut main: InitialOperators<_, _, _> = vec![ (wrap(Arc::new(RecreateWithCheapest::new(random.clone()))), 1), @@ -327,7 +327,7 @@ fn create_diversify_operators( ) -> HeuristicDiversifyOperators { let random = environment.random.clone(); - let recreates: Vec<(Arc, usize)> = vec![ + let recreates: Vec<(Arc, usize)> = vec![ (Arc::new(RecreateWithSkipBest::new(1, 2, random.clone())), 1), (Arc::new(RecreateWithRegret::new(1, 3, random.clone())), 1), (Arc::new(RecreateWithPerturbation::new_with_defaults(random.clone())), 1), @@ -436,7 +436,7 @@ mod statik { } /// Creates default local search operator. - pub fn create_default_local_search(random: Arc) -> TargetSearchOperator { + pub fn create_default_local_search(random: Arc) -> TargetSearchOperator { Arc::new(LocalSearch::new(Arc::new(CompositeLocalOperator::new( vec![ (Arc::new(ExchangeSwapStar::new(random, SINGLE_HEURISTIC_QUOTA_LIMIT)), 200), @@ -455,11 +455,8 @@ mod statik { mod dynamic { use super::*; - fn get_recreates( - problem: &Problem, - random: Arc, - ) -> Vec<(Arc, String)> { - let cheapest: Arc = Arc::new(RecreateWithCheapest::new(random.clone())); + fn get_recreates(problem: &Problem, random: Arc) -> Vec<(Arc, String)> { + let cheapest: Arc = Arc::new(RecreateWithCheapest::new(random.clone())); vec![ (cheapest.clone(), "cheapest".to_string()), (Arc::new(RecreateWithSkipBest::new(1, 2, random.clone())), "skip_best".to_string()), @@ -492,7 +489,7 @@ mod dynamic { environment: Arc, limits: RemovalLimits, prefix: &str, - ) -> Vec<(Arc, String, f64)> { + ) -> Vec<(Arc, String, f64)> { vec![ (Arc::new(AdjustedStringRemoval::new_with_defaults(limits.clone())), format!("{prefix}_asr"), 2.), (Arc::new(NeighbourRemoval::new(limits.clone())), format!("{prefix}_neighbour_removal"), 5.), @@ -578,7 +575,7 @@ mod dynamic { // NOTE we need to wrap any of ruin methods in composite which calls restore context before recreate let ruins = ruins .into_iter() - .map::<(Arc, String, f64), _>(|(ruin, name, weight)| { + .map::<(Arc, String, f64), _>(|(ruin, name, weight)| { (Arc::new(CompositeRuin::new(vec![(ruin, 1.), (extra_random_job.clone(), 0.1)])), name, weight) }) .collect::>(); @@ -648,7 +645,7 @@ mod dynamic { Arc::new(RuinAndRecreate::new(ruin, recreate)) } - pub fn create_default_local_search(random: Arc) -> Arc { + pub fn create_default_local_search(random: Arc) -> Arc { Arc::new(LocalSearch::new(Arc::new(CompositeLocalOperator::new( vec![ (Arc::new(ExchangeSwapStar::new(random, SINGLE_HEURISTIC_QUOTA_LIMIT / 4)), 2), @@ -666,12 +663,12 @@ mod dynamic { fn get_recreate_with_alternative_goal( original_goal: &GoalContext, recreate_fn: F, -) -> impl Iterator> + '_ +) -> impl Iterator> + '_ where T: Recreate + Send + Sync + 'static, F: Fn() -> T + 'static, { - original_goal.get_alternatives().map::, _>(move |goal| { - Arc::new(RecreateWithGoal::new(Arc::new(goal), recreate_fn())) - }) + original_goal + .get_alternatives() + .map::, _>(move |goal| Arc::new(RecreateWithGoal::new(Arc::new(goal), recreate_fn()))) } diff --git a/vrp-core/src/solver/mod.rs b/vrp-core/src/solver/mod.rs index 9a6116ec8..c96851524 100644 --- a/vrp-core/src/solver/mod.rs +++ b/vrp-core/src/solver/mod.rs @@ -193,12 +193,12 @@ impl Stateful for RefinementContext { /// Wraps recreate method as `InitialOperator` pub struct RecreateInitialOperator { - recreate: Arc, + recreate: Arc, } impl RecreateInitialOperator { /// Creates a new instance of `RecreateInitialOperator`. - pub fn new(recreate: Arc) -> Self { + pub fn new(recreate: Arc) -> Self { Self { recreate } } } diff --git a/vrp-core/src/solver/search/infeasible_search.rs b/vrp-core/src/solver/search/infeasible_search.rs index 5401dcddc..a9d1b4145 100644 --- a/vrp-core/src/solver/search/infeasible_search.rs +++ b/vrp-core/src/solver/search/infeasible_search.rs @@ -9,7 +9,7 @@ use std::sync::Arc; /// A mutation operator which performs search in infeasible space. pub struct InfeasibleSearch { inner_search: TargetSearchOperator, - recovery_operator: Arc, + recovery_operator: Arc, max_repeat_count: usize, shuffle_objectives_probability: (f64, f64), skip_constraint_check_probability: (f64, f64), @@ -19,7 +19,7 @@ impl InfeasibleSearch { /// Creates a new instance of `InfeasibleSearch`. pub fn new( inner_search: TargetSearchOperator, - recovery_operator: Arc, + recovery_operator: Arc, max_repeat_count: usize, shuffle_objectives_probability: (f64, f64), skip_constraint_check_probability: (f64, f64), @@ -125,7 +125,7 @@ fn create_relaxed_insertion_ctx( fn create_modified_variant( original: &GoalContext, - random: Arc, + random: Arc, skip_probability: f64, shuffle_probability: f64, ) -> Arc { @@ -156,7 +156,7 @@ fn get_random_individual(new_refinement_ctx: &RefinementContext) -> &InsertionCo struct StochasticFeatureConstraint { inner: Arc, - random: Arc, + random: Arc, probability: f64, } diff --git a/vrp-core/src/solver/search/local/exchange_inter_route.rs b/vrp-core/src/solver/search/local/exchange_inter_route.rs index b5cee8015..9c5b41a9a 100644 --- a/vrp-core/src/solver/search/local/exchange_inter_route.rs +++ b/vrp-core/src/solver/search/local/exchange_inter_route.rs @@ -177,7 +177,7 @@ fn test_job_insertion( route_ctx: &RouteContext, job: &Job, leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> Option { let eval_ctx = EvaluationContext { goal: &insertion_ctx.problem.goal, job, leg_selection, result_selector }; diff --git a/vrp-core/src/solver/search/local/exchange_swap_star.rs b/vrp-core/src/solver/search/local/exchange_swap_star.rs index bdaf52c0f..91e98d5a0 100644 --- a/vrp-core/src/solver/search/local/exchange_swap_star.rs +++ b/vrp-core/src/solver/search/local/exchange_swap_star.rs @@ -24,13 +24,13 @@ use std::iter::once; /// For more details, see `` pub struct ExchangeSwapStar { leg_selection: LegSelection, - result_selector: Box, + result_selector: Box, quota_limit: usize, } impl ExchangeSwapStar { /// Creates a new instance of `ExchangeSwapStar`. - pub fn new(random: Arc, quota_limit: usize) -> Self { + pub fn new(random: Arc, quota_limit: usize) -> Self { Self { leg_selection: LegSelection::Stochastic(random), result_selector: Box::::default(), @@ -77,7 +77,7 @@ impl LocalOperator for ExchangeSwapStar { } /// Encapsulates common data used by search phase. -type SearchContext<'a> = (&'a InsertionContext, &'a LegSelection, &'a (dyn ResultSelector + Send + Sync)); +type SearchContext<'a> = (&'a InsertionContext, &'a LegSelection, &'a (dyn ResultSelector)); fn get_route_by_idx(insertion_ctx: &InsertionContext, route_idx: usize) -> &RouteContext { insertion_ctx.solution.routes.get(route_idx).expect("invalid route index") @@ -293,7 +293,7 @@ fn try_exchange_jobs_in_routes( insertion_ctx: &mut InsertionContext, route_pair: (usize, usize), leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> bool { let quota = insertion_ctx.environment.quota.clone(); let is_quota_reached = move || quota.as_ref().map_or(false, |quota| quota.is_reached()); @@ -374,7 +374,7 @@ fn try_exchange_jobs( insertion_ctx: &mut InsertionContext, insertion_pair: (InsertionResult, InsertionResult), leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) { if let (InsertionResult::Success(outer_success), InsertionResult::Success(inner_success)) = insertion_pair { let constraint = insertion_ctx.problem.goal.clone(); diff --git a/vrp-core/src/solver/search/local/mod.rs b/vrp-core/src/solver/search/local/mod.rs index 6461def5e..a1960fcec 100644 --- a/vrp-core/src/solver/search/local/mod.rs +++ b/vrp-core/src/solver/search/local/mod.rs @@ -22,7 +22,7 @@ mod reschedule_departure; pub use self::reschedule_departure::*; /// Specifies behavior of a local search operator. -pub trait LocalOperator { +pub trait LocalOperator: Send + Sync { /// Applies local search operator to passed solution in order to explore possible /// small move in solution space which leads to a different solution. fn explore(&self, refinement_ctx: &RefinementContext, insertion_ctx: &InsertionContext) @@ -31,14 +31,14 @@ pub trait LocalOperator { /// Provides the way to run multiple local search operators with different probability. pub struct CompositeLocalOperator { - operators: Vec>, + operators: Vec>, weights: Vec, times: (i32, i32), } impl CompositeLocalOperator { /// Creates a new instance of `CompositeLocalOperator`. - pub fn new(operators: Vec<(Arc, usize)>, min: usize, max: usize) -> Self { + pub fn new(operators: Vec<(Arc, usize)>, min: usize, max: usize) -> Self { let weights = operators.iter().map(|(_, weight)| *weight).collect(); let operators = operators.into_iter().map(|(operator, _)| operator).collect(); diff --git a/vrp-core/src/solver/search/local_search.rs b/vrp-core/src/solver/search/local_search.rs index c22301cde..6614100b6 100644 --- a/vrp-core/src/solver/search/local_search.rs +++ b/vrp-core/src/solver/search/local_search.rs @@ -7,12 +7,12 @@ use std::sync::Arc; /// A mutation operator which applies local search principles. pub struct LocalSearch { - operator: Arc, + operator: Arc, } impl LocalSearch { /// Creates a new instance of `LocalSearch`. - pub fn new(operator: Arc) -> Self { + pub fn new(operator: Arc) -> Self { Self { operator } } } diff --git a/vrp-core/src/solver/search/recreate/mod.rs b/vrp-core/src/solver/search/recreate/mod.rs index dade3d9f9..828520333 100644 --- a/vrp-core/src/solver/search/recreate/mod.rs +++ b/vrp-core/src/solver/search/recreate/mod.rs @@ -9,7 +9,7 @@ use std::collections::HashMap; use std::sync::Arc; /// A trait which specifies logic to produce a new feasible solution from partial one. -pub trait Recreate { +pub trait Recreate: Send + Sync { /// Recreates a new solution from the given. fn run(&self, refinement_ctx: &RefinementContext, insertion_ctx: InsertionContext) -> InsertionContext; } @@ -46,13 +46,13 @@ pub use self::recreate_with_slice::RecreateWithSlice; /// Provides the way to run one of multiple recreate methods. pub struct WeightedRecreate { - recreates: Vec>, + recreates: Vec>, weights: Vec, } impl WeightedRecreate { /// Creates a new instance of `WeightedRecreate` using list of recreate strategies. - pub fn new(recreates: Vec<(Arc, usize)>) -> Self { + pub fn new(recreates: Vec<(Arc, usize)>) -> Self { let (recreates, weights) = recreates.into_iter().unzip(); Self { recreates, weights } } @@ -67,8 +67,8 @@ impl Recreate for WeightedRecreate { /// Provides way to reuse generic behaviour. pub struct ConfigurableRecreate { - job_selector: Box, - route_selector: Box, + job_selector: Box, + route_selector: Box, leg_selection: LegSelection, result_selection: ResultSelection, insertion_heuristic: InsertionHeuristic, @@ -77,8 +77,8 @@ pub struct ConfigurableRecreate { impl ConfigurableRecreate { /// Creates a new instance of `ConfigurableRecreate`. pub fn new( - job_selector: Box, - route_selector: Box, + job_selector: Box, + route_selector: Box, leg_selection: LegSelection, result_selection: ResultSelection, insertion_heuristic: InsertionHeuristic, @@ -106,12 +106,12 @@ impl Recreate for ConfigurableRecreate { /// Provides way to use different recreate methods on different selection phases. pub struct PhasedRecreate { - recreates: HashMap>, + recreates: HashMap>, } impl PhasedRecreate { /// Creates a new instance of `PhasedRecreate`. - pub fn new(recreates: HashMap>) -> Self { + pub fn new(recreates: HashMap>) -> Self { assert!([SelectionPhase::Initial, SelectionPhase::Exploration, SelectionPhase::Exploitation] .iter() .all(|key| recreates.contains_key(key))); @@ -126,19 +126,19 @@ impl Recreate for PhasedRecreate { } } -pub(crate) struct RecreateWithGoal { +pub(crate) struct RecreateWithGoal { goal: Arc, inner: T, } -impl RecreateWithGoal { +impl RecreateWithGoal { /// Creates a new instance of `RecreateWithGoal`. pub fn new(goal: Arc, inner: T) -> Self { Self { goal, inner } } } -impl Recreate for RecreateWithGoal { +impl Recreate for RecreateWithGoal { fn run(&self, refinement_ctx: &RefinementContext, insertion_ctx: InsertionContext) -> InsertionContext { let problem = insertion_ctx.problem.clone(); diff --git a/vrp-core/src/solver/search/recreate/recreate_with_blinks.rs b/vrp-core/src/solver/search/recreate/recreate_with_blinks.rs index 6812bd541..5a8449010 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_blinks.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_blinks.rs @@ -62,20 +62,17 @@ impl JobSelector for RankedJobSelector { /// A recreate method as described in "Slack Induction by String Removals for /// Vehicle Routing Problems" (aka SISR) paper by Jan Christiaens, Greet Vanden Berghe. pub struct RecreateWithBlinks { - job_selectors: Vec>, - route_selector: Box, + job_selectors: Vec>, + route_selector: Box, leg_selection: LegSelection, - result_selector: Box, + result_selector: Box, insertion_heuristic: InsertionHeuristic, weights: Vec, } impl RecreateWithBlinks { /// Creates a new instance of `RecreateWithBlinks`. - pub fn new( - selectors: Vec<(Box, usize)>, - random: Arc, - ) -> Self { + pub fn new(selectors: Vec<(Box, usize)>, random: Arc) -> Self { let weights = selectors.iter().map(|(_, weight)| *weight).collect(); Self { job_selectors: selectors.into_iter().map(|(selector, _)| selector).collect(), @@ -88,7 +85,7 @@ impl RecreateWithBlinks { } /// Creates a new instance of `RecreateWithBlinks` with default prameters. - pub fn new_with_defaults(random: Arc) -> Self { + pub fn new_with_defaults(random: Arc) -> Self { Self::new( vec![ (Box::::default(), 10), diff --git a/vrp-core/src/solver/search/recreate/recreate_with_cheapest.rs b/vrp-core/src/solver/search/recreate/recreate_with_cheapest.rs index 11ade9f19..891ae4fba 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_cheapest.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_cheapest.rs @@ -13,7 +13,7 @@ pub struct RecreateWithCheapest { impl RecreateWithCheapest { /// Creates a new instance of `RecreateWithCheapest`. - pub fn new(random: Arc) -> Self { + pub fn new(random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), diff --git a/vrp-core/src/solver/search/recreate/recreate_with_farthest.rs b/vrp-core/src/solver/search/recreate/recreate_with_farthest.rs index dd30f2f67..425bbcb6a 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_farthest.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_farthest.rs @@ -14,7 +14,7 @@ pub struct RecreateWithFarthest { impl RecreateWithFarthest { /// Creates a new instance of `RecreateWithFarthest`. - pub fn new(random: Arc) -> Self { + pub fn new(random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), diff --git a/vrp-core/src/solver/search/recreate/recreate_with_gaps.rs b/vrp-core/src/solver/search/recreate/recreate_with_gaps.rs index a8b3b2a9e..5875a7b93 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_gaps.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_gaps.rs @@ -30,7 +30,7 @@ pub struct RecreateWithGaps { impl RecreateWithGaps { /// Creates a new instance of `RecreateWithGaps`. - pub fn new(min_jobs: usize, max_jobs: usize, random: Arc) -> Self { + pub fn new(min_jobs: usize, max_jobs: usize, random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::new(GapsJobSelector { min_jobs, max_jobs }), diff --git a/vrp-core/src/solver/search/recreate/recreate_with_nearest_neighbor.rs b/vrp-core/src/solver/search/recreate/recreate_with_nearest_neighbor.rs index de6391ee3..538ad3c0b 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_nearest_neighbor.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_nearest_neighbor.rs @@ -12,7 +12,7 @@ pub struct RecreateWithNearestNeighbor { impl RecreateWithNearestNeighbor { /// Creates a new instance of `RecreateWithNearestNeighbor`. - pub fn new(random: Arc) -> Self { + pub fn new(random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), diff --git a/vrp-core/src/solver/search/recreate/recreate_with_perturbation.rs b/vrp-core/src/solver/search/recreate/recreate_with_perturbation.rs index 3fb0db880..c3034d040 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_perturbation.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_perturbation.rs @@ -13,7 +13,7 @@ pub struct RecreateWithPerturbation { impl RecreateWithPerturbation { /// Creates a new instance of `RecreateWithPerturbation`. - pub fn new(noise: Noise, random: Arc) -> Self { + pub fn new(noise: Noise, random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), @@ -26,7 +26,7 @@ impl RecreateWithPerturbation { } /// Creates a new instance of `RecreateWithPerturbation` with default values. - pub fn new_with_defaults(random: Arc) -> Self { + pub fn new_with_defaults(random: Arc) -> Self { Self::new(Noise::new_with_ratio(0.05, (-0.25, 0.25), random.clone()), random) } } diff --git a/vrp-core/src/solver/search/recreate/recreate_with_regret.rs b/vrp-core/src/solver/search/recreate/recreate_with_regret.rs index 1e4e55175..52599be85 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_regret.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_regret.rs @@ -22,7 +22,7 @@ impl Recreate for RecreateWithRegret { impl RecreateWithRegret { /// Creates a new instance of `RecreateWithRegret`. - pub fn new(min: usize, max: usize, random: Arc) -> Self { + pub fn new(min: usize, max: usize, random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), @@ -58,7 +58,7 @@ impl InsertionEvaluator for RegretInsertionEvaluator { job: &Job, routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { self.fallback_evaluator.evaluate_job(insertion_ctx, job, routes, leg_selection, result_selector) } @@ -69,7 +69,7 @@ impl InsertionEvaluator for RegretInsertionEvaluator { route_ctx: &RouteContext, jobs: &[&Job], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { self.fallback_evaluator.evaluate_route(insertion_ctx, route_ctx, jobs, leg_selection, result_selector) } @@ -80,7 +80,7 @@ impl InsertionEvaluator for RegretInsertionEvaluator { jobs: &[&Job], routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { let regret_index = insertion_ctx.environment.random.uniform_int(self.min as i32, self.max as i32) as usize; diff --git a/vrp-core/src/solver/search/recreate/recreate_with_skip_best.rs b/vrp-core/src/solver/search/recreate/recreate_with_skip_best.rs index 7c75b15fa..df29a5f83 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_skip_best.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_skip_best.rs @@ -20,7 +20,7 @@ impl Recreate for RecreateWithSkipBest { impl RecreateWithSkipBest { /// Creates a new instance of `RecreateWithSkipBest`. - pub fn new(min: usize, max: usize, random: Arc) -> Self { + pub fn new(min: usize, max: usize, random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), @@ -56,7 +56,7 @@ impl InsertionEvaluator for SkipBestInsertionEvaluator { job: &Job, routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { self.fallback_evaluator.evaluate_job(insertion_ctx, job, routes, leg_selection, result_selector) } @@ -67,7 +67,7 @@ impl InsertionEvaluator for SkipBestInsertionEvaluator { route_ctx: &RouteContext, jobs: &[&Job], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { self.fallback_evaluator.evaluate_route(insertion_ctx, route_ctx, jobs, leg_selection, result_selector) } @@ -78,7 +78,7 @@ impl InsertionEvaluator for SkipBestInsertionEvaluator { jobs: &[&Job], routes: &[&RouteContext], leg_selection: &LegSelection, - result_selector: &(dyn ResultSelector + Send + Sync), + result_selector: &(dyn ResultSelector), ) -> InsertionResult { let skip_index = insertion_ctx.environment.random.uniform_int(self.min as i32, self.max as i32); diff --git a/vrp-core/src/solver/search/recreate/recreate_with_skip_random.rs b/vrp-core/src/solver/search/recreate/recreate_with_skip_random.rs index 2dc1cb470..c13a8d888 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_skip_random.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_skip_random.rs @@ -14,7 +14,7 @@ pub struct RecreateWithSkipRandom { impl RecreateWithSkipRandom { /// Creates a new instance of `RecreateWithSkipRandom`. - pub fn new(random: Arc) -> Self { + pub fn new(random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), @@ -35,10 +35,7 @@ impl Recreate for RecreateWithSkipRandom { impl RecreateWithSkipRandom { /// Creates `RecreateWithSkipRandom` as `PhasedRecreate` which runs only in exploration phase. - pub fn default_explorative_phased( - default_recreate: Arc, - random: Arc, - ) -> PhasedRecreate { + pub fn default_explorative_phased(default_recreate: Arc, random: Arc) -> PhasedRecreate { let recreates = vec![ (SelectionPhase::Initial, default_recreate.clone()), (SelectionPhase::Exploration, Arc::new(RecreateWithSkipRandom::new(random))), diff --git a/vrp-core/src/solver/search/recreate/recreate_with_slice.rs b/vrp-core/src/solver/search/recreate/recreate_with_slice.rs index 1c20e9ba4..dda37b3e1 100644 --- a/vrp-core/src/solver/search/recreate/recreate_with_slice.rs +++ b/vrp-core/src/solver/search/recreate/recreate_with_slice.rs @@ -14,7 +14,7 @@ pub struct RecreateWithSlice { impl RecreateWithSlice { /// Creates a new instance of `RecreateWithSlice`. - pub fn new(random: Arc) -> Self { + pub fn new(random: Arc) -> Self { Self { recreate: ConfigurableRecreate::new( Box::::default(), diff --git a/vrp-core/src/solver/search/redistribute_search.rs b/vrp-core/src/solver/search/redistribute_search.rs index 46075c46a..35eda4ca1 100644 --- a/vrp-core/src/solver/search/redistribute_search.rs +++ b/vrp-core/src/solver/search/redistribute_search.rs @@ -17,12 +17,12 @@ use std::sync::Arc; /// the same routes again. /// The main idea is to introduce a bit more diversity in the population. pub struct RedistributeSearch { - recreate: Arc, + recreate: Arc, } impl RedistributeSearch { /// Creates a new instance of `RedistributeSearch`. - pub fn new(recreate: Arc) -> Self { + pub fn new(recreate: Arc) -> Self { Self { recreate } } } diff --git a/vrp-core/src/solver/search/ruin/adjusted_string_removal.rs b/vrp-core/src/solver/search/ruin/adjusted_string_removal.rs index cd44facec..4207cd386 100644 --- a/vrp-core/src/solver/search/ruin/adjusted_string_removal.rs +++ b/vrp-core/src/solver/search/ruin/adjusted_string_removal.rs @@ -41,7 +41,7 @@ impl AdjustedStringRemoval { } /// Calculates initial parameters from paper using 5,6,7 equations. - fn calculate_limits(&self, routes: &[RouteContext], random: &Arc) -> (usize, usize) { + fn calculate_limits(&self, routes: &[RouteContext], random: &Arc) -> (usize, usize) { // Equation 5: max removed string cardinality for each tour let lsmax = calculate_average_tour_cardinality(routes).min(self.lmax as f64); @@ -115,7 +115,7 @@ fn select_string<'a>( seed_tour: (&'a Tour, usize), cardinality: usize, alpha: f64, - random: &Arc, + random: &Arc, ) -> JobIter<'a> { if random.is_head_not_tails() { sequential_string(seed_tour, cardinality, random) @@ -125,11 +125,7 @@ fn select_string<'a>( } /// Selects sequential string. -fn sequential_string<'a>( - seed_tour: (&'a Tour, usize), - cardinality: usize, - random: &Arc, -) -> JobIter<'a> { +fn sequential_string<'a>(seed_tour: (&'a Tour, usize), cardinality: usize, random: &Arc) -> JobIter<'a> { let (begin, end) = lower_bounds(cardinality, seed_tour.0.job_activity_count(), seed_tour.1); let start = random.uniform_int(begin as i32, end as i32) as usize; @@ -141,7 +137,7 @@ fn preserved_string<'a>( seed_tour: (&'a Tour, usize), cardinality: usize, alpha: f64, - random: &Arc, + random: &Arc, ) -> JobIter<'a> { let size = seed_tour.0.job_activity_count(); let index = seed_tour.1; @@ -180,12 +176,7 @@ fn lower_bounds(string_crd: usize, tour_crd: usize, index: usize) -> (usize, usi } /// Calculates preserved substring cardinality. -fn preserved_cardinality( - string_crd: usize, - tour_crd: usize, - alpha: f64, - random: &Arc, -) -> usize { +fn preserved_cardinality(string_crd: usize, tour_crd: usize, alpha: f64, random: &Arc) -> usize { if string_crd == tour_crd { return 0; } diff --git a/vrp-core/src/solver/search/ruin/mod.rs b/vrp-core/src/solver/search/ruin/mod.rs index 8b2a2ceef..6482e8304 100644 --- a/vrp-core/src/solver/search/ruin/mod.rs +++ b/vrp-core/src/solver/search/ruin/mod.rs @@ -10,7 +10,7 @@ use std::ops::Range; use std::sync::Arc; /// A trait which specifies logic to destroy parts of solution. -pub trait Ruin { +pub trait Ruin: Send + Sync { /// Ruins given solution and returns a new one with less jobs assigned. fn run(&self, refinement_ctx: &RefinementContext, insertion_ctx: InsertionContext) -> InsertionContext; } @@ -34,7 +34,7 @@ mod worst_jobs_removal; pub use self::worst_jobs_removal::WorstJobRemoval; /// A type which specifies a group of multiple ruin strategies with their probability. -pub type RuinGroup = (Vec<(Arc, f64)>, usize); +pub type RuinGroup = (Vec<(Arc, f64)>, usize); /// Provides the way to pick one ruin from the group ruin methods. pub struct WeightedRuin { @@ -83,12 +83,12 @@ impl Ruin for WeightedRuin { /// Provides the way to run multiple ruin methods one by one on the same solution. pub struct CompositeRuin { - ruins: Vec<(Arc, f64)>, + ruins: Vec<(Arc, f64)>, } impl CompositeRuin { /// Creates a new instance of `CompositeRuin` using list of ruin strategies. - pub fn new(ruins: Vec<(Arc, f64)>) -> Self { + pub fn new(ruins: Vec<(Arc, f64)>) -> Self { Self { ruins } } } diff --git a/vrp-core/src/solver/search/ruin/route_removal.rs b/vrp-core/src/solver/search/ruin/route_removal.rs index 016b0760c..695fd4f71 100644 --- a/vrp-core/src/solver/search/ruin/route_removal.rs +++ b/vrp-core/src/solver/search/ruin/route_removal.rs @@ -139,7 +139,7 @@ impl Ruin for WorstRouteRemoval { fn remove_routes_with_actors( solution_ctx: &mut SolutionContext, limits: &RemovalLimits, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), actors: Iter, ) where Iter: Iterator>, diff --git a/vrp-core/src/solver/search/ruin/worst_jobs_removal.rs b/vrp-core/src/solver/search/ruin/worst_jobs_removal.rs index d0503ade4..595b3d955 100644 --- a/vrp-core/src/solver/search/ruin/worst_jobs_removal.rs +++ b/vrp-core/src/solver/search/ruin/worst_jobs_removal.rs @@ -114,7 +114,7 @@ fn get_cost_savings( start: &Activity, middle: &Activity, end: &Activity, - transport: &Arc, + transport: &Arc, ) -> Cost { let actor = route.actor.as_ref(); @@ -128,6 +128,6 @@ fn get_cost_savings( } #[inline(always)] -fn get_cost(route: &Route, from: &Activity, to: &Activity, transport: &Arc) -> Cost { +fn get_cost(route: &Route, from: &Activity, to: &Activity, transport: &Arc) -> Cost { transport.cost(route, from.place.location, to.place.location, TravelTime::Departure(from.schedule.departure)) } diff --git a/vrp-core/src/solver/search/ruin_recreate.rs b/vrp-core/src/solver/search/ruin_recreate.rs index b7bd73bdb..80ab155b2 100644 --- a/vrp-core/src/solver/search/ruin_recreate.rs +++ b/vrp-core/src/solver/search/ruin_recreate.rs @@ -7,13 +7,13 @@ use std::sync::Arc; /// A mutation operator based on ruin and recreate principle. pub struct RuinAndRecreate { - ruin: Arc, - recreate: Arc, + ruin: Arc, + recreate: Arc, } impl RuinAndRecreate { /// Creates a new instance of `RuinAndRecreate` using given ruin and recreate methods. - pub fn new(ruin: Arc, recreate: Arc) -> Self { + pub fn new(ruin: Arc, recreate: Arc) -> Self { Self { ruin, recreate } } } diff --git a/vrp-core/src/solver/search/utils/removal.rs b/vrp-core/src/solver/search/utils/removal.rs index 6dd1dcfc1..9aa3fd7bf 100644 --- a/vrp-core/src/solver/search/utils/removal.rs +++ b/vrp-core/src/solver/search/utils/removal.rs @@ -21,7 +21,7 @@ pub struct JobRemovalTracker { impl JobRemovalTracker { /// Creates a new instance of `JobRemoval`. - pub fn new(limits: &RemovalLimits, random: &(dyn Random + Send + Sync)) -> Self { + pub fn new(limits: &RemovalLimits, random: &(dyn Random)) -> Self { Self { activities_left: random .uniform_int(limits.removed_activities_range.start as i32, limits.removed_activities_range.end as i32), @@ -81,7 +81,7 @@ impl JobRemovalTracker { &mut self, solution: &mut SolutionContext, route_idx: usize, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), ) -> bool { if self.routes_left == 0 || self.activities_left == 0 { return false; @@ -96,12 +96,7 @@ impl JobRemovalTracker { } } - fn can_remove_full_route( - &self, - solution: &SolutionContext, - route_idx: usize, - random: &(dyn Random + Send + Sync), - ) -> bool { + fn can_remove_full_route(&self, solution: &SolutionContext, route_idx: usize, random: &(dyn Random)) -> bool { let route_ctx = solution.routes.get(route_idx).expect("invalid route index"); // check locked jobs @@ -148,7 +143,7 @@ impl JobRemovalTracker { &mut self, solution: &mut SolutionContext, route_idx: usize, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), ) -> bool { let locked = solution.locked.clone(); let route_ctx = solution.routes.get(route_idx).expect("invalid route index"); diff --git a/vrp-core/src/solver/search/utils/selection.rs b/vrp-core/src/solver/search/utils/selection.rs index 31cb3a27d..b670aaf79 100644 --- a/vrp-core/src/solver/search/utils/selection.rs +++ b/vrp-core/src/solver/search/utils/selection.rs @@ -44,7 +44,7 @@ pub(crate) fn select_seed_job_with_tabu_list( /// Selects seed job from existing solution pub(crate) fn select_seed_job( routes: &[RouteContext], - random: &(dyn Random + Send + Sync), + random: &(dyn Random), route_filter: &(dyn Fn(&RouteContext) -> bool), job_filter: &(dyn Fn(&Job) -> bool), ) -> Option<(Profile, usize, Job)> { @@ -76,7 +76,7 @@ pub(crate) fn select_seed_job( fn select_random_job( route_ctx: &RouteContext, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), job_filter: &(dyn Fn(&Job) -> bool), ) -> Option { let size = route_ctx.route().tour.job_activity_count(); diff --git a/vrp-core/src/solver/search/utils/tabu_list.rs b/vrp-core/src/solver/search/utils/tabu_list.rs index e506d8e12..96762b670 100644 --- a/vrp-core/src/solver/search/utils/tabu_list.rs +++ b/vrp-core/src/solver/search/utils/tabu_list.rs @@ -15,7 +15,7 @@ pub struct TabuList { jobs: HashSet, max_actors: usize, max_jobs: usize, - random: Arc, + random: Arc, } impl TabuList { @@ -77,7 +77,7 @@ fn add_with_limits( new_item: T, old_items: &mut HashSet, limits: usize, - random: &(dyn Random + Send + Sync), + random: &(dyn Random), ) { // NOTE do not use tabu list when limit is zero if limits == 0 { diff --git a/vrp-core/src/solver/search/utils/termination.rs b/vrp-core/src/solver/search/utils/termination.rs index 05a6d9f84..b5947fabb 100644 --- a/vrp-core/src/solver/search/utils/termination.rs +++ b/vrp-core/src/solver/search/utils/termination.rs @@ -3,7 +3,7 @@ use rosomaxa::utils::*; use std::sync::Arc; struct CompositeTimeQuota { - inner: Arc, + inner: Arc, limit: usize, timer: Timer, } diff --git a/vrp-core/tests/helpers/models/domain.rs b/vrp-core/tests/helpers/models/domain.rs index 7308015bb..5300d7c4c 100644 --- a/vrp-core/tests/helpers/models/domain.rs +++ b/vrp-core/tests/helpers/models/domain.rs @@ -4,7 +4,7 @@ use crate::models::problem::JobIdDimension; use crate::prelude::*; use std::sync::Arc; -pub fn test_random() -> Arc { +pub fn test_random() -> Arc { Arc::new(DefaultRandom::default()) } diff --git a/vrp-core/tests/helpers/solver/mod.rs b/vrp-core/tests/helpers/solver/mod.rs index 672ccfd9d..dbc798ec7 100644 --- a/vrp-core/tests/helpers/solver/mod.rs +++ b/vrp-core/tests/helpers/solver/mod.rs @@ -104,11 +104,7 @@ pub fn generate_matrix_routes( rows: usize, cols: usize, is_open_vrp: bool, - goal_factory: impl FnOnce( - Arc, - Arc, - &Extras, - ) -> GoalContext, + goal_factory: impl FnOnce(Arc, Arc, &Extras) -> GoalContext, job_factory: impl Fn(&str, Option) -> Arc, vehicle_modify: impl Fn(Vehicle) -> Vehicle, matrix_modify: impl Fn(Vec) -> (Vec, Vec), diff --git a/vrp-core/tests/helpers/utils/mod.rs b/vrp-core/tests/helpers/utils/mod.rs index 54b1e470a..412c96b5f 100644 --- a/vrp-core/tests/helpers/utils/mod.rs +++ b/vrp-core/tests/helpers/utils/mod.rs @@ -3,6 +3,6 @@ use std::sync::Arc; pub mod random; -pub fn create_test_environment_with_random(random: Arc) -> Arc { +pub fn create_test_environment_with_random(random: Arc) -> Arc { Arc::new(Environment { random, ..Default::default() }) } diff --git a/vrp-core/tests/unit/construction/clustering/dbscan_test.rs b/vrp-core/tests/unit/construction/clustering/dbscan_test.rs index 55ef1db23..09b19ac69 100644 --- a/vrp-core/tests/unit/construction/clustering/dbscan_test.rs +++ b/vrp-core/tests/unit/construction/clustering/dbscan_test.rs @@ -19,11 +19,7 @@ fn can_get_max_curvature() { assert_eq!(get_max_curvature(values), 2.); } -fn goal_factory( - _: Arc, - _: Arc, - _: &Extras, -) -> GoalContext { +fn goal_factory(_: Arc, _: Arc, _: &Extras) -> GoalContext { TestGoalContextBuilder::with_transport_feature().build() } @@ -119,7 +115,7 @@ fn can_create_job_clusters_impl(param: (usize, f64), expected: &[Vec]) |v| v, |_| (vec![0.; 64], create_test_distances()), ); - let random: Arc = Arc::new(FakeRandom::new(vec![0, 0], vec![epsilon])); + let random: Arc = Arc::new(FakeRandom::new(vec![0, 0], vec![epsilon])); let clusters = create_job_clusters(&problem, random.as_ref(), Some(min_points), Some(epsilon)) .iter() diff --git a/vrp-core/tests/unit/models/problem/jobs_test.rs b/vrp-core/tests/unit/models/problem/jobs_test.rs index 96f948aab..d86723687 100644 --- a/vrp-core/tests/unit/models/problem/jobs_test.rs +++ b/vrp-core/tests/unit/models/problem/jobs_test.rs @@ -78,7 +78,7 @@ impl TransportCost for FixedTransportCost { } impl FixedTransportCost { - pub fn new_shared(duration_cost: f64, distance_cost: f64) -> Arc { + pub fn new_shared(duration_cost: f64, distance_cost: f64) -> Arc { Arc::new(Self { duration_cost, distance_cost }) } } @@ -240,7 +240,7 @@ can_handle_negative_distances_durations! { case04: (-1., 0.), } -fn can_handle_negative_distances_durations_impl(transport_costs: Arc) { +fn can_handle_negative_distances_durations_impl(transport_costs: Arc) { let profile = Profile::default(); let species = vec![ TestSingleBuilder::default().id("s0").location(Some(0)).build_as_job_ref(), diff --git a/vrp-pragmatic/src/format/problem/fleet_reader.rs b/vrp-pragmatic/src/format/problem/fleet_reader.rs index 855c5f30e..797789627 100644 --- a/vrp-pragmatic/src/format/problem/fleet_reader.rs +++ b/vrp-pragmatic/src/format/problem/fleet_reader.rs @@ -27,7 +27,7 @@ pub(super) fn create_transport_costs( api_problem: &ApiProblem, matrices: &[Matrix], coord_index: Arc, -) -> Result, GenericError> { +) -> GenericResult> { if !matrices.iter().all(|m| m.profile.is_some()) && !matrices.iter().all(|m| m.profile.is_none()) { return Err("all matrices should have profile set or none of them".into()); } diff --git a/vrp-pragmatic/src/format/problem/goal_reader.rs b/vrp-pragmatic/src/format/problem/goal_reader.rs index 292bf40f1..238a110d2 100644 --- a/vrp-pragmatic/src/format/problem/goal_reader.rs +++ b/vrp-pragmatic/src/format/problem/goal_reader.rs @@ -385,7 +385,7 @@ fn create_capacity_with_reload_feature, + transport: Arc, ) -> GenericResult { let (distances, durations) = api_problem .fleet @@ -423,7 +423,7 @@ fn get_tour_limit_feature( fn get_recharge_feature( name: &str, api_problem: &ApiProblem, - transport: Arc, + transport: Arc, ) -> GenericResult { fn is_recharge_single(single: &Single) -> bool { single.dimens.get_job_type().map_or(false, |job_type| job_type == "recharge") diff --git a/vrp-pragmatic/src/format/problem/job_reader.rs b/vrp-pragmatic/src/format/problem/job_reader.rs index 9b42cae8e..5714d6a0d 100644 --- a/vrp-pragmatic/src/format/problem/job_reader.rs +++ b/vrp-pragmatic/src/format/problem/job_reader.rs @@ -30,7 +30,7 @@ pub(super) fn read_jobs_with_extra_locks( fleet: &Fleet, transport: &(dyn TransportCost + Sync + Send), job_index: &mut JobIndex, - random: &Arc, + random: &Arc, ) -> (Jobs, Vec>) { let (mut jobs, mut locks) = read_required_jobs(api_problem, props, coord_index, job_index, random); let (conditional_jobs, conditional_locks) = read_conditional_jobs(api_problem, coord_index, job_index); @@ -108,7 +108,7 @@ fn read_required_jobs( props: &ProblemProperties, coord_index: &CoordIndex, job_index: &mut JobIndex, - random: &Arc, + random: &Arc, ) -> (Vec, Vec>) { let mut jobs = vec![]; let has_multi_dimens = props.has_multi_dimen_capacity; @@ -439,12 +439,7 @@ fn get_single_job(job: &ApiJob, single: Single) -> Job { Job::Single(Arc::new(single)) } -fn get_multi_job( - job: &ApiJob, - singles: Vec, - deliveries_start_index: usize, - random: &Arc, -) -> Job { +fn get_multi_job(job: &ApiJob, singles: Vec, deliveries_start_index: usize, random: &Arc) -> Job { let mut dimens: Dimensions = Default::default(); fill_dimens(job, &mut dimens); diff --git a/vrp-pragmatic/src/format/problem/mod.rs b/vrp-pragmatic/src/format/problem/mod.rs index 2a5caef7e..918647fdb 100644 --- a/vrp-pragmatic/src/format/problem/mod.rs +++ b/vrp-pragmatic/src/format/problem/mod.rs @@ -120,8 +120,8 @@ struct ProblemBlocks { jobs: Arc, fleet: Arc, job_index: Option>, - transport: Arc, - activity: Arc, + transport: Arc, + activity: Arc, locks: Vec>, reserved_times_index: ReservedTimesIndex, } diff --git a/vrp-pragmatic/src/format/problem/problem_reader.rs b/vrp-pragmatic/src/format/problem/problem_reader.rs index 33c895d42..0c535f16a 100644 --- a/vrp-pragmatic/src/format/problem/problem_reader.rs +++ b/vrp-pragmatic/src/format/problem/problem_reader.rs @@ -193,7 +193,7 @@ fn get_problem_blocks( format!("check matrix routing data: '{err}'"), )] })?; - let activity: Arc = Arc::new(OnlyVehicleActivityCost::default()); + let activity: Arc = Arc::new(OnlyVehicleActivityCost::default()); let (transport, activity) = if reserved_times_index.is_empty() { (transport, activity) @@ -209,14 +209,14 @@ fn get_problem_blocks( format!("check fleet definition: '{err}'"), )] }) - .map::<(Arc, Arc), _>( - |(transport, activity)| (Arc::new(transport), Arc::new(activity)), - )? + .map::<(Arc, Arc), _>(|(transport, activity)| { + (Arc::new(transport), Arc::new(activity)) + })? }; // TODO pass random from outside as there might be need to have it initialized with seed // at the moment, this random instance is used only by multi job permutation generator - let random: Arc = Arc::new(DefaultRandom::default()); + let random: Arc = Arc::new(DefaultRandom::default()); let (jobs, locks) = read_jobs_with_extra_locks( api_problem, problem_props, diff --git a/vrp-pragmatic/src/format/solution/initial_reader.rs b/vrp-pragmatic/src/format/solution/initial_reader.rs index 028b5a73a..6b78b01a5 100644 --- a/vrp-pragmatic/src/format/solution/initial_reader.rs +++ b/vrp-pragmatic/src/format/solution/initial_reader.rs @@ -26,7 +26,7 @@ type ActorKey = (String, String, usize); pub fn read_init_solution( solution: BufReader, problem: Arc, - random: Arc, + random: Arc, ) -> Result { let solution = deserialize_solution(solution).map_err(|err| format!("cannot deserialize solution: {err}"))?; diff --git a/vrp-pragmatic/tests/helpers/solution.rs b/vrp-pragmatic/tests/helpers/solution.rs index a04e4fa82..45b3df354 100644 --- a/vrp-pragmatic/tests/helpers/solution.rs +++ b/vrp-pragmatic/tests/helpers/solution.rs @@ -461,14 +461,14 @@ pub fn get_ids_from_tour_sorted(tour: &Tour) -> Vec> { ids } -pub fn create_random() -> Arc { +pub fn create_random() -> Arc { Arc::new(DefaultRandom::default()) } pub fn to_core_solution( solution: &Solution, core_problem: Arc, - random: Arc, + random: Arc, ) -> Result { let mut writer = BufWriter::new(Vec::new()); serialize_solution(solution, &mut writer).expect("cannot serialize test solution"); diff --git a/vrp-scientific/src/common/initial_reader.rs b/vrp-scientific/src/common/initial_reader.rs index f38a34e6c..bd454c919 100644 --- a/vrp-scientific/src/common/initial_reader.rs +++ b/vrp-scientific/src/common/initial_reader.rs @@ -16,7 +16,7 @@ use vrp_core::prelude::*; pub fn read_init_solution( mut reader: BufReader, problem: Arc, - random: Arc, + random: Arc, ) -> Result { let mut buffer = String::new(); diff --git a/vrp-scientific/src/common/routing.rs b/vrp-scientific/src/common/routing.rs index 0068b1b89..7580f0533 100644 --- a/vrp-scientific/src/common/routing.rs +++ b/vrp-scientific/src/common/routing.rs @@ -31,7 +31,7 @@ impl CoordIndex { } /// Creates transport. - pub fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { + pub fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { let matrix_values = self .locations .iter() diff --git a/vrp-scientific/src/common/text_reader.rs b/vrp-scientific/src/common/text_reader.rs index 1aa6cfa74..55d19dbb4 100644 --- a/vrp-scientific/src/common/text_reader.rs +++ b/vrp-scientific/src/common/text_reader.rs @@ -31,12 +31,12 @@ pub(crate) trait TextReader { fn create_goal_context( &self, activity: Arc, - transport: Arc, + transport: Arc, ) -> Result; fn read_definitions(&mut self) -> Result<(Vec, Fleet), GenericError>; - fn create_transport(&self, is_rounded: bool) -> Result, GenericError>; + fn create_transport(&self, is_rounded: bool) -> Result, GenericError>; fn create_extras(&self) -> Extras; } @@ -104,7 +104,7 @@ pub(crate) fn create_dimens_with_id( pub(crate) fn create_goal_context_prefer_min_tours( activity: Arc, - transport: Arc, + transport: Arc, is_time_constrained: bool, ) -> GenericResult { let features = get_essential_features(activity, transport, is_time_constrained)?; @@ -117,7 +117,7 @@ pub(crate) fn create_goal_context_prefer_min_tours( pub(crate) fn create_goal_context_distance_only( activity: Arc, - transport: Arc, + transport: Arc, is_time_constrained: bool, ) -> Result { let features = get_essential_features(activity, transport, is_time_constrained)?; @@ -130,7 +130,7 @@ pub(crate) fn create_goal_context_distance_only( fn get_essential_features( activity: Arc, - transport: Arc, + transport: Arc, is_time_constrained: bool, ) -> Result, GenericError> { Ok(vec![ diff --git a/vrp-scientific/src/lilim/reader.rs b/vrp-scientific/src/lilim/reader.rs index b5a7025be..639793095 100644 --- a/vrp-scientific/src/lilim/reader.rs +++ b/vrp-scientific/src/lilim/reader.rs @@ -61,7 +61,7 @@ impl TextReader for LilimReader { fn create_goal_context( &self, activity: Arc, - transport: Arc, + transport: Arc, ) -> Result { let is_time_constrained = true; create_goal_context_prefer_min_tours(activity, transport, is_time_constrained) @@ -74,7 +74,7 @@ impl TextReader for LilimReader { Ok((jobs, fleet)) } - fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { + fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { self.coord_index.create_transport(is_rounded) } diff --git a/vrp-scientific/src/solomon/reader.rs b/vrp-scientific/src/solomon/reader.rs index 442e32f07..5f6fed428 100644 --- a/vrp-scientific/src/solomon/reader.rs +++ b/vrp-scientific/src/solomon/reader.rs @@ -57,7 +57,7 @@ impl TextReader for SolomonReader { fn create_goal_context( &self, activity: Arc, - transport: Arc, + transport: Arc, ) -> Result { let is_time_constrained = true; create_goal_context_prefer_min_tours(activity, transport, is_time_constrained) @@ -70,7 +70,7 @@ impl TextReader for SolomonReader { Ok((jobs, fleet)) } - fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { + fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { self.coord_index.create_transport(is_rounded) } diff --git a/vrp-scientific/src/tsplib/reader.rs b/vrp-scientific/src/tsplib/reader.rs index c25cf6560..7f028c2ea 100644 --- a/vrp-scientific/src/tsplib/reader.rs +++ b/vrp-scientific/src/tsplib/reader.rs @@ -42,7 +42,7 @@ impl TextReader for TsplibReader { fn create_goal_context( &self, activity: Arc, - transport: Arc, + transport: Arc, ) -> Result { let is_time_constrained = false; create_goal_context_distance_only(activity, transport, is_time_constrained) @@ -81,7 +81,7 @@ impl TextReader for TsplibReader { Ok((jobs, fleet)) } - fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { + fn create_transport(&self, is_rounded: bool) -> Result, GenericError> { self.coord_index.create_transport(is_rounded) }