I would have all of the object be of the same type or implement the same interface (A), then set some calculated facts in a rule that I would use in a subsequent rule to get the final calculation.
This first rule fires for every instance of the type or interface
A.weight > 0
Set fact calculated_weight = calculated_weight + A.weight
Set fact calculated_certaintity = calculated_certaintity + A.certaintity * A.weight
Set fact final_answer = calculated_certaintity / calculated_weight.
Something like that. Hope it helps
I search a rule implementation for the following calculation:
I have n Objects of differents types (A, B, C, ...) each with a parameter certainty.
the overall certainty is calculated as follows: certaintyOverall = (certaintyA * weightA + certaintyB * weightB + ... ) / (weightA + weightB + ...)
If it can be assumed that all Objects in the formula always exist it's quite easy:
A (certaintyA: certainty)
B (certaintyB: certainty)
certaintyOverall = (certaintyA * weightA + certaintyB * weightB + ... ) / (weightA + weightB + ...)
But if one ore more objects are missing the formula should be reduced to the certainty and weights of the existing objects. But there are too many combinations of existing/nonexisting objects. How can this be implemented in Drools?