Skip to content

Instantly share code, notes, and snippets.

@noxdafox
Last active February 28, 2019 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noxdafox/e6d945f310ca0974e65aa478b915159c to your computer and use it in GitHub Desktop.
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.
(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