【问题标题】:CLIPS(arguments) - family relations: how to avoid an issue of one person being a brother of himself?CLIPS(arguments) - 家庭关系:如何避免一个人成为自己兄弟的问题?
【发布时间】:2019-03-31 04:51:15
【问题描述】:

简介

我正在尝试用 CLIPS 语言实现一个规则——一个人是另一个人的兄弟的关系。 约束是这样的规则只能从以下前提推导出来:

(male ?x) ("x 是女性")

(female ?y) ("y 是女性")

(mother-of ?x ?y) ("x is a mother of y")

(father-of ?x ?y) ("x is a Father of y")

我的尝试

我写了以下代码:

(deftemplate father-of 
    (slot father)
    (slot child)
)

(deftemplate mother-of 
    (slot mother)
    (slot child)
)

(deftemplate male 
    (slot person)
)

(deftemplate female
     (slot person)
)

(deffacts family
    (father-of (father John) (child Mark))
    (father-of (father John) (child Mary))
    (mother-of (mother Alice) (child Mark))
    (mother-of (mother Alice) (child Mary))
    (male (person John))
    (male (person Mark))
    (female (person Alice))
    (female (person Mary))
)

(defrule brother
    (and
        (male (person ?alpha))
        (mother-of (mother ?x) (child ?alpha))
        (father-of (father ?y) (child ?alpha))
        (mother-of (mother ?x) (child ?beta))
        (father-of (father ?y) (child ?beta))
    )
    =>
    (printout t ?alpha " is a brother of " ?beta crlf)
    (assert (brother ?alpha ?beta))
)

问题的要点

上面的代码编译并返回“true”(换句话说,构造的规则在逻辑上是正确的)。

然而,有一个微妙的问题:

如何避免添加事实的问题,例如“马克是马克的兄弟”(我们假设每个名字都是唯一的,所以同名对应同一个人)?显然,这样的事实是错误的,但我的规则却输出了这样的愚蠢。

上面的代码没有处理这个问题。

如何解决这个问题?

致谢

感谢您在这个问题上的帮助!!!

【问题讨论】:

    标签: logic relationship clips expert-system


    【解决方案1】:

    将第二个母亲模式中的约束 ?beta 更改为 ?beta&~?alpha。

    (defrule brother
        (and
            (male (person ?alpha))
            (mother-of (mother ?x) (child ?alpha))
            (father-of (father ?y) (child ?alpha))
            (mother-of (mother ?x) (child ?beta&~?alpha))
            (father-of (father ?y) (child ?beta))
        )
        =>
        (printout t ?alpha " is a brother of " ?beta crlf)
        (assert (brother ?alpha ?beta))
    )
    

    【讨论】:

      【解决方案2】:

      这是我的独立解决方案:

      (defrule brother
          (and
              (male (person ?alpha))
      
              (or
                   (male (person ?beta))
                   (female (person ?beta))
               )
      
              (mother-of (mother ?x) (child ?alpha))
              (father-of (father ?y) (child ?alpha))
              (mother-of (mother ?x) (child ?beta))
              (father-of (father ?y) (child ?beta))
              (test (neq ?alpha ?beta))
          )
          =>
          (printout t ?alpha " is a brother of " ?beta crlf)
          (assert (brother ?alpha ?beta))
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-26
        • 2018-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多