Skip to main content

SBXCrossover

Struct SBXCrossover 

Source
pub struct SBXCrossover { /* private fields */ }
Expand description

Simulated Binary Crossover (SBX)

A crossover operator for real-valued variables that simulates the behavior of single-point crossover on binary strings. Widely used in multi-objective optimization.

Implementations§

Source§

impl SBXCrossover

Source

pub fn new(distribution_index: f64) -> Self

Create a new SBX crossover operator

§Parameters
  • distribution_index: Controls the spread of offspring (typical value: 20.0) Higher values produce offspring closer to parents
Source

pub fn new_default() -> Self

Create with default distribution index

Examples found in repository?
examples/zdt1_nsga2_demo.rs (line 23)
14fn main() {
15    let seed = seed_from_cli_or(42);
16
17    let problem = ZDT1Problem::new(30);
18
19    let parameters = NSGAIIParameters::new(
20        60,
21        0.9,
22        1.0 / 30.0,
23        SBXCrossover::new_default(),
24        PolynomialMutation::new_default(),
25        MultiObjectiveTournamentSelection::new(),
26        TerminationCriteria::new(vec![TerminationCriterion::MaxIterations(40)]),
27    )
28    .with_seed(seed);
29
30    let mut algorithm = NSGAII::new(parameters);
31    let observer = ConsoleObserver::new(true);
32    let observer2 = ChartObserver::new_default();
33    algorithm.add_observer(Box::new(observer));
34    algorithm.add_observer(Box::new(observer2));
35    let result = algorithm
36        .run(&problem)
37        .expect("NSGA-II run failed");
38
39    if let Some(best) = result.get(0) {
40        println!(
41            "NSGA-II finished (seed={}). population={}, best objectives={:?}",
42            seed,
43            result.size(),
44            best.objectives()
45        );
46    } else {
47        println!("NSGA-II finished with empty population (seed={})", seed);
48    }
49}

Trait Implementations§

Source§

impl<Q> CrossoverOperator<f64, Q> for SBXCrossover
where Q: Clone + Display,

Source§

fn execute( &self, parent1: &Solution<f64, Q>, parent2: &Solution<f64, Q>, rng: &mut Random, ) -> Vec<Solution<f64, Q>>

Applies crossover to two parent solutions and returns offspring. Read more
Source§

fn execute_several( &self, solutions: Vec<Solution<f64, Q>>, rng: &mut Random, ) -> Vec<Solution<f64, Q>>

Applies crossover to several parent solutions and returns offspring. Read more
Source§

fn number_of_offspring(&self) -> usize

Returns the expected number of offspring produced by this operator
Source§

impl Operator for SBXCrossover

Source§

fn name(&self) -> &str

Returns the name of the operator for debugging/logging purposes

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