This is perfectly reasonable code -- nothing at all unusual about
it. It's possible that one of your predicate functions isn't
performing as expected, or something else is not quite what you
anticipate. Some ideas for debugging:
- Try all the predicate functions from the command line,
using real Beans.
- Use the (watch) command to trace activity.
- Use the (matches) function to find out what pattern-matches
succeed.
- Use the (ppdefrule) function to see how your rules are being
interpreted.
- Use the (view) command to see the compiled Rete network -- this
can help you interpret the (matches) results.
- (advanced) you can use the (progn) function to group function
calls together into "mini-procedures." The result is the result of
the last function in the group. You can use this trick to add
debug-prints to your rule LHSs, and this can help you see where
the matching succeeds or not.
I think Greger Ottosson wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
>
> 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]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------