2014-07-25 47 views
1

我想積累累積結果集合的結果。問題如下:Drools - 累積嵌套在其他累積中

  • 我有一個對象集合(SwapAllocation),可以在不同的組(StockGroup)中進行分類。
  • 如果其元素的累積值高於給定閾值,則該羣組被視爲「大」。
  • 當「大」組的值之和本身高於給定限制時,必須觸發該規則。

應該翻譯爲類似(抱歉,這是我的乳膠沒有足夠的代表張貼圖片)

\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的規則的嘗試看起來像:

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"] 

因爲它似乎是我一個不能像我將在當節中的累加功能定義多個元素的規則。

回答

0

據我理解這一點:

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

我建議寫,做一個insertLogical規則(見「真維修」)的輔助事實,標記該組爲「大」 。

這應該簡化「大」組的積累。

(對不起,我編輯過,以減少名稱怪物的可讀性。)