From a29694c04094991ac2924f6081351af5e14e1079 Mon Sep 17 00:00:00 2001 From: "AGRAR\\xavier.gillard" Date: Thu, 22 Feb 2024 15:26:43 +0100 Subject: [PATCH] clippy lints --- Cargo.toml | 2 ++ ddo/examples/srflp/io_utils.rs | 4 ++-- ddo/examples/srflp/model.rs | 4 ++-- ddo/examples/tsptw/heuristics.rs | 2 +- ddo/examples/tsptw/model.rs | 8 ++++---- ddo/examples/tsptw/relax.rs | 6 +++--- ddo/src/implementation/mdd/clean.rs | 10 ++++++++-- ddo/src/implementation/mdd/pooled.rs | 9 +++++++-- 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22e29355..40c5bb3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,8 @@ members = [ "xtask", ] +resolver = "2" + [profile.release] lto = 'fat' panic = 'abort' diff --git a/ddo/examples/srflp/io_utils.rs b/ddo/examples/srflp/io_utils.rs index fc31e5e7..c6dea2a6 100644 --- a/ddo/examples/srflp/io_utils.rs +++ b/ddo/examples/srflp/io_utils.rs @@ -85,8 +85,8 @@ pub fn read_instance>(fname: P) -> Result { } if clearance { - for i in 0..nb_departments { - lengths[i] += 10; + for item in lengths.iter_mut().take(nb_departments) { + *item += 10; } } diff --git a/ddo/examples/srflp/model.rs b/ddo/examples/srflp/model.rs index bfb05693..f974a1e8 100644 --- a/ddo/examples/srflp/model.rs +++ b/ddo/examples/srflp/model.rs @@ -96,10 +96,10 @@ impl Problem for Srflp { let d = d.value as usize; // if it is a true move - let mut remaining = state.must_place.clone(); + let mut remaining = state.must_place; remaining.remove_inplace(d); // if it is a possible move - let mut maybes = state.maybe_place.clone(); + let mut maybes = state.maybe_place; if let Some(maybe) = maybes.as_mut() { maybe.remove_inplace(d); diff --git a/ddo/examples/tsptw/heuristics.rs b/ddo/examples/tsptw/heuristics.rs index 8f7cc6c8..2ac6dd86 100644 --- a/ddo/examples/tsptw/heuristics.rs +++ b/ddo/examples/tsptw/heuristics.rs @@ -47,6 +47,6 @@ impl TsptwWidth { } impl WidthHeuristic for TsptwWidth { fn max_width(&self, state: &SubProblem) -> usize { - self.nb_vars * (state.depth as usize + 1) * self.factor + self.nb_vars * (state.depth + 1) * self.factor } } \ No newline at end of file diff --git a/ddo/examples/tsptw/model.rs b/ddo/examples/tsptw/model.rs index 5c3395f1..296959cb 100644 --- a/ddo/examples/tsptw/model.rs +++ b/ddo/examples/tsptw/model.rs @@ -94,10 +94,10 @@ impl Problem for Tsptw { fn transition(&self, state: &TsptwState, d: Decision) -> TsptwState { // if it is a true move - let mut remaining = state.must_visit.clone(); + let mut remaining = state.must_visit; remaining.remove_inplace(d.value as usize); // if it is a possible move - let mut maybes = state.maybe_visit.clone(); + let mut maybes = state.maybe_visit; if let Some(maybe) = maybes.as_mut() { maybe.remove_inplace(d.value as usize); } @@ -199,7 +199,7 @@ impl Tsptw { Position::Node(i) => self.instance.distances[*i as usize][j], Position::Virtual(candidates) => candidates.iter() - .map(|i| self.instance.distances[i as usize][j as usize]) + .map(|i| self.instance.distances[i][j]) .min() .unwrap() } @@ -209,7 +209,7 @@ impl Tsptw { Position::Node(i) => self.instance.distances[*i as usize][j], Position::Virtual(candidates) => candidates.iter() - .map(|i| self.instance.distances[i as usize][j as usize]) + .map(|i| self.instance.distances[i][j]) .max() .unwrap() } diff --git a/ddo/examples/tsptw/relax.rs b/ddo/examples/tsptw/relax.rs index c0598d87..19c01f69 100644 --- a/ddo/examples/tsptw/relax.rs +++ b/ddo/examples/tsptw/relax.rs @@ -132,7 +132,7 @@ impl RelaxHelper { self.depth } fn get_position(&self) -> Position { - Position::Virtual(self.position.clone()) + Position::Virtual(self.position) } fn get_elapsed(&self) -> ElapsedTime { if self.earliest == self.latest { @@ -147,10 +147,10 @@ impl RelaxHelper { } } fn get_must_visit(&self) -> Set256 { - self.all_agree.clone() + self.all_agree } fn get_maybe_visit(&self) -> Option { - let mut maybe = self.all_maybe.clone(); // three lines: faster because it is in-place + let mut maybe = self.all_maybe; // three lines: faster because it is in-place maybe.union_inplace(&self.all_must); maybe.diff_inplace(&self.all_agree); diff --git a/ddo/src/implementation/mdd/clean.rs b/ddo/src/implementation/mdd/clean.rs index 44f0a1d3..8660d586 100644 --- a/ddo/src/implementation/mdd/clean.rs +++ b/ddo/src/implementation/mdd/clean.rs @@ -444,6 +444,7 @@ where } } + #[allow(clippy::redundant_closure_call)] fn _compute_local_bounds(&mut self, input: &CompilationInput) { if self.lel.unwrap().0 < self.layers.len() && input.comp_type == CompilationType::Relaxed { // initialize last layer @@ -472,7 +473,8 @@ where } } } - + + #[allow(clippy::redundant_closure_call)] fn _compute_thresholds(&mut self, input: &CompilationInput) { if input.comp_type == CompilationType::Relaxed || self.is_exact { let mut best_known = input.best_lb; @@ -579,7 +581,8 @@ where } } } - + + #[allow(clippy::redundant_closure_call)] fn _compute_frontier_cutset(&mut self) { // traverse bottom-up for Layer{from, to} in self.layers.iter().rev().copied() { @@ -808,6 +811,7 @@ where curr_l.truncate(input.max_width); } + #[allow(clippy::redundant_closure_call)] fn _relax(&mut self, input: &CompilationInput, curr_l: &mut Vec) { curr_l.sort_unstable_by(|a, b| { get!(node a, self).value_top @@ -957,6 +961,8 @@ where T: Debug + Eq + PartialEq + Hash + Clone { let attributes = self.node_attributes(id, config); format!("\t{id} [{attributes}];\n") } + + #[allow(clippy::redundant_closure_call)] /// Creates a string representation of the edges incident to one node fn edges_of(&self, id: usize) -> String { let mut out = String::new(); diff --git a/ddo/src/implementation/mdd/pooled.rs b/ddo/src/implementation/mdd/pooled.rs index a9d48ac3..ecc5a670 100644 --- a/ddo/src/implementation/mdd/pooled.rs +++ b/ddo/src/implementation/mdd/pooled.rs @@ -433,7 +433,7 @@ where } } } - + #[allow(clippy::redundant_closure_call)] fn _compute_local_bounds(&mut self, input: &CompilationInput) { if !self.cutset.is_empty() && input.comp_type == CompilationType::Relaxed { // initialize last layer @@ -463,6 +463,7 @@ where } } + #[allow(clippy::redundant_closure_call)] fn _compute_thresholds(&mut self, input: &CompilationInput) { if input.comp_type == CompilationType::Relaxed || self.is_exact { let mut best_known = input.best_lb; @@ -531,7 +532,8 @@ where } } } - + + #[allow(clippy::redundant_closure_call)] fn _compute_frontier_cutset(&mut self, input: &CompilationInput) { if input.comp_type == CompilationType::Relaxed || self.is_exact { // traverse bottom-up @@ -758,6 +760,7 @@ where curr_l.truncate(input.max_width); } + #[allow(clippy::redundant_closure_call)] fn _relax(&mut self, input: &CompilationInput, curr_l: &mut Vec) { self.is_exact = false; curr_l.sort_unstable_by(|a, b| { @@ -877,6 +880,8 @@ where T: Debug + Eq + PartialEq + Hash + Clone { let attributes = self.node_attributes(id, config); format!("\t{id} [{attributes}];\n") } + + #[allow(clippy::redundant_closure_call)] /// Creates a string representation of the edges incident to one node fn edges_of(&self, id: usize) -> String { let mut out = String::new();