chore: fix clippy warnings in NSGA-III, SPEA2, and compare example
- nsga3: drop redundant `.into_iter()` in extend call; use `#[allow(clippy::needless_range_loop)]` on the back-substitution loop where `j` indexes into the matrix; remove an unneeded `return` keyword in a closure. - spea2: switch `pool.extend(x.drain(..))` to `pool.append(&mut x)`. - examples/compare.rs DTLZ2 evaluator: same `needless_range_loop` silencer on the inner cosine product loop.
This commit is contained in:
@@ -79,6 +79,7 @@ impl Problem for Dtlz2 {
|
||||
let mut f = vec![0.0_f64; m];
|
||||
for i in 0..m {
|
||||
let mut prod = scale;
|
||||
#[allow(clippy::needless_range_loop)] // Body indexes `x[j]`.
|
||||
for j in 0..(m - i - 1) {
|
||||
prod *= (x[j] * std::f64::consts::FRAC_PI_2).cos();
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ where
|
||||
// --- Combine + survival selection ---
|
||||
let mut combined: Vec<Candidate<P::Decision>> =
|
||||
Vec::with_capacity(2 * n);
|
||||
combined.extend(population.into_iter());
|
||||
combined.extend(population);
|
||||
combined.extend(offspring);
|
||||
population = environmental_selection(&combined, &objectives, &reference_points, n, &mut rng);
|
||||
}
|
||||
@@ -325,6 +325,7 @@ fn solve_intercepts(oriented: &[Vec<f64>], extremes: &[usize]) -> Option<Vec<f64
|
||||
let mut a: Vec<Vec<f64>> = extremes.iter().map(|&i| oriented[i].clone()).collect();
|
||||
let mut b: Vec<f64> = vec![1.0; m];
|
||||
// Forward elimination with partial pivoting.
|
||||
#[allow(clippy::needless_range_loop)] // Body indexes both `a` and `b` by row.
|
||||
for k in 0..m {
|
||||
let mut pivot = k;
|
||||
for i in (k + 1)..m {
|
||||
@@ -339,6 +340,7 @@ fn solve_intercepts(oriented: &[Vec<f64>], extremes: &[usize]) -> Option<Vec<f64
|
||||
b.swap(k, pivot);
|
||||
for i in (k + 1)..m {
|
||||
let factor = a[i][k] / a[k][k];
|
||||
#[allow(clippy::needless_range_loop)] // Body indexes both `a[i]` and `a[k]`.
|
||||
for j in k..m {
|
||||
a[i][j] -= factor * a[k][j];
|
||||
}
|
||||
@@ -360,7 +362,7 @@ fn solve_intercepts(oriented: &[Vec<f64>], extremes: &[usize]) -> Option<Vec<f64
|
||||
// Intercept along axis k is 1 / x[k].
|
||||
let intercepts: Vec<f64> = x
|
||||
.into_iter()
|
||||
.map(|v| if v.abs() < 1e-12 { return f64::NAN } else { 1.0 / v })
|
||||
.map(|v| if v.abs() < 1e-12 { f64::NAN } else { 1.0 / v })
|
||||
.collect();
|
||||
if intercepts.iter().any(|v| !v.is_finite() || *v <= 0.0) {
|
||||
return None;
|
||||
|
||||
@@ -87,8 +87,8 @@ where
|
||||
// --- Combine pool, compute fitness ---
|
||||
let mut pool: Vec<Candidate<P::Decision>> =
|
||||
Vec::with_capacity(population.len() + archive.len());
|
||||
pool.extend(population.drain(..));
|
||||
pool.extend(archive.drain(..));
|
||||
pool.append(&mut population);
|
||||
pool.append(&mut archive);
|
||||
let fitness = compute_fitness(&pool, &objectives);
|
||||
|
||||
// --- Build the next archive ---
|
||||
|
||||
Reference in New Issue
Block a user