剪辑专家系统

时间:2020-11-03 16:20:43

标签: clips

我正在尝试创建一个专家系统,该系统决定您是否可以购买房屋。我想知道如何写一条规则,允许某人超过一定年龄来购买房屋。例如,如果您输入的年龄已超过40岁,系统将返回并告知您不允许购买房屋。 我已经在下面尝试过此代码,但无法正常工作

(defrule age-over-forty
    (student yes)
    (income low)
    (credit excellent)
    (age 40>)
    =>
    (printout t "You can not buy a house" crlf))

编辑:我的意思是“它不起作用”;当我运行它时,您输入一个年龄,可以说我输入了46。它会将其添加到事实中,但是应该打印出“您不能买房”,因此不符合(年龄) 40>)部分代码。

1 个答案:

答案 0 :(得分:1)

使用谓词约束(CLIPS 6.3基本编程指南的5.4.1.5节)或测试条件元素进行数值比较。

         CLIPS (6.31 6/12/19)
CLIPS> 
(defrule age-over-forty
   (student yes)
   (income low)
   (credit excellent)
   (age ?age&:(> ?age 40))
   =>
   (printout t "You can not buy a house" crlf))
CLIPS> 
(assert (student yes)
        (income low)
        (credit excellent)
        (age 46))
<Fact-4>
CLIPS> (agenda)
0      age-over-forty: f-1,f-2,f-3,f-4
For a total of 1 activation.
CLIPS> (run)
You can not buy a house
CLIPS>