Struct HiveBuilder

Source
pub struct HiveBuilder<Ctx: Context> { /* private fields */ }
Expand description

Manages the parameters of the ABC algorithm.

Implementations§

Source§

impl<Ctx: Context> HiveBuilder<Ctx>

Source

pub fn new(context: Ctx, workers: usize) -> HiveBuilder<Ctx>

Creates a new hive.

  • context - Factory-like state that can be used while generating solutions.
  • workers - Number of working solution candidates to maintain at a time.
Examples found in repository?
examples/max_i32.rs (line 32)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_scaling(scaling::power_rank(10_f64));
35    println!("{:?}", hive.build().unwrap().run_for_rounds(1_000));
36}
More examples
Hide additional examples
examples/streaming.rs (line 32)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_observers(4)
35        .set_scaling(scaling::power_rank(10_f64));
36    for candidate in hive.build()
37                         .unwrap()
38                         .stream()
39                         .iter()
40                         .skip_while(|c| c.fitness < 200_f64)
41                         .take(5) {
42        println!("{:?}", candidate);
43    }
44}
Source

pub fn set_observers(self, observers: usize) -> HiveBuilder<Ctx>

Sets the number of “bees” that will pick a candidate to work on at random.

This defaults to the number of workers.

Examples found in repository?
examples/streaming.rs (line 34)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_observers(4)
35        .set_scaling(scaling::power_rank(10_f64));
36    for candidate in hive.build()
37                         .unwrap()
38                         .stream()
39                         .iter()
40                         .skip_while(|c| c.fitness < 200_f64)
41                         .take(5) {
42        println!("{:?}", candidate);
43    }
44}
Source

pub fn set_retries(self, retries: usize) -> HiveBuilder<Ctx>

Sets the number of times a candidate can go unimproved before being reinitialized.

This defaults to the number of workers.

Source

pub fn set_threads(self, threads: usize) -> HiveBuilder<Ctx>

Sets the number of worker threads to use while running.

Examples found in repository?
examples/max_i32.rs (line 33)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_scaling(scaling::power_rank(10_f64));
35    println!("{:?}", hive.build().unwrap().run_for_rounds(1_000));
36}
More examples
Hide additional examples
examples/streaming.rs (line 33)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_observers(4)
35        .set_scaling(scaling::power_rank(10_f64));
36    for candidate in hive.build()
37                         .unwrap()
38                         .stream()
39                         .iter()
40                         .skip_while(|c| c.fitness < 200_f64)
41                         .take(5) {
42        println!("{:?}", candidate);
43    }
44}
Source

pub fn set_scaling(self, scale: Box<ScalingFunction>) -> HiveBuilder<Ctx>

Sets the scaling function for observers to use.

Examples found in repository?
examples/max_i32.rs (line 34)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_scaling(scaling::power_rank(10_f64));
35    println!("{:?}", hive.build().unwrap().run_for_rounds(1_000));
36}
More examples
Hide additional examples
examples/streaming.rs (line 35)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_observers(4)
35        .set_scaling(scaling::power_rank(10_f64));
36    for candidate in hive.build()
37                         .unwrap()
38                         .stream()
39                         .iter()
40                         .skip_while(|c| c.fitness < 200_f64)
41                         .take(5) {
42        println!("{:?}", candidate);
43    }
44}
Source

pub fn build(self) -> AbcResult<Hive<Ctx>>

Activates the HiveBuilder to create a runnable object.

Examples found in repository?
examples/max_i32.rs (line 35)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_scaling(scaling::power_rank(10_f64));
35    println!("{:?}", hive.build().unwrap().run_for_rounds(1_000));
36}
More examples
Hide additional examples
examples/streaming.rs (line 36)
31fn main() {
32    let hive = HiveBuilder::<Foo>::new(Foo, 5)
33        .set_threads(5)
34        .set_observers(4)
35        .set_scaling(scaling::power_rank(10_f64));
36    for candidate in hive.build()
37                         .unwrap()
38                         .stream()
39                         .iter()
40                         .skip_while(|c| c.fitness < 200_f64)
41                         .take(5) {
42        println!("{:?}", candidate);
43    }
44}

Auto Trait Implementations§

§

impl<Ctx> Freeze for HiveBuilder<Ctx>
where Ctx: Freeze,

§

impl<Ctx> !RefUnwindSafe for HiveBuilder<Ctx>

§

impl<Ctx> Send for HiveBuilder<Ctx>

§

impl<Ctx> Sync for HiveBuilder<Ctx>

§

impl<Ctx> Unpin for HiveBuilder<Ctx>
where Ctx: Unpin,

§

impl<Ctx> !UnwindSafe for HiveBuilder<Ctx>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.