【问题标题】:CLIPS control factCLIPS 控制事实
【发布时间】:2018-09-12 19:28:00
【问题描述】:

我有这个剪辑程序,它使用显着性来获取消息“欢迎使用建议系统”。总是首先出现,但我想知道如何在不使用显着性的情况下使用控制事实来做到这一点。

  1  (deffacts prerequisites
  2  (after COP1000 take COP2000)
  3  (after COP1001 take COP2001)
  4  (after MAC1000 take MAC2000)
  5  (after MAC1001 take MAC2001)
  6  (after ENG1000 and ENG1001 take ENG2000))
  7 
  8  (defrule welcome
  9  (declare (salience 10000))
 10   =>
 11   (printout t "Welcome to the advising system." crlf))
 12   
 13  (defrule rule2
 14   (after ?course1 take ?course2)
 15   (student ?name $? ?course1 $?)
 16   =>
 17   (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf))

【问题讨论】:

    标签: clips


    【解决方案1】:
    CLIPS> 
    (deffacts prerequisites
       (after COP1000 take COP2000)
       (after COP1001 take COP2001)
       (after MAC1000 take MAC2000)
       (after MAC1001 take MAC2001)
       (after ENG1000 and ENG1001 take ENG2000)
       (student Cindy COP1000 MAC1001)
       (phase welcome))
    CLIPS>   
    (defrule welcome
       ?f <- (phase welcome)
       =>
       (retract ?f)
       (assert (phase process))
       (printout t "Welcome to the advising system." crlf))
    CLIPS>   
    (defrule rule2
       (phase process)
       (after ?course1 take ?course2)
       (student ?name $? ?course1 $?)
       =>
       (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf))
    CLIPS> (reset)
    CLIPS> (watch facts)
    CLIPS> (watch activations)
    CLIPS> (watch rules)
    CLIPS> (run)
    FIRE    1 welcome: f-7
    <== f-7     (phase welcome)
    ==> f-8     (phase process)
    ==> Activation 0      rule2: f-8,f-1,f-6
    ==> Activation 0      rule2: f-8,f-4,f-6
    Welcome to the advising system.
    FIRE    2 rule2: f-8,f-4,f-6
    Since Cindy has taken MAC1001 , I suggest taking MAC2001.
    FIRE    3 rule2: f-8,f-1,f-6
    Since Cindy has taken COP1000 , I suggest taking COP2000.
    CLIPS>
    

    【讨论】:

      【解决方案2】:

      如果您想要多个阶段(比如两个以上),我会坚持 Gary Riley 的方法。但是,如果您的愿望是一个简单的预触发规则,我建议您根据控制标志对事实进行初始声明。

      (defrule prerequisites
        (preinit-done)
        =>
        (assert
          (after COP1000 take COP2000)
          (after COP1001 take COP2001)
          (after MAC1000 take MAC2000)
          (after MAC1001 take MAC2001)
          (after ENG1000 and ENG1001 take ENG2000))
      )
      
      (defrule welcome
        (not (preinit-done))
        =>
        (printout t "Welcome to the advising system." crlf)
        (assert (preinit-done))
      )
      
      (defrule rule2
         (after ?course1 take ?course2)
         (student ?name $? ?course1 $?)
         =>
         (printout t "Since " ?name " has taken " ?course1 " , I suggest taking " ?course2 "." crlf)
      )
      

      这样您就不必为每个规则添加阶段事实,只要它们以某种方式依赖于您的初始事实。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-22
        相关资源
        最近更新 更多