Skip to main content

DifferentialEvolution

Struct DifferentialEvolution 

Source
pub struct DifferentialEvolution {
    pub config: DifferentialEvolutionConfig,
    pub bounds: RealBounds,
}
Expand description

Single-objective DE/rand/1/bin (spec §12.4).

Vec<f64> decisions only; single-objective problems only. Bounds come from the embedded RealBounds, and mutant vectors are clamped to those bounds.

§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 = DifferentialEvolution::new(
    DifferentialEvolutionConfig {
        population_size: 20,
        generations: 50,
        differential_weight: 0.5,
        crossover_probability: 0.9,
        seed: 42,
    },
    RealBounds::new(vec![(-5.0, 5.0); 5]),
);
let r = opt.run(&Sphere);
// DE crushes Sphere; expect very small objective.
assert!(r.best.unwrap().evaluation.objectives[0] < 1e-3);

Fields§

§config: DifferentialEvolutionConfig

Algorithm configuration.

§bounds: RealBounds

Per-variable bounds — used both to seed the population and to clamp mutants.

Implementations§

Source§

impl DifferentialEvolution

Source

pub fn new(config: DifferentialEvolutionConfig, bounds: RealBounds) -> Self

Construct a DifferentialEvolution optimizer.

Trait Implementations§

Source§

impl AlgorithmInfo for DifferentialEvolution

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 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§

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§

impl Clone for DifferentialEvolution

Source§

fn clone(&self) -> DifferentialEvolution

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 Debug for DifferentialEvolution

Source§

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

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

impl<P> Optimizer<P> for DifferentialEvolution
where P: Problem<Decision = Vec<f64>> + Sync,

Source§

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

Run the optimizer to completion against problem.

Auto Trait Implementations§

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