Another solution to your problem could be based on a deftemplate
"Category" which is used for finding a group of experts. Experts' facts
are kept in a linked list used for assigning another expert for every
new problem. (The code assumes that one expert is servicing only one
Category, but this can be extended easily.)
(deftemplate Category
(slot catId)
(slot currExpert (default nil)))
(deftemplate Expert
(slot name)
(slot catId)
(slot prevExpert (default nil))
(slot nextExpert (default nil)))
(deftemplate Problem
(slot proId)
(slot user)
(slot catId)
(slot asgnExpert (default nil))
(slot status (default NEW)))
(defrule assignProblem
?p <- (Problem (catId ?cat)(status NEW))
?c <- (Category (catId ?cat)(currExpert ?e))
=>
(modify ?p (status ASSIGNED)(asgnExpert ?e))
(modify ?c (currExpert (fact-slot-value ?e nextExpert)))
)
(defrule addExpert
?e <- (Expert (prevExpert nil)(catId ?cat))
?c <- (Category (catId ?cat)(currExpert ?exp))
=>
(bind ?prev (fact-slot-value ?exp prevExpert))
(bind ?next (fact-slot-value ?exp nextExpert))
(modify ?e (prevExpert ?prev)(nextExpert ?next))
(modify ?prev (nextExpert ?e))
(modify ?next (prevExpert ?e))
)
(defrule addCategoryAndExpert
?e <- (Expert (prevExpert nil)(catId ?cat))
(not (Category (catId ?cat)))
=>
(assert (Category (catId ?cat)(currExpert ?e)))
(modify ?e (prevExpert ?e)(nextExpert ?e))
)
(deffunction addExpert (?name ?cat)
(assert (Expert (name ?name)(catId ?cat))))
(deffunction addProblem (?pro ?user ?cat)
(assert (Problem (proId ?pro)(user ?user)(catId ?cat)))
(run))
(reset)
(addExpert Jon cats)
(addExpert Jerry cats)
(addExpert Popeye spinach)
(run)
(addProblem 1 Ann cats)
(addProblem 2 Bea spinach)
(addProblem 3 Ann cats)
(addProblem 4 Chi cats)
(run)
(facts)
Noël Huebers wrote:
Dear Jessers,
I am developing a kind of an expert system. If a user has a problem, a
problem fact is asserted. Now I'm looking at a rule to find an expert for my
problem.
In my implementation it is possible that several experts (facts) can match
for the asserted problem.
Right now, the user with the problem receives multiple expert proposal. But
I want the user to get only one by time. Therefore, the rule should only
fire once. I tried to modify the rule with 'exists'-test. Unfortunatly, I
use some slots of the expert fact (e.g. name) on the RHS of the rule. Jess
throws an exception that the bound variable of the expert fact is unknown. I
read something according to this on the Jess book. Is there another way of
achieving this?
Another solution would be to retract the problem fact after the rule found
the first expert. But later on, I want to implement a confirmation that the
contact was established. If the expert is not available the problem fact
should remain in the working memory.
Another question is, after this problem is solved: Is it possible to
randomize the matching expert fact? I don't want the first expert in the
memory to get all of the help calls.
Thanks for your suggestions!
Best regards,
Noel Huebers
--------------------------------------------------------------------
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]
--------------------------------------------------------------------