diff --git a/src/components/replacement/bh.rs b/src/components/replacement/bh.rs index 481c4ad..2191886 100644 --- a/src/components/replacement/bh.rs +++ b/src/components/replacement/bh.rs @@ -1,11 +1,11 @@ //! Replacement components for the Black Hole algorithm (BH). -use rand::Rng; -use serde::{Deserialize, Serialize}; -use crate::{Component, ExecResult, Individual, SingleObjectiveProblem, State}; use crate::population::BestIndividual; use crate::problems::LimitedVectorProblem; use crate::utils::squared_euclidean; +use crate::{Component, ExecResult, Individual, SingleObjectiveProblem, State}; +use rand::Rng; +use serde::{Deserialize, Serialize}; #[derive(Clone, Serialize, Deserialize)] pub struct EventHorizon; @@ -28,30 +28,35 @@ impl
Component
for EventHorizon fn execute(&self, problem: &P, state: &mut State
) -> ExecResult<()> {
let mut populations = state.populations_mut();
- let mut offspring = populations.pop();
+ let offspring = populations.pop();
let f_bh = state.best_objective_value().unwrap().value();
let fitness_sum = offspring.iter().map(|x| x.objective().value()).sum:: for ExponentialAnnealingAcceptance
Ok(())
}
-
#[ensures(state.populations().current().len() == 1, "population after should contain a single individual")]
#[ensures(state.populations().len() == old(state.populations().len()) - 1)]
fn execute(&self, _problem: &P, state: &mut State ) -> ExecResult<()> {
@@ -76,7 +75,6 @@ impl for ExponentialAnnealingAcceptance
} else {
populations.pop();
}
-
Ok(())
}
}
diff --git a/src/components/swarm/bh.rs b/src/components/swarm/bh.rs
index 9501ef1..2cb59fe 100644
--- a/src/components/swarm/bh.rs
+++ b/src/components/swarm/bh.rs
@@ -1,10 +1,13 @@
-use rand::{
- distributions::{Distribution, Uniform},
-};
+use rand::distributions::{Distribution, Uniform};
use serde::Serialize;
-
-use crate::{component::ExecResult, components::Component, identifier::{Global, Identifier, PhantomId}, problems::{LimitedVectorProblem}, State};
use crate::population::{AsSolutionsMut, BestIndividual};
+use crate::{
+ component::ExecResult,
+ components::Component,
+ identifier::{Global, Identifier, PhantomId},
+ problems::{LimitedVectorProblem},
+ SingleObjectiveProblem, State
+};
/// Updates the positions in the black hole algorithm.
///
@@ -31,7 +34,7 @@ impl () -> Box () -> Box Component for BlackHoleParticlesUpdate
where
- P: LimitedVectorProblem ) -> ExecResult<()> {
@@ -56,12 +59,14 @@ impl Component for BlackHoleParticlesUpdate
}
fn execute(&self, _problem: &P, state: &mut State ) -> ExecResult<()> {
- let mut distr = Uniform::new(0.0, 1.0);
+ let distr = Uniform::new(0.0, 1.0);
// Get necessary state like global best `xg`
let best = state.populations().current().best_individual().cloned();
- let xg = best.unwrap().solution();
- let xs = state.populations_mut().current_mut().as_solutions_mut();
+ let binding = best.unwrap();
+ let xg = binding.solution();
+ let mut binding2 = state.populations_mut();
+ let xs = binding2.current_mut().as_solutions_mut();
// Perform the update step.
for x in xs {
@@ -74,4 +79,4 @@ impl Component for BlackHoleParticlesUpdate
}
Ok(())
}
-}
\ No newline at end of file
+}
diff --git a/src/components/swarm/fa.rs b/src/components/swarm/fa.rs
index 588497f..260ed71 100644
--- a/src/components/swarm/fa.rs
+++ b/src/components/swarm/fa.rs
@@ -2,13 +2,18 @@ use std::array::from_mut;
use better_any::{Tid, TidAble};
use derive_more::{Deref, DerefMut};
-use itertools::{izip};
+use itertools::izip;
use rand::Rng;
use serde::Serialize;
-use crate::{component::ExecResult, components::Component, identifier::{Global, Identifier, PhantomId}, problems::{LimitedVectorProblem}, CustomState, State};
use crate::state::common;
use crate::state::common::Evaluator;
+use crate::{
+ component::ExecResult,
+ components::Component,
+ identifier::{Global, Identifier, PhantomId},
+ problems::{LimitedVectorProblem},
+ CustomState, State};
/// Updates the and firefly positions.
///
@@ -67,35 +72,37 @@ impl Component for FireflyPositionsUpdate
}
fn execute(&self, problem: &P, state: &mut State ) -> ExecResult<()> {
-
// Prepare parameters
- let &Self {
- beta, gamma, ..
- } = self;
+ let &Self { beta, gamma, .. } = self;
let a = state.get_value:: Component for FireflyPositionsUpdate
|evaluator: &mut Evaluator , state| {
evaluator
.as_inner_mut()
- .evaluate(problem, state, from_mut(&mut individuals[i]));
+ .evaluate(
+ problem,
+ state,
+ from_mut(&mut individuals[i])
+ );
Ok(())
},
)?;
diff --git a/src/components/swarm/pso.rs b/src/components/swarm/pso.rs
index 78052c1..14b870d 100644
--- a/src/components/swarm/pso.rs
+++ b/src/components/swarm/pso.rs
@@ -335,17 +335,17 @@ impl () -> Box Component for GlobalBestParticleUpdate
- where
- P: SingleObjectiveProblem + LimitedVectorProblem ) -> ExecResult<()> {
state
@@ -422,4 +422,4 @@ impl ParticleSwarmUpdate (
params: RealProblemParameters,
condition: Box (
Parameters {
particle_update: swarm::bh::BlackHoleParticlesUpdate::new(),
constraints: boundary::Saturation::new(),
+ replacement: replacement::bh::EventHorizon::new(),
},
condition,
))
@@ -56,17 +54,19 @@ pub fn real_bh (
pub struct Parameters {
pub particle_update: Box (params: Parameters , condition: Box (params: Parameters , condition: Box (
params: RealProblemParameters,
condition: Box (
.update_best_individual()
.do_(fa:: (
Parameters {
- firefly_update: swarm::fa::FireflyPositionsUpdate::new(
- alpha,
- beta,
- gamma,
- ),
+ firefly_update: swarm::fa::FireflyPositionsUpdate::new(alpha, beta, gamma),
constraints: boundary::Saturation::new(),
alpha_update: Box::from(mapping::sa::GeometricCooling::new(
delta,
@@ -79,9 +74,9 @@ pub struct Parameters {
/// A generic single-objective Firefly Algorithm (FA) template.
pub fn fa (params: Parameters , condition: Box (params: Parameters , condition: Box