fuzzy_expert/
rules.rs

1use crate::dsl::Expr;
2
3#[derive(Default)]
4pub struct Rules<T>(pub(crate) Vec<Rule<T>>);
5
6impl<T> Rules<T> {
7    pub fn new() -> Self {
8        Rules(Vec::new())
9    }
10
11    pub fn with_capacity(capacity: usize) -> Self {
12        Rules(Vec::with_capacity(capacity))
13    }
14
15    // REVIEW: Maybe consequence should be (Variable<I>, T) so we can manually
16    // turn it into Expr::Is(VariableKey, T)?
17    pub fn add(&mut self, premise: Expr<T>, consequence: Expr<T>) {
18        self.0.push(Rule {
19            premise,
20            consequence,
21            // TODO: CFs should be overridable
22            cf: 1.0,
23            threshold_cf: 0.,
24        });
25    }
26}
27
28pub(crate) struct Rule<T> {
29    // TODO: Rename to condition?
30    pub(crate) premise: Expr<T>,
31    // TODO: Rename to result or output?
32    pub(crate) consequence: Expr<T>,
33    pub(crate) cf: f64,
34    pub(crate) threshold_cf: f64,
35}