Hi,

I have a question regarding the evaluation of 'not' conditional
elements, or more precisely how to have them evaluated when I want them
to.  But let me give you a brief overview of what I do.

I'm using Jess to build a (for now) fairly simple router.  Basically,
there's work items which needs to be assigned (routed) to agents.
Item's and Agent's are beans. Proporties are integer 'difficulty' for
Item's which are matched against integer 'skill' for agents.  Agents are
'available' (or not), and Item's are 'assigned' (or not).

The main rule included below.

My problem is with the 'not' matching patterns, which does not seem to
get evaluated when I would want them to.  According to the manual (I'm
using Jess 6.0a8) they are evaluated when the preceding pattern is
evaluated.  I'm generating items dynamically, and sometimes this causes
the rule to fire, and sometimes it doesn't (it hangs, not firing, and
thereby not assigning items to agents although they are available and
qualified).  I assume this is related to the 'not' conditionals.

I've experimented with a '(wakeup)' fact, placed just above the 'not'
patterns, but I haven't been able to control this successfully.

Any tips on how to do this, or is there a better way to achieve what I
want?  I'd prefer not generating lots of facts, including doing
backwards chaining, since I might have lots of items and agents.  

Is this a common use of/problem with rules?

Best regards,
/Greg


---x---
(defclass item workrouter.Item)
(defclass agent workrouter.Agent)

(defrule route-item
  ;; Match a unassigned item C1...
  (item (name ?cname1) (assigned FALSE) (OBJECT ?item1))
  ;; ...with an available, qualified agent A1...
  (agent (available TRUE) (OBJECT ?agent1
                                  &:(qualified ?agent1 ?item1)))
;  (wakeup)
  ;; unless there's another available, qualified agent A2 with lower
skills...
  (not (agent (available TRUE) (OBJECT ?agent2
                                       &~?agent1 
                                       &:(cheaper ?agent2 ?agent1)
                                       &:(qualified ?agent2 ?item1))))
  ;; and unless there's an older item which agent A1 can handle.
  (not (item (assigned FALSE) (OBJECT ?item2
                                      &~?item1 
                                      &:(older ?item2 ?item1)
                                      &:(qualified ?agent1 ?item2))))
  =>
  (printout t "Assigning " ?cname1 " to " (get ?agent1 name) "." crlf)
  (set ?item1 assigned TRUE)
  (set ?agent1 available FALSE)
  )

(deffunction qualified (?agent ?item)
  (>= (get ?agent skill)
      (get ?item difficulty)))

(deffunction cheaper (?agent1 ?agent2)
  (< (get ?agent1 skill)
     (get ?agent2 skill)))

(deffunction older (?item1 ?item2)
  (< (get ?item1 stamp)
     (get ?item2 stamp)))
---x---

greger ottosson
developer/architect
the eon company
www.eoncompany.com

o 212.401.5000
m 917.754.2116
e [EMAIL PROTECTED]

---------------------------------------------------------------------
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