Struct coco_rs::RandomState

source ·
pub struct RandomState { /* private fields */ }
Expand description

COCO specific random number generator.

Implementations§

source§

impl RandomState

source

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!");
}
source

pub fn normal(&mut self) -> f64

Generates an approximately normal random number.

source

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§

source§

impl Drop for RandomState

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.