use std::sync::Arc;
use crate::search::plugin::{
Method, OptionKind, OptionSpec, PerturbModifier, Plugin, Registry, Scope, StartCtx,
};
use crate::search::SearchState;
struct Perturbation;
impl Method for Perturbation {
fn id(&self) -> &'static str {
"perturbation"
}
fn parent(&self) -> Option<&'static str> {
Some("nrpa") }
fn label_key(&self) -> &'static str {
"algo-perturbation"
}
fn spawn(&self, ctx: StartCtx, search: Arc<SearchState>) {
let StartCtx {
level,
variant,
seed_history,
..
} = ctx;
std::thread::spawn(move || super::run_perturbation(search, level, seed_history, variant));
}
fn method_desc(&self, ctx: &StartCtx) -> String {
format!("perturbation L{}", ctx.level)
}
fn checkpoint_kind(&self) -> Option<&'static str> {
Some("perturbation")
}
}
static PERTURBATION: Perturbation = Perturbation;
pub struct PerturbationPlugin;
impl Plugin for PerturbationPlugin {
fn id(&self) -> &'static str {
"perturbation"
}
fn register(&self, reg: &mut Registry) {
reg.add_method(&PERTURBATION);
}
}
pub static PERTURBATION_PLUGIN: PerturbationPlugin = PerturbationPlugin;
struct CoreCrossover;
impl PerturbModifier for CoreCrossover {}
static CORE_CROSSOVER: CoreCrossover = CoreCrossover;
pub struct CrossoverPlugin;
impl Plugin for CrossoverPlugin {
fn id(&self) -> &'static str {
"crossover"
}
fn deps(&self) -> &'static [&'static str] {
&["perturbation"]
}
fn register(&self, reg: &mut Registry) {
reg.add_perturb(&CORE_CROSSOVER);
reg.add_option(OptionSpec {
key: "crossover",
label_key: "opt-crossover",
help_key: "opt-crossover-hint",
help: "Perturbation genetic-crossover rate (0 = off). Only used by \
`--algo perturbation`.",
kind: OptionKind::Float {
default: 0.0,
min: 0.0,
max: 1.0,
step: 0.05,
},
scope: Scope::Methods(&["perturbation"]),
});
}
}
pub static CROSSOVER_PLUGIN: CrossoverPlugin = CrossoverPlugin;