12 Haziran 2009 Cuma

An example expert system with CLIPS - domain: ballistics

ast night, i developped a rule based system for balistics domain with clips. actually, i had developped an analog project with ESB (Expert System Builder) and the post is here: http://hilaltarakci.blogspot.com/2009/05/how-to-develop-expert-system.html

this is just a simple project to discover usage of rule based systems and expert system tools. this post includes the steps of development and the project files..

clips is a tool for building rule based systems and can be downloaded fromhttp://clipsrules.sourceforge.net/
i do not want to reinvent the wheel, so read this tutorial for using clips :http://iweb.tntech.edu/bhuguenard/ds6530/ClipsTutorial/CLIPS%20tutorial%201.htmthe tutorial consists of 6 parts. (try the addresses ....02.htm to ...06.html) a short and disciplinary tutorial, it helped me a lot..

the domain of the proposed system is balistics and the decision tree for the system is as follows:

In the above tree, rectangles represent the questions and triangles are the -probable- answers.

The .clp file for the above decision tree is:

(defrule compare-object
=>
(printout t "What do you want to compare (cartridge-case or bullet)?")
(assert (object-to-compare (read))))


(defrule comparable-ejector-mark
(object-to-compare cartridge-case)
=>
(printout t "Are the ejector marks comparable (yes or no)?")
(assert (ejector-mark-comparable (read))))


(defrule similar-ejector-mark
(and (object-to-compare cartridge-case)
(ejector-mark-comparable yes))
=>
(printout t "What is the similarity ratio of the ejector marks (high or low)?")
(assert (ejector-mark-similarity (read))))

(defrule comparable-pin-mark
(object-to-compare cartridge-case)
=>
(printout t "Are the pin marks comparable (yes or no)?")
(assert (pin-mark-comparable (read))))


(defrule similar-pin-mark
(and (object-to-compare cartridge-case)
(pin-mark-comparable yes))
=>
(printout t "What is the similarity ratio of the pin marks (high or low)?")
(assert (pin-mark-similarity (read))))

(defrule similar-breech-face
(object-to-compare cartridge-case)
=>
(printout t "What is the similarity ratio of the breech faces (high or low)?")
(assert (breech-face-similarity (read))))

(defrule comparable-set-mark
(object-to-compare bullet)
=>
(printout t "Is there a comparable set mark (yes or no)?")
(assert (set-mark-comparable (read))))


(defrule similar-set-mark
(and (object-to-compare bullet)
(set-mark-comparable yes))
=>
(printout t "Is there a highly similar set mark on the other bullet (yes or no)?")
(assert (set-mark-similarity (read))))

(defrule similar-other-set-marks
(and (object-to-compare bullet)
(set-mark-similar yes))
=>
(printout t "What is the similarity ratio when all the set marks are compared to their matching set marks taking the previously similar set mark as pivot (high or low)?")
(assert (other-set-marks-similarity (read))))

(defrule related-cartridge-cases1
(and (ejector-mark-similarity low)
(pin-mark-similarity low)
(breech-face-similarity low))
=>
(printout t "The cartridge cases are not related.")
(assert (related-cartridge-cases no)))

(defrule related-cartridge-cases2
(and (or (ejector-mark-similarity high)
(pin-mark-similarity high) )
(breech-face-similarity high))
=>
(printout t "The cartridge cases are highly probable that related, but better to consult an expert.")
(assert (related-cartridge-cases highly-probably-yes))))


(defrule related-cartridge-cases3
(and (or (ejector-mark-similarity high)
(pin-mark-similarity high) )
(breech-face-similarity low))
=>
(printout t "The cartridge cases are possible related, but better to consult an expert.")
(assert (related-cartridge-cases possibly-yes)))

(defrule related-cartridge-cases4
(and (ejector-mark-similarity low)
(pin-mark-similarity low)
(breech-face-similarity high))
=>
(printout t "The cartridge cases are possible not related, but better to consult an expert.")
(assert (related-cartridge-cases possibly-no)))

(defrule related-cartridge-cases5
(and (ejector-mark-similarity high)
(pin-mark-similarity high)
(breech-face-similarity low))
=>
(printout t "The cartridge cases are highly probably related, but consult to an expert for breech face differences.")
(assert (related-cartridge-cases highly-probably-yes))))

(defrule related-cartridge-cases6
(and (ejector-mark-similarity high)
(pin-mark-similarity high)
(breech-face-similarity high))
=>
(printout t "The cartridge cases are definitely related")
(assert (related-cartridge-cases yes)))

(defrule related-bullets1
(and (other-set-marks-similarity high)
(set-marks-similarity yes) )

=>
(printout t "The bullets are definitely related")
(assert (related-bullets yes)))

(defrule related-bullets2
(set-marks-similarity no)
=>
(printout t "The bullets are definitely not related")
(assert (related-bullets no)))


Open CLIPSWin.exe and load the above .clp file. You can examine facst and rules by (facts) and (rules) commands. Then type (run). The system will ask questions and generates the facts base according to the questions. You can examine the facts base after the run and you will see a set of facts are asserted during the run.. Here is a screenshot from CLIPS:

the end :)

Hiç yorum yok:

Yorum Gönder