【发布时间】: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)))
【问题讨论】: