【问题标题】:Drools: how to use abbreviated condition notation together with further conditions?Drools:如何将缩写条件表示法与进一步条件一起使用?
【发布时间】:2016-12-20 18:29:59
【问题描述】:

使用 Drools 6.5.0.Final

我想结合其他条件使用缩写组合关系条件(例如Person( age > 30 && < 40 ))。 我试过了,但是生成的规则被执行了不止一次。

我有一个小例子,其中检查了与设定点的温度偏差,允许的偏差取决于设定点。允许的偏差使用Param 事实配置,见下文。 如果我执行示例(fire-all-rules):

  • 规则 1 触发两次(错误?)
  • 规则 2 按预期触发一次(没有缩写符号)。

是我对缩写符号的使用错误还是这是一个错误?

示例规则:

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

【问题讨论】:

    标签: drools


    【解决方案1】:

    缩写限制

     $p.from <= setpoint && < $p.to
    

    等价于

     $p.from <= setpoint && $p.from < $p.to
    

    你想要的是

     setpoint >= $p.from && < $p.to
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2019-10-16
      • 2011-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多