【问题标题】:CLIPS search for a fact matching conditions in RHSCLIPS 在 RHS 中搜索事实匹配条件
【发布时间】:2014-02-03 01:27:48
【问题描述】:

我已经为此苦苦挣扎了一段时间,但没有找到关于如何完成我将要说明的内容的参考。 假设我有一个单元格网格,每个单元格对应于以下模板:

(deftemplate cell 
    (slot x)
    (slot y)
    (slot type (allowed-values urban rural lake hill gate border))
)

现在我的网格中的单元格类型是使用(assert (cell (x <x_coord>) (y <y_coord>) (type <some_type>)) 语句随机生成的,我想定义以下规则,它检查 3x3 范围内的所有单元格,以中心单元格为中心,并根据类型采取行动检查的细胞数:

(defrule inspect
    (cell (x ?xval) (y ?yval))
    ; ...
=>
    (loop-for-count (?i -1 1) do
        (loop-for-count (?j -1 1) do
            ; get "type" of cell @ coordinates (- ?x ?i ), (+ ?y ?j)
            ; do stuff according to type (i.e. assert other facts)
        )
    )
)

在 CLIPS 规则的 RHS 上给定特定标准(在本例中为单元格坐标),我将如何查找事实?我知道如何在 LHS 上进行模式匹配,但我很想知道是否也可以在 RHS 上这样做。 提前致谢。

【问题讨论】:

    标签: artificial-intelligence expert-system clips


    【解决方案1】:

    使用事实集查询函数(基本编程指南中的第 12.9.12 节):

    CLIPS> 
    (deftemplate cell 
       (slot x)
       (slot y)
       (slot type (allowed-values urban rural lake hill gate border)))
    CLIPS> 
    (deftemplate inspect
       (slot x)
       (slot y))
    CLIPS> 
    (deffacts example
       (inspect (x 3) (y 3))
       (cell (type urban) (x 1) (y 1))
       (cell (type rural) (x 2) (y 3))
       (cell (type lake) (x 4) (y 4))
       (cell (type border) (x 4) (y 4))
       (cell (type hill) (x 3) (y 5))
       (cell (type gate) (x 3) (y 3)))
    CLIPS> 
    (defrule inspect
       ; Changed to inspect so the example does
       ; not fire this rule for every cell
       (inspect (x ?xval) (y ?yval))  
       =>
       (do-for-all-facts ((?c cell))
                         (and (<= (- ?xval 1) ?c:x (+ ?xval 1))
                              (<= (- ?yval 1) ?c:y (+ ?yval 1)))
          (printout t ?c:type " " ?c:x " " ?c:y crlf)))
    CLIPS> (reset)
    CLIPS> (run)
    rural 2 3
    lake 4 4
    border 4 4
    gate 3 3
    CLIPS>
    

    【讨论】:

    • 很抱歉没有尽快回复,我已经离开几天了,刚刚有机会尝试您的解决方案。它就像一个魅力,谢谢。干杯。
    • 但是,我找不到您所指的参考资料(第 12.9.12 节);我在网上只能找到this,你可以看到它只到第 12.9.6 节。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多