Skip to content

Commit

Permalink
clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
xgillard committed Feb 22, 2024
1 parent d5adf2e commit a29694c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ members = [
"xtask",
]

resolver = "2"

[profile.release]
lto = 'fat'
panic = 'abort'
Expand Down
4 changes: 2 additions & 2 deletions ddo/examples/srflp/io_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ pub fn read_instance<P: AsRef<Path>>(fname: P) -> Result<SrflpInstance, Error> {
}

if clearance {
for i in 0..nb_departments {
lengths[i] += 10;
for item in lengths.iter_mut().take(nb_departments) {
*item += 10;
}
}

Expand Down
4 changes: 2 additions & 2 deletions ddo/examples/srflp/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/tsptw/heuristics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ impl TsptwWidth {
}
impl WidthHeuristic<TsptwState> for TsptwWidth {
fn max_width(&self, state: &SubProblem<TsptwState>) -> usize {
self.nb_vars * (state.depth as usize + 1) * self.factor
self.nb_vars * (state.depth + 1) * self.factor
}
}
8 changes: 4 additions & 4 deletions ddo/examples/tsptw/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down
6 changes: 3 additions & 3 deletions ddo/examples/tsptw/relax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Set256> {
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);

Expand Down
10 changes: 8 additions & 2 deletions ddo/src/implementation/mdd/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ where
}
}

#[allow(clippy::redundant_closure_call)]
fn _compute_local_bounds(&mut self, input: &CompilationInput<T>) {
if self.lel.unwrap().0 < self.layers.len() && input.comp_type == CompilationType::Relaxed {
// initialize last layer
Expand Down Expand Up @@ -472,7 +473,8 @@ where
}
}
}


#[allow(clippy::redundant_closure_call)]
fn _compute_thresholds(&mut self, input: &CompilationInput<T>) {
if input.comp_type == CompilationType::Relaxed || self.is_exact {
let mut best_known = input.best_lb;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -808,6 +811,7 @@ where
curr_l.truncate(input.max_width);
}

#[allow(clippy::redundant_closure_call)]
fn _relax(&mut self, input: &CompilationInput<T>, curr_l: &mut Vec<NodeId>) {
curr_l.sort_unstable_by(|a, b| {
get!(node a, self).value_top
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 7 additions & 2 deletions ddo/src/implementation/mdd/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ where
}
}
}

#[allow(clippy::redundant_closure_call)]
fn _compute_local_bounds(&mut self, input: &CompilationInput<T>) {
if !self.cutset.is_empty() && input.comp_type == CompilationType::Relaxed {
// initialize last layer
Expand Down Expand Up @@ -463,6 +463,7 @@ where
}
}

#[allow(clippy::redundant_closure_call)]
fn _compute_thresholds(&mut self, input: &CompilationInput<T>) {
if input.comp_type == CompilationType::Relaxed || self.is_exact {
let mut best_known = input.best_lb;
Expand Down Expand Up @@ -531,7 +532,8 @@ where
}
}
}


#[allow(clippy::redundant_closure_call)]
fn _compute_frontier_cutset(&mut self, input: &CompilationInput<T>) {
if input.comp_type == CompilationType::Relaxed || self.is_exact {
// traverse bottom-up
Expand Down Expand Up @@ -758,6 +760,7 @@ where
curr_l.truncate(input.max_width);
}

#[allow(clippy::redundant_closure_call)]
fn _relax(&mut self, input: &CompilationInput<T>, curr_l: &mut Vec<NodeId>) {
self.is_exact = false;
curr_l.sort_unstable_by(|a, b| {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a29694c

Please sign in to comment.