What you really want is the "forall" conditional element, which isn't
implemented yet in Jess, although should be in the next release. 

(forall (person (name ?Name))
        (instruction (name ?Name) (counted true)))

means "for each person, there is a corresponding instruction," which
is exactly what you want.

One way you could do it now would be to put a (has-intruction) slot in
person. Then the count-instruction rule could modify person to set
that slot to true. Then got-all-instructions would look like

(defrule got-all-instructions ""
      ?Mode <- (current-mode (mode collect))
      (not (person (has-intruction false)))
      =>
      (modify ?Mode (mode process))
    )                              

You don't need not-all-instructions-in-yet.


I think [EMAIL PROTECTED] wrote:
> 
> 
> I'm trying to figure out the best way to handle this situation.
> 
> My program has two "modes".  In the first, the program collects "instructions",
> and in the second, the instructions are "processed".  Now the program shouldn't
> go into the second mode until all the instructions are received.  There are X
> number of people (represented by facts), and each one should have an instruction
> (also represented by a fact).  So the program should wait in the first mode
> until all X instructions have been received, then it should go process them.
> The number of people can change from run to run of the program, and the
> instructions can be asserted in any order.
> 
> This won't work.  (assuming all deftemplates are already stated) :
> 
> (current-mode (mode collect))
> 
> (defrule count-instruction ""
>      (person (name ?Name))
>      (instruction (name ?Name) (counted false))
>      ?Instruction <- (instruction (name ?Name) (counted false))
>      =>
>      (modify ?Instruction (counted true))
> )
> (defrule got-all-instructions ""
>      ?Mode <- (current-mode (mode collect))
>      (person (name ?Name))
>      (instruction (name ?Name) (counted true))
>      =>
>      (modify ?Mode (mode process))
> )
> (defrule not-all-instructions-in-yet ""
>      ?Mode <- (current-mode (mode collect))
>      (person (name ?Name))
>       ; This should catch a missing instruction and one that has not been
> "counted" yet.
>      (not (instruction (name ?Name) (counted true)))
>      =>
>      (modify ?Mode (mode collect))
> )
> 
> And I have yet to come up with a good mechanism.  What pattern have other people
> used for this situation?
> 
> -Chuck.
> 
> 
> 
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------

Reply via email to