diff --git a/Dockerfile b/Dockerfile index bab679044..96236c46c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.72-alpine AS Builder +FROM rust:1.73-alpine AS Builder LABEL maintainer="Ilya Builuk " \ org.opencontainers.image.title="A Vehicle Routing Problem solver CLI" \ diff --git a/experiments/heuristic-research/src/plots/mod.rs b/experiments/heuristic-research/src/plots/mod.rs index 40dc3a5f8..63f908203 100644 --- a/experiments/heuristic-research/src/plots/mod.rs +++ b/experiments/heuristic-research/src/plots/mod.rs @@ -203,7 +203,7 @@ fn get_solution_points(generation: usize) -> Vec { data_points }) - .unwrap_or_else(Vec::new) + .unwrap_or_default() } fn get_heuristic_state(generation: usize, _kind: &str) -> HeuristicDrawConfig { diff --git a/experiments/heuristic-research/src/solver/proxies.rs b/experiments/heuristic-research/src/solver/proxies.rs index 4f83ed209..e946a1a6b 100644 --- a/experiments/heuristic-research/src/solver/proxies.rs +++ b/experiments/heuristic-research/src/solver/proxies.rs @@ -118,17 +118,13 @@ where type Individual = S; fn add_all(&mut self, individuals: Vec) -> bool { - self.acquire() - .on_add - .entry(self.generation) - .or_insert_with(Vec::new) - .extend(individuals.iter().map(|i| i.into())); + self.acquire().on_add.entry(self.generation).or_default().extend(individuals.iter().map(|i| i.into())); self.inner.add_all(individuals) } fn add(&mut self, individual: Self::Individual) -> bool { - self.acquire().on_add.entry(self.generation).or_insert_with(Vec::new).push((&individual).into()); + self.acquire().on_add.entry(self.generation).or_default().push((&individual).into()); self.inner.add(individual) } @@ -151,7 +147,7 @@ where fn select<'a>(&'a self) -> Box + 'a> { Box::new(self.inner.select().map(|individual| { - self.acquire().on_select.entry(self.generation).or_insert_with(Vec::new).push(individual.into()); + self.acquire().on_select.entry(self.generation).or_default().push(individual.into()); individual })) diff --git a/experiments/heuristic-research/src/solver/state.rs b/experiments/heuristic-research/src/solver/state.rs index 0ac84c11b..d08c8240f 100644 --- a/experiments/heuristic-research/src/solver/state.rs +++ b/experiments/heuristic-research/src/solver/state.rs @@ -152,8 +152,9 @@ impl HyperHeuristicState { map.entry(key).or_insert_with(|| length); }; - let mut search_states = - data.lines().skip(3).take_while(|line| *line != "heuristic:").fold(HashMap::new(), |mut data, line| { + let mut search_states = data.lines().skip(3).take_while(|line| *line != "heuristic:").fold( + HashMap::<_, Vec<_>>::new(), + |mut data, line| { let fields: Vec = line.split(',').map(|s| s.to_string()).collect(); let name = fields[0].clone(); let generation = fields[1].parse().unwrap(); @@ -170,21 +171,18 @@ impl HyperHeuristicState { let from = states.get(&from).copied().unwrap(); let to = states.get(&to).copied().unwrap(); - data.entry(generation).or_insert_with(Vec::default).push(SearchResult( - name, - reward, - (from, to), - duration, - )); + data.entry(generation).or_default().push(SearchResult(name, reward, (from, to), duration)); data - }); + }, + ); search_states .values_mut() .for_each(|states| states.sort_by(|SearchResult(a, ..), SearchResult(b, ..)| a.cmp(b))); - let mut heuristic_states = - data.lines().skip_while(|line| *line != "heuristic:").skip(2).fold(HashMap::new(), |mut data, line| { + let mut heuristic_states = data.lines().skip_while(|line| *line != "heuristic:").skip(2).fold( + HashMap::<_, Vec<_>>::new(), + |mut data, line| { let fields: Vec = line.split(',').map(|s| s.to_string()).collect(); let generation: usize = fields[0].parse().unwrap(); @@ -202,12 +200,11 @@ impl HyperHeuristicState { let state = states.get(&state).copied().unwrap(); let name = names.get(&name).copied().unwrap(); - data.entry(generation) - .or_insert_with(Vec::default) - .push(HeuristicResult(state, name, alpha, beta, mu, v, n)); + data.entry(generation).or_default().push(HeuristicResult(state, name, alpha, beta, mu, v, n)); data - }); + }, + ); heuristic_states .values_mut() .for_each(|states| states.sort_by(|HeuristicResult(_, a, ..), HeuristicResult(_, b, ..)| a.cmp(b))); diff --git a/vrp-cli/src/extensions/import/csv.rs b/vrp-cli/src/extensions/import/csv.rs index 238b2ec16..91127f731 100644 --- a/vrp-cli/src/extensions/import/csv.rs +++ b/vrp-cli/src/extensions/import/csv.rs @@ -86,8 +86,8 @@ mod actual { let jobs = read_csv_entries::(reader)? .iter() - .fold(HashMap::new(), |mut acc, job| { - acc.entry(&job.id).or_insert_with(Vec::new).push(job); + .fold(HashMap::<_, Vec<_>>::new(), |mut acc, job| { + acc.entry(&job.id).or_default().push(job); acc }) .into_iter() diff --git a/vrp-core/src/algorithms/clustering/dbscan.rs b/vrp-core/src/algorithms/clustering/dbscan.rs index 481636204..6ffe42707 100644 --- a/vrp-core/src/algorithms/clustering/dbscan.rs +++ b/vrp-core/src/algorithms/clustering/dbscan.rs @@ -54,7 +54,7 @@ where } match point_type { - Some(point_type) if point_type == PointType::Clustered => {} + Some(PointType::Clustered) => {} _ => { point_types.insert(point, PointType::Clustered); cluster.push(point); diff --git a/vrp-core/src/models/problem/costs.rs b/vrp-core/src/models/problem/costs.rs index 88fdfe5e2..cac7ebd63 100644 --- a/vrp-core/src/models/problem/costs.rs +++ b/vrp-core/src/models/problem/costs.rs @@ -270,7 +270,7 @@ impl TimeAwareMatrixTransportCost { let duration = match timestamps.binary_search(&(timestamp as u64)) { Ok(matrix_idx) => matrices.get(matrix_idx).unwrap().durations.get(data_idx).copied(), - Err(matrix_idx) if matrix_idx == 0 => matrices.first().unwrap().durations.get(data_idx).copied(), + Err(0) => matrices.first().unwrap().durations.get(data_idx).copied(), Err(matrix_idx) if matrix_idx == matrices.len() => { matrices.last().unwrap().durations.get(data_idx).copied() } @@ -315,7 +315,7 @@ impl TimeAwareMatrixTransportCost { match timestamps.binary_search(&(timestamp as u64)) { Ok(matrix_idx) => matrices.get(matrix_idx).unwrap().distances.get(data_idx), - Err(matrix_idx) if matrix_idx == 0 => matrices.first().unwrap().distances.get(data_idx), + Err(0) => matrices.first().unwrap().distances.get(data_idx), Err(matrix_idx) if matrix_idx == matrices.len() => matrices.last().unwrap().distances.get(data_idx), Err(matrix_idx) => matrices.get(matrix_idx - 1).unwrap().distances.get(data_idx), } diff --git a/vrp-core/src/models/problem/fleet.rs b/vrp-core/src/models/problem/fleet.rs index c033196bd..4e60e7c95 100644 --- a/vrp-core/src/models/problem/fleet.rs +++ b/vrp-core/src/models/problem/fleet.rs @@ -164,8 +164,8 @@ impl Fleet { .collect::>(); let group_key = (*group_key)(&actors); - let groups = actors.iter().cloned().fold(HashMap::new(), |mut acc, actor| { - acc.entry((*group_key)(&actor)).or_insert_with(HashSet::new).insert(actor.clone()); + let groups: HashMap<_, HashSet<_>> = actors.iter().cloned().fold(HashMap::new(), |mut acc, actor| { + acc.entry((*group_key)(&actor)).or_default().insert(actor.clone()); acc }); diff --git a/vrp-core/src/models/problem/jobs.rs b/vrp-core/src/models/problem/jobs.rs index 88e3fd682..e16570de4 100644 --- a/vrp-core/src/models/problem/jobs.rs +++ b/vrp-core/src/models/problem/jobs.rs @@ -425,8 +425,8 @@ fn get_avg_profile_costs(fleet: &Fleet) -> HashMap { fleet .vehicles .iter() - .fold(HashMap::new(), |mut acc, vehicle| { - acc.entry(vehicle.profile.index).or_insert_with(Vec::new).push(vehicle.costs.clone()); + .fold(HashMap::<_, Vec<_>>::new(), |mut acc, vehicle| { + acc.entry(vehicle.profile.index).or_default().push(vehicle.costs.clone()); acc }) .iter() diff --git a/vrp-core/src/solver/search/utils/selection.rs b/vrp-core/src/solver/search/utils/selection.rs index 05698f5e5..5d3fb714e 100644 --- a/vrp-core/src/solver/search/utils/selection.rs +++ b/vrp-core/src/solver/search/utils/selection.rs @@ -90,7 +90,7 @@ fn select_random_job( loop { let job = route_ctx.route().tour.get(ai).and_then(|a| a.retrieve_job()); - if job.as_ref().map_or(false, |job| job_filter(job)) { + if job.as_ref().map_or(false, job_filter) { return job; } diff --git a/vrp-pragmatic/src/checker/assignment.rs b/vrp-pragmatic/src/checker/assignment.rs index 369759c10..ff8bd140b 100644 --- a/vrp-pragmatic/src/checker/assignment.rs +++ b/vrp-pragmatic/src/checker/assignment.rs @@ -349,7 +349,7 @@ fn check_groups(ctx: &CheckerContext) -> Result<(), GenericError> { .flat_map(|activity| ctx.get_job_by_id(&activity.job_id)) .flat_map(|job| job.group.as_ref()) .for_each(|group| { - acc.entry(group.clone()).or_insert_with(HashSet::default).insert(( + acc.entry(group.clone()).or_default().insert(( tour.type_id.clone(), tour.vehicle_id.clone(), tour.shift_index, diff --git a/vrp-pragmatic/src/checker/mod.rs b/vrp-pragmatic/src/checker/mod.rs index 427986fbd..0b92fc1cd 100644 --- a/vrp-pragmatic/src/checker/mod.rs +++ b/vrp-pragmatic/src/checker/mod.rs @@ -261,7 +261,7 @@ impl CheckerContext { match (commute.is_zero_distance(), activity_idx) { (true, _) => Ok(Some(commute)), // NOTE that's unreachable - (false, idx) if idx == 0 => Err("cannot have commute at first activity in the stop".into()), + (false, 0) => Err("cannot have commute at first activity in the stop".into()), (false, idx) => { let prev_location = if matches!(config.visiting, VisitPolicy::Return) { stop_location diff --git a/vrp-pragmatic/src/format/problem/job_reader.rs b/vrp-pragmatic/src/format/problem/job_reader.rs index 1bce88cbd..db5148379 100644 --- a/vrp-pragmatic/src/format/problem/job_reader.rs +++ b/vrp-pragmatic/src/format/problem/job_reader.rs @@ -42,12 +42,13 @@ pub(super) fn read_locks(api_problem: &ApiProblem, job_index: &JobIndex) -> Vec< return vec![]; } - let relations = api_problem.plan.relations.as_ref().unwrap().iter().fold(HashMap::new(), |mut acc, r| { - let shift_index = r.shift_index.unwrap_or(0); - acc.entry((r.vehicle_id.clone(), shift_index)).or_insert_with(Vec::new).push(r.clone()); + let relations: HashMap<_, Vec<_>> = + api_problem.plan.relations.as_ref().unwrap().iter().fold(HashMap::new(), |mut acc, r| { + let shift_index = r.shift_index.unwrap_or_default(); + acc.entry((r.vehicle_id.clone(), shift_index)).or_default().push(r.clone()); - acc - }); + acc + }); relations.into_iter().fold(vec![], |mut acc, ((vehicle_id, shift_index), rels)| { let condition = create_condition(vehicle_id.clone(), shift_index);