use crate::{Candidate, FitnessReport, ReplayStatus};
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct EvaluationCacheKey(pub String);
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct ConstructionDependency(pub String);
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct ReplayHook {
pub domain: String,
pub target: String,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct EvaluationCost {
pub calls: usize,
pub units: usize,
}
impl EvaluationCost {
pub const fn one_call() -> Self {
Self { calls: 1, units: 1 }
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SurrogateStage {
pub name: String,
pub lossy: bool,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SurrogateDecision {
PromoteToReplay,
ProposalOnly,
Reject,
}
#[derive(Clone, Debug, PartialEq)]
pub struct BlackBoxEvaluationReport {
pub fitness: FitnessReport,
pub cost: EvaluationCost,
pub cache_key: Option<EvaluationCacheKey>,
pub dependencies: Vec<ConstructionDependency>,
pub replay_hooks: Vec<ReplayHook>,
pub surrogate_stage: Option<SurrogateStage>,
}
impl BlackBoxEvaluationReport {
pub fn is_promotable(&self) -> bool {
self.surrogate_stage.is_none() && self.fitness.replay == ReplayStatus::Accepted
}
pub fn requires_replay(&self) -> bool {
self.surrogate_stage.is_some() || self.fitness.replay != ReplayStatus::Accepted
}
}
pub trait FitnessOracle {
fn evaluate(&self, candidate: &Candidate) -> BlackBoxEvaluationReport;
}
pub trait SurrogateScreen {
fn screen(&self, candidate: &Candidate) -> SurrogateScreenReport;
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SurrogateScreenReport {
pub candidate: String,
pub stage: SurrogateStage,
pub decision: SurrogateDecision,
pub cache_key: Option<EvaluationCacheKey>,
}
pub fn evaluate_candidate_with_oracle<O: FitnessOracle>(
oracle: &O,
candidate: &Candidate,
) -> BlackBoxEvaluationReport {
oracle.evaluate(candidate)
}
pub fn surrogate_allows_archive_promotion(report: &SurrogateScreenReport) -> bool {
let _ = report;
false
}