英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论