【问题标题】:CLIPS rule not firingCLIPS 规则未触发
【发布时间】:2022-01-19 06:09:42
【问题描述】:

尝试在 CLIPS 中一遍又一遍地运行此代码,但规则不会触发。 该规则必须将有限状态机从其当前状态转换为表单的下一个状态(输入),并且这些状态表示为事实。

(deftemplate state 
   (slot name)           ; Given the current state,
   (slot input)          ; and this input,
   (slot new-state))     ; then this is the next state 

(deffacts Figure-3-5-states
   (current-state start)
   (state (name start) (input N) (new-state 5))
   (state (name start) (input Q) (new-state 25))
   (state (name 5) (input N) (new-state 10))
   (state (name 5) (input Q) (new-state 30))
   (state (name 10) (input N) (new-state 15))
   (state (name 10) (input Q) (new-state 35))
   (state (name 15) (input N) (new-state 20))
   (state (name 15) (input Q) (new-state 35))
   (state (name 20) (input N) (new-state 25))
   (state (name 20) (input Q) (new-state 45))
   (state (name 25) (input N) (new-state 30))
   (state (name 25) (input Q) (new-state 50))
   (state (name 30) (input N) (new-state 35))
   (state (name 30) (input Q) (new-state success))
   (state (name 35) (input N) (new-state 40))
   (state (name 35) (input Q) (new-state success))
   (state (name 40) (input N) (new-state 45))
   (state (name 40) (input Q) (new-state success))
   (state (name 45) (input N) (new-state 50))
   (state (name 45) (input Q) (new-state success))
   (state (name 50) (input N) (new-state success))
   (state (name 50) (input Q) (new-state success)))

(defrule move-to-next-state
   ?current <- (current-state ?old-state)
   ?input <- (input ?value)
   (state (name ?old-state)
          (input ?value)
          (new-state ?new-state))
   =>
   (printout t "Moving from state " ?old-state " to " ?new-state 
               " given the input " ?value  crlf)
   (retract ?current ?input)
   (assert (current-state ?new-state)))

【问题讨论】:

    标签: rules clips


    【解决方案1】:

    您是否重置了 CLIPS 并声明了一个输入事实,以便匹配规则中的所有模式?

             CLIPS (6.4 2/9/21)
    CLIPS> Loading Buffer...
    %$*
    CLIPS> (reset)
    CLIPS> (agenda)
    CLIPS> (assert (input N))
    <Fact-24>
    CLIPS> (agenda)
    0      move-to-next-state: f-1,f-24,f-2
    For a total of 1 activation.
    CLIPS> (run)
    Moving from state start to 5 given the input N
    CLIPS>
    

    您可以添加规则以自动查询用户的下一个输入:

    (defrule input
       (not (input ?))
       =>
       (printout t "Input? ")
       (assert (input (read))))
    

    【讨论】:

    • 谢谢,我刚开始学习剪辑,而且很粗糙。有没有办法让我把它融入规则而不是每次都输入?可能我输入错误的方式与输入 (assert (current-state ?new-state)) 的方式相同..
    • 添加了回答规则。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2017-04-05
    • 1970-01-01
    • 2020-09-16
    相关资源
    最近更新 更多