feat(factor): introduce Factor trait and BuiltinFactor enum

Adds the trait that all factors implement and the enum dispatcher
used by the schedule to drive heterogeneous factors without dynamic
dispatch in the hot loop.

The three built-in factors (TeamSum, RankDiff, Trunc) are stubbed
out; concrete implementations follow in tasks 4-6.
This commit is contained in:
2026-04-24 08:14:00 +02:00
parent dac4427b65
commit ebccc7b454
4 changed files with 112 additions and 0 deletions

32
src/factor/trunc.rs Normal file
View File

@@ -0,0 +1,32 @@
use crate::{
N_INF,
factor::{Factor, VarId, VarStore},
gaussian::Gaussian,
};
#[derive(Debug)]
pub(crate) struct TruncFactor {
pub(crate) diff: VarId,
pub(crate) margin: f64,
pub(crate) tie: bool,
pub(crate) msg: Gaussian,
pub(crate) evidence_cached: Option<f64>,
}
impl TruncFactor {
pub(crate) fn new(diff: VarId, margin: f64, tie: bool) -> Self {
Self {
diff,
margin,
tie,
msg: N_INF,
evidence_cached: None,
}
}
}
impl Factor for TruncFactor {
fn propagate(&mut self, _vars: &mut VarStore) -> (f64, f64) {
unimplemented!("TruncFactor stub — implemented in Task 6")
}
}