【问题标题】:Jess matching rule does not fireJess 匹配规则不会触发
【发布时间】:2018-05-15 07:13:15
【问题描述】:

我在定义匹配规则时遇到了困难。

(defrule set-current  
    ?desAct <- (Actuator (name 0) (StrokeLength ?sl) (Force ?f) 
    (nominalCurrent ?c3)) 
    (test (eq ?c3 0)) ; I have defined this to change only if value is not 
                      ; set yet
    ?act <- (Actuator (inputVoltage ?v1)  ; actuator that has matching slots
    (StrokeLength ?sl1)
    (nominalCurrent ?c1))
    (test (eq ?sl1 ?sl)) ; for same stroke length I want to modify 
                         ; nominalCurrent of ?desAct
    =>
    (modify ?desAct (nominalCurrent ?c1))
    )   

?desAct 表示我想根据基于某些标准的其他现有事实更改哪些插槽值。 我不确定为什么这条规则不会因为以下事实而触发:

f-4   (MAIN::Actuator (name 4) (inputVoltage 12) (Force 17) (StrokeLength 10) (length 62) (width 18) (height 15.1) (motorType DC) (speedAtNomLoad 25) (weight 28) (nominalCurrent 0.46) (highTemp 50) (lowTemp -10) (price 90) (dutyCycle 20))
f-9   (MAIN::Actuator (name 0) (inputVoltage 12) (Force 17) (StrokeLength 10) (length 10) (width 10) (height 10) (motorType DC) (speedAtNomLoad 0) (weight 0) (nominalCurrent 0) (highTemp 0) (lowTemp 0) (price 0) (dutyCycle 0))

我期望名称为 0 且具有此规则的执行器具有与 f-4 相同的nominalCurrent,但规则不会触发。

【问题讨论】:

    标签: clips expert-system jess


    【解决方案1】:

    规则会触发但不止一次。如果您有相同模板的事实,请确保避免 1 或 2 个事实的多次匹配。

    (defrule set-current  
      ?act1 <- (Actuator (name ?n1)
                         (inputVoltage ?v1)
                         (StrokeLength ?sl1)
                         (nominalCurrent ?c1&0))
      ?act2 <- (Actuator (name ?n2&~?n1)         ; avoid redundant matches
                         (inputVoltage ?v1)      ; same input voltage
                         (StrokeLength ?sl1)     ; same stroke length
                         (nominalCurrent ?c2))   ; bind current
    =>
      (printout t "modify actuator " ?n1 " current=" ?c2 crlf)
      (modify ?act1 (nominalCurrent ?c2))
    )   
    

    约束(name ?n2&amp;~?n1) 强制匹配发生在具有不同名称值的执行器之间。重用绑定变量会强制与该值的槽匹配。

    不要使用test。与绑定变量的名称更加一致。

    【讨论】:

      猜你喜欢
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 2018-05-15
      • 1970-01-01
      • 2020-09-16
      • 2018-02-01
      相关资源
      最近更新 更多