无法在评估Drools中的条件时访问同一议程组中的修改后事实。

huangapple go评论66阅读模式
英文:

Cannot access the modified fact in the same agenda-group while evaluating when condition in drools

问题

我有一个具有相同议程组的规则列表。这些规则是相互依赖的。月度 PI 规则依赖于年度 PI 规则,而年度 PI 的值也是 Drools 工作内存的一个事实。只有当我更改议程组名称或移除 lock-on-active true(但即使使用 no-loop 也会进入循环)时,它才起作用。在月度 PI 规则的 when 条件中,我正在检查年度 PI 是否不为空,然后触发规则,但它不起作用,因为它不会获取更新后的值。请建议我该怎么做?

规则 "Annual P&I one"
@attribute("interestRate,originalLoanAmount")
议程组 "loaneconomics"
优先级 500
lock-on-active true
when
$loanFact:LoanFact30Yr(loan.loanEcon.interestRate!=null)
then
System.out.println("::::Annual P&I Working ::::: ");
modify($loanFact){
$loanFact.getLoanRuleResult().getLoanEconomics().setAnnualPI( /FORMULA/ );
}
end

规则 "Monthly P&I one"
@attribute("AnnualPI")
议程组 "loaneconomics"
优先级 400
lock-on-active true
when
$loanFact:LoanFact30Yr( $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI() != null )
then
System.out.println(":::: Monthly P&I Working ::::: ");
System.out.println("Monthly Payments ::: " + $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI()/12f);
modify($loanFact){
getLoanRuleResult().getLoanEconomics().setToorakMonthlyPI( $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI()/12f );
}
end

英文:

I have a list of rules with same agenda-group. These rules are interdependent. The rule monthly PI is dependent upon rule annual PI and the value of annual PI is also a fact for drools working memory. It works only when I change the agenda-group name or remove lock-on-active true (but goes into a loop even if i use no-loop). Inside when condition for monthly PI rule I'm checking if annual PI is not null then trigger the rule but it doesnt work as it doesnt fetch the updated value for it. Kindly suggest me what to do ?

rule "Annual P&I one"
@attribute("interestRate,originalLoanAmount")
agenda-group "loaneconomics"
salience 500
lock-on-active true
when 
$loanFact:LoanFact30Yr(loan.loanEcon.interestRate!=null)
then
System.out.println("::::Annual P&I Working ::::: ");

modify($loanFact){
$loanFact.getLoanRuleResult().getLoanEconomics().setAnnualPI( /*FORMULA*/  );
}
end

rule "Monthly P&I one"
@attribute("AnnualPI")
agenda-group "loaneconomics"
salience 400
lock-on-active true
when 
$loanFact:LoanFact30Yr( $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI() != null )
then
System.out.println(":::: Monthly P&I Working ::::: ");
System.out.println("Monthly Payments ::: " + $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI()/12f);
modify($loanFact){
getLoanRuleResult().getLoanEconomics().setToorakMonthlyPI( $loanFact.getLoanRuleResult().getLoanEconomics().getAnnualPI()/12f );
}
end

答案1

得分: 0

lock-on-active 基本上会在当前的 fireAllRules() 调用期间阻止任何新的激活。请查看此答案以查看可能适用于您问题的解决方案:https://stackoverflow.com/questions/17042437/what-is-the-difference-between-no-loop-and-lock-on-active-in-drools/17049887#17049887

英文:

lock-on-active will basically prevent any new activation during the current fireAllRules() invocation. Take a look at this answer to see possible solutions for your problem: https://stackoverflow.com/questions/17042437/what-is-the-difference-between-no-loop-and-lock-on-active-in-drools/17049887#17049887

huangapple
  • 本文由 发表于 2020年8月7日 19:51:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63301251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定