Skip to content

Commit

Permalink
fix: Allow to use custom population initializer in Cuckoo
Browse files Browse the repository at this point in the history
  • Loading branch information
pnevyk committed Jan 6, 2022
1 parent 5ed3226 commit 7f3193d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/solver/cuckoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct CuckooOptions<F: System, I: PopulationInit<F>> {
#[getset(get_copy = "pub", set = "pub")]
population_size: PopulationSize,
/// Population initializer. Default: [`UniformInit`].
#[getset(get = "pub", set = "pub")]
#[getset(get = "pub")]
population_init: I,
/// Scale factor when doing local search. Default: `0.05`.
#[getset(get_copy = "pub", set = "pub")]
Expand All @@ -71,14 +71,12 @@ pub struct CuckooOptions<F: System, I: PopulationInit<F>> {
local_walk_dir: LocalWalkDirection,
}

impl<F: System> Default for CuckooOptions<F, UniformInit<F>>
where
F::Scalar: SampleUniform,
{
fn default() -> Self {
impl<F: System, I: PopulationInit<F>> CuckooOptions<F, I> {
/// Initializes the options with given population initializer.
pub fn with_population_init(population_init: I) -> Self {
Self {
population_size: PopulationSize::Adaptive,
population_init: UniformInit::default(),
population_init,
scale_factor: convert(0.05),
abandon_prob: 0.25,
elite_fraction: 0.15,
Expand All @@ -87,6 +85,15 @@ where
}
}

impl<F: System> Default for CuckooOptions<F, UniformInit<F>>
where
F::Scalar: SampleUniform,
{
fn default() -> Self {
Self::with_population_init(UniformInit::default())
}
}

/// Cuckoo search solver. See [module](self) documentation for more details.
pub struct Cuckoo<F: System, I: PopulationInit<F>, R: Rng>
where
Expand Down

0 comments on commit 7f3193d

Please sign in to comment.