Skip to main content

RandomSearch

Struct RandomSearch 

Source
pub struct RandomSearch<I> {
    pub config: RandomSearchConfig,
    pub initializer: I,
}
Expand description

Sample-evaluate-keep baseline optimizer.

Each iteration the configured Initializer produces batch_size decisions which are evaluated and pushed into the population. Cheap, parallelism-free, and useful as a sanity-check baseline.

§Example

use heuropt::prelude::*;

struct Sphere;
impl Problem for Sphere {
    type Decision = Vec<f64>;
    fn objectives(&self) -> ObjectiveSpace {
        ObjectiveSpace::new(vec![Objective::minimize("f")])
    }
    fn evaluate(&self, x: &Vec<f64>) -> Evaluation {
        Evaluation::new(vec![x.iter().map(|v| v * v).sum::<f64>()])
    }
}

let mut opt = RandomSearch::new(
    RandomSearchConfig { iterations: 200, batch_size: 10, seed: 42 },
    RealBounds::new(vec![(-5.0, 5.0); 3]),
);
let r = opt.run(&Sphere);
assert_eq!(r.evaluations, 200 * 10);
assert!(r.best.is_some());

Fields§

§config: RandomSearchConfig

Algorithm configuration.

§initializer: I

Decision-sampling strategy.

Implementations§

Source§

impl<I> RandomSearch<I>

Source

pub fn new(config: RandomSearchConfig, initializer: I) -> Self

Construct a RandomSearch from its config and initializer.

Trait Implementations§

Source§

impl<I> AlgorithmInfo for RandomSearch<I>

Source§

fn name(&self) -> &'static str

Canonical short algorithm name — e.g. "NSGA-II", "DE", "CMA-ES". This is the form that should appear in tables, plot legends, and exported JSON metadata.
Source§

fn seed(&self) -> Option<u64>

The deterministic seed driving this run, if the algorithm uses one. Default: None. Built-in algorithms return Some(self.config.seed).
Source§

fn full_name(&self) -> &'static str

Academic long name, expanded — e.g. "Non-dominated Sorting Genetic Algorithm II". Defaults to name() for algorithms whose short and long forms coincide (Random Search, Hill Climber, Tabu Search, Hyperband, …).
Source§

impl<I: Clone> Clone for RandomSearch<I>

Source§

fn clone(&self) -> RandomSearch<I>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug> Debug for RandomSearch<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P, I> Optimizer<P> for RandomSearch<I>
where P: Problem + Sync, P::Decision: Send, I: Initializer<P::Decision>,

Source§

fn run(&mut self, problem: &P) -> OptimizationResult<P::Decision>

Run the optimizer to completion against problem.

Auto Trait Implementations§

§

impl<I> Freeze for RandomSearch<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for RandomSearch<I>
where I: RefUnwindSafe,

§

impl<I> Send for RandomSearch<I>
where I: Send,

§

impl<I> Sync for RandomSearch<I>
where I: Sync,

§

impl<I> Unpin for RandomSearch<I>
where I: Unpin,

§

impl<I> UnsafeUnpin for RandomSearch<I>
where I: UnsafeUnpin,

§

impl<I> UnwindSafe for RandomSearch<I>
where I: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V