我在定义匹配规则方面遇到了困难。
(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的Actuator与此规则具有与f-4相同的nominalCurrent,但规则不会触发。
答案 0 :(得分: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&~?n1)
强制匹配在具有不同名称值的执行器之间发生。重用绑定变量会强制匹配该值的插槽。
请勿使用test
。与绑定变量的名称更加一致。