2

我试图在 CLIPS 中定义大于规则,但它似乎不起作用。关于如何修复它的任何想法。问题似乎发生在defrule btwn100and120

(defrule part-credits
    (or (current-part "a")
        (current-part "b")
        (current-part "c"))
    =>
    (bind ?reply (get-text-from-user "How many points did you achieve?"))
    (assert (part-credits ?reply))
)

(defrule btwn100and120
    (part-credits => 100)
    (part-credits <= 120)
    =>
    (bind ?reply (get-text-from-user "Did you Part A before the changes? (y/n)"))
    (assert (btwn100and120 ?reply))
)
4

1 回答 1

4

使用该test函数进行数值比较。另外,请注意 CLIPS 对数学运算符使用前缀表示法。这是一个简化的规则,可以满足您的要求:

(defrule MAIN::btwn100and120
  (part-credits ?val)
  (test (<= ?val 120))
  (test (>= ?val 100))
=>
  (printout t "Value " ?val " is in range." crlf)
)

这是对规则的测试:

CLIPS> (watch facts)
CLIPS> (watch activations)
CLIPS> (assert (part-credits 99))
==> f-0     (part-credits 99)
<Fact-0>
CLIPS> (assert (part-credits 110))
==> f-1     (part-credits 110)
==> Activation 0      btwn100and120: f-1
<Fact-1>
CLIPS> (run)
Value 110 is in range.
CLIPS> 
于 2012-11-26T14:53:37.340 回答