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:
32
src/factor/trunc.rs
Normal file
32
src/factor/trunc.rs
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user