From 911a3830145349cb03af0b5135e823a6b6bffa26 Mon Sep 17 00:00:00 2001 From: reinterpretcat Date: Thu, 9 May 2024 23:36:45 +0200 Subject: [PATCH] Change ruin limits --- vrp-core/src/solver/heuristic.rs | 22 +++++++++++-------- vrp-core/src/solver/search/ruin/mod.rs | 2 +- .../src/solver/search/ruin/route_removal.rs | 6 +++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/vrp-core/src/solver/heuristic.rs b/vrp-core/src/solver/heuristic.rs index 9b11b94c1..f7fc53762 100644 --- a/vrp-core/src/solver/heuristic.rs +++ b/vrp-core/src/solver/heuristic.rs @@ -555,20 +555,21 @@ mod dynamic { problem: Arc, environment: Arc, limits: RemovalLimits, + prefix: &str, ) -> Vec<(Arc, String, f64)> { vec![ - (Arc::new(AdjustedStringRemoval::new_with_defaults(limits.clone())), "asr".to_string(), 2.), - (Arc::new(NeighbourRemoval::new(limits.clone())), "neighbour_removal".to_string(), 5.), + (Arc::new(AdjustedStringRemoval::new_with_defaults(limits.clone())), format!("{prefix}_asr"), 2.), + (Arc::new(NeighbourRemoval::new(limits.clone())), format!("{prefix}_neighbour_removal"), 5.), ( Arc::new(ClusterRemoval::new_with_defaults(problem.clone(), environment)), - "cluster_removal".to_string(), + format!("{prefix}_cluster_removal"), 4., ), - (Arc::new(WorstJobRemoval::new(4, limits.clone())), "worst_job".to_string(), 4.), - (Arc::new(RandomJobRemoval::new(limits.clone())), "random_job_removal".to_string(), 4.), - (Arc::new(RandomRouteRemoval::new(limits.clone())), "random_route_removal".to_string(), 2.), - (Arc::new(CloseRouteRemoval::new(limits.clone())), "close_route_removal".to_string(), 4.), - (Arc::new(WorstRouteRemoval::new(limits)), "worst_route_removal".to_string(), 5.), + (Arc::new(WorstJobRemoval::new(4, limits.clone())), format!("{prefix}_worst_job"), 4.), + (Arc::new(RandomJobRemoval::new(limits.clone())), format!("{prefix}_random_job_removal"), 4.), + (Arc::new(RandomRouteRemoval::new(limits.clone())), format!("{prefix}_random_route_removal"), 2.), + (Arc::new(CloseRouteRemoval::new(limits.clone())), format!("{prefix}_close_route_removal"), 4.), + (Arc::new(WorstRouteRemoval::new(limits)), format!("{prefix}_worst_route_removal"), 5.), ] } @@ -633,7 +634,10 @@ mod dynamic { // NOTE: consider checking usage of names within heuristic filter before changing them let recreates = get_recreates(problem.as_ref(), random.clone()); - let ruins = get_ruins(problem.clone(), environment.clone(), normal_limits.clone()); + let ruins = get_ruins(problem.clone(), environment.clone(), normal_limits.clone(), "normal") + .into_iter() + .chain(get_ruins(problem.clone(), environment.clone(), small_limits.clone(), "small").into_iter()) + .collect::>(); let extra_random_job = Arc::new(RandomJobRemoval::new(small_limits)); diff --git a/vrp-core/src/solver/search/ruin/mod.rs b/vrp-core/src/solver/search/ruin/mod.rs index c0ee795db..8b2a2ceef 100644 --- a/vrp-core/src/solver/search/ruin/mod.rs +++ b/vrp-core/src/solver/search/ruin/mod.rs @@ -57,7 +57,7 @@ impl RemovalLimits { let jobs_size = problem.jobs.size() as f64; let min_activities = ((jobs_size * 0.05) as usize).clamp(1, 8); - let max_activities = ((jobs_size * 0.5) as usize).clamp(8, 48); + let max_activities = ((jobs_size * 0.5) as usize).clamp(8, 32); Self { removed_activities_range: min_activities..max_activities, affected_routes_range: 2..5 } } diff --git a/vrp-core/src/solver/search/ruin/route_removal.rs b/vrp-core/src/solver/search/ruin/route_removal.rs index 847b0a74d..016b0760c 100644 --- a/vrp-core/src/solver/search/ruin/route_removal.rs +++ b/vrp-core/src/solver/search/ruin/route_removal.rs @@ -44,8 +44,10 @@ pub struct CloseRouteRemoval { impl CloseRouteRemoval { /// Creates a new instance of `CloseRouteRemoval`. - pub fn new(limits: RemovalLimits) -> Self { - assert!(limits.affected_routes_range.start > 1); + pub fn new(mut limits: RemovalLimits) -> Self { + limits.affected_routes_range.start = limits.affected_routes_range.start.max(2); + limits.affected_routes_range.end = limits.affected_routes_range.end.max(3); + Self { limits } } }