2013-11-04 27 views
0

使用this作爲一個例子,假設有其says-什麼Rete算法發生,當有多個「然後」

if the flyer's status is silver, then allow free upgrade to business class **and** give a free drink 

應該如何Rete算法來構建網絡的條件下?在網絡底部,會有兩個節點: 1)免費升級2)免費飲料

這兩個節點應該如何鏈接到「銀色」節點?

所有我見過相關的大約一個Rete算法會談「然後」

回答

2

如果2個動作在同一規則進行,那麼只有1個動作節點將在「銀」後建造的例子alpha節點。即

rule "Allow free upgrade to business class and give a free drink to Silver flyers" 
no-loop true 
when 
    $a: Account (status == "SILVER") 
then 
    modify($a){ 
     .setFreeUpgrade(true); 
     .setFreeDrinks(true); 
    } 
end 

Drools將規則的RHS視爲黑盒子。 RHS始終表示爲RETE網絡中的「動作」節點。即使對於具有完全相同的RHS的規則也是如此:將創建兩個Action節點。

如果要實現相同的業務規則和2分獨立的規則,然後2個動作節點將要發佈:

rule "Allow free upgrade to business class to Silver flyers" 
lock-on-active true 
when 
    $a: Account (status == "SILVER") 
then 
    modify($a){ 
     .setFreeUpgrade(true);    
    } 
end 

rule "Give a free drink to Silver flyers" 
lock-on-active true 
when 
    $a: Account (status == "SILVER") 
then 
    modify($a){ 
     .setFreeDrinks(true); 
    } 
end 

我們可以進一步討論哪種方法更好,但要回答你的問題,我認爲這就足夠了:RETE網絡將包含AS MANY Action節點AS規則在您的kbase中有

如果您使用Drools的eclipse插件,您可以看到爲單個.DRL文件創建的RETE網絡。編輯DRL時,您會注意到編輯器底部的一個選項卡,用於檢查正在生成的RETE網絡。

希望它有幫助,

相關問題