Last active
February 28, 2019 07:51
-
-
Save noxdafox/e6d945f310ca0974e65aa478b915159c to your computer and use it in GitHub Desktop.
This snippet shows the behaviour of a simple CLIPS rule set with different conflict resolution strategy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftemplate complaint | |
(slot customer)) | |
(deftemplate manager | |
(slot name) | |
; managers have a list of assigned customers | |
(multislot assigned-customers)) | |
(deffunction respond-to-customer (?customer ?message) | |
(printout t "Dear " ?customer ", " crlf ?message crlf)) | |
(deffunction forward-to-manager (?manager ?complaint) | |
(printout t "New complaint " ?complaint " for manager " ?manager crlf)) | |
(defrule generic-excuse | |
; Provide a generic excuse to complaining customers | |
?complaint <- (complaint (customer ?customer)) | |
=> | |
(respond-to-customer ?customer "We are sorry for the inconvenience.") | |
(retract ?complaint)) | |
(defrule forward-complaint-to-manager | |
; Forward a complaint to the assigned manager | |
?complaint <- (complaint (customer ?customer)) | |
(manager (name ?name) (assigned-customers $?customers)) | |
; test if the customer is among the ones assigned to the manager | |
(test (member$ ?customer ?customers)) | |
=> | |
(forward-to-manager ?name ?complaint) | |
(retract ?complaint)) | |
(assert (manager (name "Nobody") (assigned-customers (create$ "Leeroy Jenkins" "John Doe")))) | |
(assert (complaint (customer "Leeroy Jenkins"))) | |
(run) | |
(reset) | |
(set-strategy complexity) | |
(assert (manager (name "Nobody") (assigned-customers (create$ "Leeroy Jenkins" "John Doe")))) | |
(assert (complaint (customer "Leeroy Jenkins"))) | |
(run) | |
(exit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment