使用Drools 6.5.0.Final
我想将缩写组合关系条件(例如Person( age > 30 && < 40 )
)与其他条件结合使用。
我尝试过,但结果规则不止一次执行。
我有一个小例子,其中检查设定点的温度偏差,允许的偏差取决于设定值。允许的偏差配置为Param
个事实,请参见下文。
如果我执行示例(fire-all-rules
):
我对缩写符号的使用是错误的还是这个错误?
示例规则:
declare Param
from : float
to : float
low : float
high : float
end
declare TemperatureEvent
@role( event )
id : String
setpoint : float
t : float
end
rule "Init abbreviated conditions test"
when
then
insert(new Param(0, 10, 1, 1));
insert(new Param(10,20, 2, 3));
insert(new TemperatureEvent("id1", 13.7f,11.5f));
// rule 1 and rule 2 should fire exactly once
end
rule "rule 1"
when
$p: Param()
$x : TemperatureEvent($p.from <= setpoint && < $p.to, (t < setpoint+$p.low || t > setpoint+$p.high))
then
System.out.println("rule 1: "+$x.getId()+" "+$x.getSetpoint()+" "+$x.getT());
end
rule "rule 2"
when
$p: Param()
$x : TemperatureEvent($p.from <= setpoint, setpoint < $p.to, (t < setpoint+$p.low || t > setpoint+$p.high))
then
System.out.println("rule 2: "+$x.getId()+" "+$x.getSetpoint()+" "+$x.getT());
end
答案 0 :(得分:0)
缩写限制
$p.from <= setpoint && < $p.to
相当于
$p.from <= setpoint && $p.from < $p.to
你想要的是
setpoint >= $p.from && < $p.to