Skip to content

Commit 0cdf93d

Browse files
committed
rustfmt
1 parent fd82c07 commit 0cdf93d

File tree

5 files changed

+61
-18
lines changed

5 files changed

+61
-18
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ pub use crate::mode::Mode;
126126
pub use crate::objective_function::{ObjectiveFunction, ParallelObjectiveFunction};
127127
pub use crate::options::CMAESOptions;
128128
pub use crate::parameters::Weights;
129-
pub use crate::sampling::Constraints;
130-
pub use crate::sampling::Bounds;
131129
#[cfg(feature = "plotters")]
132130
pub use crate::plotting::PlotOptions;
131+
pub use crate::sampling::Bounds;
132+
pub use crate::sampling::Constraints;
133133
pub use crate::termination::TerminationReason;
134134

135135
use std::f64;

src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl CMAESOptions {
200200
/// Changes the bounds from the defalt value. Vector length must match the number of dimensions.
201201
/// Convenience method for constraints().
202202
pub fn bounds(mut self, lower: Vec<f64>, upper: Vec<f64>) -> Self {
203-
self.constraints = Some(Box::new(Bounds{lower, upper}));
203+
self.constraints = Some(Box::new(Bounds { lower, upper }));
204204
self
205205
}
206206

src/restart/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ impl Restarter {
317317
let seed = self.rng.gen();
318318

319319
// Apply default configuration (may be overridden by individual restart strategies)
320-
let mut options = self.default_options.clone()
320+
let mut options = self
321+
.default_options
322+
.clone()
321323
.initial_mean(initial_mean)
322324
.mode(self.mode)
323325
.parallel_update(self.parallel_update)

src/restart/options.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
use std::ops::RangeInclusive;
55
use std::time::Duration;
66

7-
8-
use super::{DEFAULT_INITIAL_STEP_SIZE, RestartStrategy, Restarter};
7+
use super::{RestartStrategy, Restarter, DEFAULT_INITIAL_STEP_SIZE};
98
use crate::{CMAESOptions, Mode};
109

1110
/// Represents invalid options for a `Restarter`.

src/sampling.rs

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::mode::Mode;
1111
use crate::state::State;
1212
use crate::{ObjectiveFunction, ParallelObjectiveFunction};
1313

14-
pub trait Constraints : Sync + std::fmt::Debug {
14+
pub trait Constraints: Sync + std::fmt::Debug {
1515
fn meets_constraints(&self, x: &DVector<f64>) -> bool;
1616
fn clone_box(&self) -> Box<dyn Constraints>;
1717
}
@@ -58,7 +58,14 @@ pub struct Sampler<F> {
5858
}
5959

6060
impl<F> Sampler<F> {
61-
pub fn new(dim: usize, constraints: Option<Box<dyn Constraints>>, max_resamples: Option<usize>, population_size: usize, objective_function: F, rng_seed: u64) -> Self {
61+
pub fn new(
62+
dim: usize,
63+
constraints: Option<Box<dyn Constraints>>,
64+
max_resamples: Option<usize>,
65+
population_size: usize,
66+
objective_function: F,
67+
rng_seed: u64,
68+
) -> Self {
6269
Self {
6370
dim,
6471
constraints,
@@ -102,11 +109,17 @@ impl<F> Sampler<F> {
102109
};
103110

104111
if parallel_update {
105-
z.into_par_iter().map(transform).filter(ok_constraints).collect()
112+
z.into_par_iter()
113+
.map(transform)
114+
.filter(ok_constraints)
115+
.collect()
106116
} else {
107-
z.into_iter().map(transform).filter(ok_constraints).collect()
117+
z.into_iter()
118+
.map(transform)
119+
.filter(ok_constraints)
120+
.collect()
108121
}
109-
},
122+
}
110123
None => {
111124
if parallel_update {
112125
z.into_par_iter().map(transform).collect()
@@ -139,7 +152,6 @@ impl<F> Sampler<F> {
139152
i += 1;
140153
}
141154

142-
143155
let mut points = evaluate_points(y, &mut self.objective_function)?;
144156

145157
self.function_evals += points.len();
@@ -285,7 +297,14 @@ mod tests {
285297
fn test_sample() {
286298
let dim = 10;
287299
let population_size = 12;
288-
let mut sampler = Sampler::new(dim, None, None, population_size, Box::new(|_: &DVector<f64>| 0.0), 1);
300+
let mut sampler = Sampler::new(
301+
dim,
302+
None,
303+
None,
304+
population_size,
305+
Box::new(|_: &DVector<f64>| 0.0),
306+
1,
307+
);
289308
let state = State::new(vec![0.0; dim].into(), 2.0);
290309

291310
let n = 5;
@@ -323,17 +342,33 @@ mod tests {
323342

324343
// No resampling: Value should be out-of-bounds
325344
{
326-
let mut sampler = Sampler::new(dim, Some(Box::new(bounds.clone())), Some(0), population_size, objective_function, 1);
345+
let mut sampler = Sampler::new(
346+
dim,
347+
Some(Box::new(bounds.clone())),
348+
Some(0),
349+
population_size,
350+
objective_function,
351+
1,
352+
);
327353
let state = State::new(vec![0.0; dim].into(), 2.0);
328354
let individuals = sampler.sample(&state, Mode::Minimize, false).unwrap();
329355

330-
assert!( individuals[0].point[0] < bounds.lower[0]
331-
|| individuals[0].point[0] > bounds.upper[0]);
356+
assert!(
357+
individuals[0].point[0] < bounds.lower[0]
358+
|| individuals[0].point[0] > bounds.upper[0]
359+
);
332360
}
333361

334362
// With limited resampling: Value should be in bounds
335363
{
336-
let mut sampler = Sampler::new(dim, Some(Box::new(bounds.clone())), Some(10), population_size, objective_function, 1);
364+
let mut sampler = Sampler::new(
365+
dim,
366+
Some(Box::new(bounds.clone())),
367+
Some(10),
368+
population_size,
369+
objective_function,
370+
1,
371+
);
337372
let state = State::new(vec![0.0; dim].into(), 2.0);
338373
let individuals = sampler.sample(&state, Mode::Minimize, false).unwrap();
339374

@@ -343,7 +378,14 @@ mod tests {
343378

344379
// With unlimited resampling: Value should be in bounds
345380
{
346-
let mut sampler = Sampler::new(dim, Some(Box::new(bounds.clone())), None, population_size, objective_function, 1);
381+
let mut sampler = Sampler::new(
382+
dim,
383+
Some(Box::new(bounds.clone())),
384+
None,
385+
population_size,
386+
objective_function,
387+
1,
388+
);
347389
let state = State::new(vec![0.0; dim].into(), 2.0);
348390
let individuals = sampler.sample(&state, Mode::Minimize, false).unwrap();
349391

0 commit comments

Comments
 (0)