use crate::aco::pheromone::Pheromone;
use crate::aco::probe::{Probe, ProbingPolicy};
use crate::aco::Solution;
pub struct PolicyDrivenProbe<Ph: Pheromone> {
probe: Box<dyn Probe<Ph>>,
policy: Box<dyn ProbingPolicy>,
}
impl<Ph: Pheromone> PolicyDrivenProbe<Ph> {
pub fn new(probe: Box<dyn Probe<Ph>>, policy: Box<dyn ProbingPolicy>) -> PolicyDrivenProbe<Ph> {
PolicyDrivenProbe { probe, policy }
}
}
impl<Ph: Pheromone> Probe<Ph> for PolicyDrivenProbe<Ph> {
fn on_pheromone_update(&mut self, old_pheromone: &Ph, new_pheromone: &Ph) {
if self.policy.on_pheromone_update() {
self.probe.on_pheromone_update(old_pheromone, new_pheromone);
}
}
fn on_current_best(&mut self, best: &Solution) {
if self.policy.on_current_best() {
self.probe.on_current_best(best);
}
}
fn on_iteration_start(&mut self) {
if self.policy.on_iteration_start() {
self.probe.on_iteration_start();
}
}
fn on_iteration_end(&mut self) {
if self.policy.on_iteration_end() {
self.probe.on_iteration_end();
}
}
fn on_end(&mut self) {
if self.policy.on_end() {
self.probe.on_end();
}
}
}