In the program below, Jess will only fire the second rule if both are uncommented, but each of them fires if the other one isn't there. If the order of rule definitions is reversed, the second one "wins" again.

Jess Version 7.0p1

Kind regards
Wolfgang

(clear)

(deftemplate Obj
   (slot id           (type STRING))
)

(deftemplate Room extends Obj
   (slot occupied (type SYMBOL)(default false)) ; Boolean
)

(deftemplate Suite extends Room
   (slot rooms (type INTEGER)))

(deftemplate Single extends Room)
(deftemplate Double extends Room)


(deftemplate NextTo
   (slot room1 (type STRING))
   (slot room2 (type STRING))
)

(deffacts fact-23
   (Suite  (id "100") (rooms 3))
   (Single (id "101"))
   (Double (id "102"))
   (Double (id "103"))

   (NextTo (room1 "100")(room2 "101"))
   (NextTo (room1 "101")(room2 "100"))
   (NextTo (room1 "101")(room2 "102"))
   (NextTo (room1 "102")(room2 "101"))
   (NextTo (room1 "102")(room2 "103"))
   (NextTo (room1 "103")(room2 "102"))
)

(reset)

;;/***
(defrule oneNext
   "Check that a suite has exactly one neighbour."
   (Suite (id ?rid))
   ?sn <- (accumulate (bind ?xcount 0) (++ ?xcount) ?xcount
                      (NextTo (room1 ?rid)))
   (test (= ?sn 1))
   =>
   (printout t "===> Suite " ?rid " has " ?sn " neighbours." crlf)
)
;;***/

;;/***
(defrule maxNext
   "Check that no room is next to three or more."
   (Room (id ?rid))
   ?nc <- (accumulate (bind ?count 0) (++ ?count) ?count
                      (NextTo (room1 ?rid)))
   (test (<= ?nc 2))
   =>
   (printout t  "---> " ?rid " has " ?nc " neighbours." crlf)
)
;;***/

(run)


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to