杰西匹配规则不会发射



我在定义匹配规则方面遇到困难。

(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))
    )   

?否定的事实代表了我想根据某些标准根据其他现有事实更改的事实。我不确定为什么该规则不会遵循事实:

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相同,但规则不发射。

规则会发射,但不止一次。如果您有相同模板的事实,请确保避免进行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&~?n1)力匹配具有不同名称值的执行器之间。重复使用界变量会迫使与该值的插槽匹配。

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

最新更新