Drools - 累积嵌套在其他积累中

时间:2014-07-25 13:44:49

标签: drools

我想积累累积结果集合的结果。问题如下:

  • 我有一组对象(SwapAllocation),可以分为不同的组(StockGroup)。
  • 小组被视为"大"如果其元素的累积值高于给定的阈值。
  • 当" large"的值的总和时,必须触发规则。群体本身超出了给定的限制。

应该翻译成类似的东西(抱歉它是在乳胶中我没有足够的代表发布图像)

\sum _{G \in \Gamma} \left(  \left\{\begin{matrix} &\text{if } \sum _{S \in G} S.nominal > 5 \text{ then } 1
\\ 
&\text{else } 0
\end{matrix}\right \right ) \leq 40

是否有" drools"这样做的方法?

我对drools规则的尝试如下:

rule "maximalCumulativeWeightLargeWeightStockPerSwap"
  when
    $sw : Swap($nominal: nominal,
               $largeWeightStockGroupThresh: largeWeightStockGroupThresh,
                $maxCumWeightLargeWeightStockGroup:
                     maxCumWeightLargeWeightStockGroup)
    $reqNominal : Number(doubleValue > $maxCumWeightLargeWeightStockGroup*$nominal ) from accumulate(
        $sg : StockGroup()
        $reqNominalSG : Number( doubleValue > $largeWeightStockGroupThresh*$nominal) from accumulate(
            $sa : SwapAllocation(swap == $sw, stock.getStockGroup() == $sg)
            sum($sa.nominal())
        )
        sum($reqNominalSG.doubleValue())
      )
  then
    scoreHolder.addHardConstraintMatch(kcontext, (int) (100 * ($maxCumWeightLargeWeightStockGroup - $reqNominal.doubleValue()/$nominal)));
end

产生

text=[ERR 102] Line 73:27 mismatched input ':' in rule "maximalCumWeightLargeWeightStockPerSwap"]

因为我似乎无法像在规则的when部分那样在累积函数中定义多个元素。

1 个答案:

答案 0 :(得分:0)

据我所知:

"A group is considered "large" if the cumulative value of its elements is above a given threshold."

我建议编写一个规则来执行insertLogical(参见“Truth Maintenance”)的辅助事实,将该组标记为“大”。

这应该简化“大”群体的积累。

(抱歉,我编辑了将怪物名称缩小为可读性。)