Struct coco_rs::RandomState
source · pub struct RandomState { /* private fields */ }
Expand description
COCO specific random number generator.
Implementations§
source§impl RandomState
impl RandomState
sourcepub fn new(seed: u32) -> Self
pub fn new(seed: u32) -> Self
Creates a new random number state using the given seed.
Examples found in repository?
examples/example-experiment.rs (line 8)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
fn main() {
let random_generator = &mut RandomState::new(RANDOM_SEED);
println!("Running the example experiment... (might take time, be patient)");
coco_rs::set_log_level(LogLevel::Info);
example_experiment(
SuiteName::Bbob,
"",
ObserverName::Bbob,
"result_folder: RS_on_bbob",
random_generator,
);
println!("Done!");
}
sourcepub fn uniform(&mut self) -> f64
pub fn uniform(&mut self) -> f64
Returns one uniform [0, 1) random value.
Examples found in repository?
examples/example-experiment.rs (line 68)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
fn my_random_search(problem: &mut Problem, max_budget: usize, random_generator: &mut RandomState) {
let dimension = problem.dimension();
let number_of_objectives = problem.number_of_objectives();
let numver_of_constraints = problem.number_of_constraints();
let number_of_integer_variables = problem.number_of_integer_variables();
let bounds = problem.get_ranges_of_interest();
let x = &mut vec![0.0; dimension];
let y = &mut vec![0.0; number_of_objectives];
let c = &mut vec![0.0; numver_of_constraints];
problem.initial_solution(x);
problem.evaluate_function(x, y);
for _ in 0..max_budget {
for (i, xi) in x.iter_mut().enumerate() {
let (lower, upper) = bounds[i].clone().into_inner();
*xi = lower + random_generator.uniform() * (upper - lower);
if i < number_of_integer_variables {
*xi = xi.round();
}
}
if numver_of_constraints > 0 {
problem.evaluate_constraint(x, c);
}
problem.evaluate_function(x, y);
}
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for RandomState
impl !Send for RandomState
impl !Sync for RandomState
impl Unpin for RandomState
impl UnwindSafe for RandomState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more