You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Evaluates a collection of `Causable` items that may contain a mix of deterministic and
9
+
/// probabilistic effects, aggregating them into a final deterministic outcome.
10
+
///
11
+
/// This is a private helper function that encapsulates the core reasoning logic,
12
+
/// allowing the public-facing trait method to remain a simple delegation.
13
+
/// It is optimized to short-circuit for performance where possible.
14
+
///
15
+
/// # Arguments
16
+
/// * `items` - A vector of references to `Causable` items.
17
+
/// * `effect` - The `PropagatingEffect` to pass to each item's `evaluate` method.
18
+
/// * `logic` - The aggregation logic to apply.
19
+
/// * `threshold` - The numerical threshold used to convert probabilistic effects to boolean.
20
+
///
21
+
/// # Returns
22
+
/// A `Result` containing the final `PropagatingEffect` outcome.
23
+
/// For `AggregateLogic::All`, it returns `PropagatingEffect::Deterministic` after applying the threshold.
24
+
/// For `Any`, `None`, and `Some(k)`, it returns `PropagatingEffect::Deterministic`.
25
+
/// Returns a `CausalityError` if any item returns an unsupported effect type.
26
+
pubfn_evaluate_mixed_logic<T:Causable>(
27
+
items:Vec<&T>,
28
+
effect:&PropagatingEffect,
29
+
logic:&AggregateLogic,
30
+
threshold:NumericalValue,
31
+
) -> Result<PropagatingEffect,CausalityError>{
32
+
if items.is_empty(){
33
+
returnErr(CausalityError(
34
+
"No Causaloids found to evaluate".to_string(),
35
+
));
36
+
}
37
+
38
+
match logic {
39
+
AggregateLogic::All => {
40
+
letmut cumulative_prob:NumericalValue = 1.0;
41
+
for cause in items {
42
+
let current_effect = cause.evaluate(effect)?;
43
+
let current_prob = match current_effect {
44
+
PropagatingEffect::Deterministic(true) => 1.0,
45
+
PropagatingEffect::Deterministic(false) => 0.0,
46
+
PropagatingEffect::Probabilistic(p) => p,
47
+
PropagatingEffect::Numerical(p) => p,
48
+
_ => {
49
+
returnErr(CausalityError(format!(
50
+
"evaluate_mixed_propagation encountered an unsupported effect: {current_effect:?}. Only probabilistic, deterministic, or numerical effects are allowed."
"evaluate_mixed_propagation encountered an unsupported effect: {evaluated_effect:?}. Only probabilistic, numerical, or deterministic effects are allowed."
0 commit comments