CLIPS基于规则的编程语言 - 为什么程序不运行? [英] CLIPS Rule Based Programming Language - Why the program does not run?
本文介绍了CLIPS基于规则的编程语言 - 为什么程序不运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(deffacts init-facts
(saleman s1 is city 1 3)
(goal city 5 1 km 6)
(city 1 3 km 3)
(city 3 1 km 3)
(city 1 4 km 4)
(city 4 1 km 4)
(city 1 5 km 2)
(city 5 1 km 2)
(city 3 2 km 6)
(city 2 3 km 6)
(city 5 4 km 7)
(city 4 5 km 7)
(city 5 2 km 8)
(city 2 5 km 8)
(city 4 2 km 4)
(city 2 4 km 4)
(city 5 3 km 3)
(city 3 5 km 3)
(passing 1 3 km 3 no)
(passing 3 1 km 3 no)
(passing 1 4 km 4 no)
(passing 4 1 km 4 no)
(passing 1 5 km 2 no)
(passing 5 1 km 6 no)
(passing 3 2 km 6 no)
(passing 2 3 km 6 no)
(passing 5 4 km 7 no)
(passing 4 5 km 7 no)
(passing 5 2 km 8 no)
(passing 2 5 km 8 no)
(passing 4 2 km 4 no)
(passing 2 4 km 4 no)
(passing 5 3 km 3 no)
(passing 3 5 km 3 no)
)
(defrule R1
?x <- (saleman s1 is city ?s ?)
?y <- (passing ?w ?z ? ?x ?p)
(city ?w ?z ? ?)
(test (and (= ?s ?w) (eq ?p no)))
=>
(set-strategy breadth)
(retract ?x ?y)
(assert (saleman s1 is city ?z ?s)
(passing ?w ?z km ?x yes))
)
(defrule Goal
(declare (salience 90))
(saleman s1 is city ?s ?e)
(goal city ?w ?z)
(test (and(= ?s ?w) (= ?e ?z)))
=>
(printout t "The Saleman has arrived" crlf)
(halt)
)
推荐答案
问题如下:
假设一个街头小贩从
开始城市1并想要到达城市5只穿过每个城市一次
澄清:
< br $> b $ b saleman - >我错了,我想写推销员(街头小贩)
(城市1 3 km 3)
1 - >是这个城市的名字
3 - >是邻近城市的名字
km 3 - >从1号城市到3号城市的距离
(通过1 3公里否)
no - >如果推销员没有从这个城市出来,那么标志就是否定,否则是肯定的。
$ CL $开发环境中的b $ b:>
步骤:加载缓冲区 - >重置 - >运行
CLIPS(Quicksilver Beta 3/26/08)
CLIPS>加载选择...
定义deffacts:init-facts
定义defrule:R1 + j + j + j + j
定义规则:目标= j + j + j
CLIPS> (重置)
< == f-0(初始事实)
==> f-0(初始事实)
==> f-1(销售员s1是城市1 3)
==> f-2(进球城5 1 km 6)
==> f-3(城市1 3 km 3)
==> f-4(城市3 1 km 3)
==> f-5(城市1 4 km 4)
==> f-6(城市4 1 km 4)
==> f-7(城市1 5 km 2)
==> f-8(城市5 1 km 2)
==> f-9(城市3 2 km 6)
==> f-10(城市2 3 km 6)
==> f-11(城市5 4 km 7)
==> f-12(城市4 5 km 7)
==> f-13(城市5 2 km 8)
==> f-14(城市2 5 km 8)
==> f-15(城市4 2 km 4)
==> f-16(城市2 4 km 4)
==> f-17(城市5 3 km 3)
==> f-18(城市3 5 km 3)
==> f-19(通过1 3 km 3否)
==> f-20(通过3 1 km 3 no)
==> f-21(通过1 4 km 4否)
==> f-22(通过4 1 km 4 no)
==> f-23(通过1 5 km 2 no)
==> f-24(通过5 1 km 6 no)
==> f-25(通过3 2 km 6 no)
==> f-26(传球2 3 km 6否)
==> f-27(通过5 4 km 7 no)
==> f-28(通过4 5 km 7否)
==> f-29(通过5 2 km 8 no)
==> f-30(通过2 5 km 8否)
==> f-31(通过4 2 km 4 no)
==> f-32(通过2 4 km 4 no)
==> f-33(通过5 3 km 3否)
==> f-34(通过3 5 km 3否)
CLIPS> (运行)
CLIPS>
程序崩溃的原因是什么?
The problem is as follows:
Suppose that a street vendor who begins from
the city 1 and wants to get to city 5 passing through each city only once time
clarifications:
saleman -> I was wrong,i wanted to write salesman (street vendor)
(city 1 3 km 3)
1 -> is the name of the city
3 -> is the name of neighboring city
km 3 -> the distance from city 1 to city 3
(passing 1 3 km no)
no -> if the salesman has not passing from this city then the flag is no, else is yes
in CLIPS development environment:
steps: load buffer -> reset -> run
CLIPS (Quicksilver Beta 3/26/08)
CLIPS> Loading Selection...
Defining deffacts: init-facts
Defining defrule: R1 +j+j+j+j
Defining defrule: Goal =j+j+j
CLIPS> (reset)
<== f-0 (initial-fact)
==> f-0 (initial-fact)
==> f-1 (saleman s1 is city 1 3)
==> f-2 (goal city 5 1 km 6)
==> f-3 (city 1 3 km 3)
==> f-4 (city 3 1 km 3)
==> f-5 (city 1 4 km 4)
==> f-6 (city 4 1 km 4)
==> f-7 (city 1 5 km 2)
==> f-8 (city 5 1 km 2)
==> f-9 (city 3 2 km 6)
==> f-10 (city 2 3 km 6)
==> f-11 (city 5 4 km 7)
==> f-12 (city 4 5 km 7)
==> f-13 (city 5 2 km 8)
==> f-14 (city 2 5 km 8)
==> f-15 (city 4 2 km 4)
==> f-16 (city 2 4 km 4)
==> f-17 (city 5 3 km 3)
==> f-18 (city 3 5 km 3)
==> f-19 (passing 1 3 km 3 no)
==> f-20 (passing 3 1 km 3 no)
==> f-21 (passing 1 4 km 4 no)
==> f-22 (passing 4 1 km 4 no)
==> f-23 (passing 1 5 km 2 no)
==> f-24 (passing 5 1 km 6 no)
==> f-25 (passing 3 2 km 6 no)
==> f-26 (passing 2 3 km 6 no)
==> f-27 (passing 5 4 km 7 no)
==> f-28 (passing 4 5 km 7 no)
==> f-29 (passing 5 2 km 8 no)
==> f-30 (passing 2 5 km 8 no)
==> f-31 (passing 4 2 km 4 no)
==> f-32 (passing 2 4 km 4 no)
==> f-33 (passing 5 3 km 3 no)
==> f-34 (passing 3 5 km 3 no)
CLIPS> (run)
CLIPS>
why the program crashes?
这篇关于CLIPS基于规则的编程语言 - 为什么程序不运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文