Hi everybody,

I have a rule which fires twice and I just can't see why. So any hint would be appreciated. The rule is based on two templates defined in Java. Here are the other significant details about my program :

1) The first template is a Java class (defclass Station) and the second is a normal template (deftemplate Controller) which has only one slot (time).
2) Both templates have their SlotSpecific property assigned as true.
3) Each fields (disabled, processing, etc.) in the Station class have getter-setter methods with PropertyChangeEvents. 4) The Java program asserts a bunch of facts, imports the rules from a clp file, and calls the Rete.run() method.

Here is a simplified version of the troublesome rule :

(defrule PROCESS::process-entity
       ?fact <- (MAIN::Station (disabled FALSE)
                                             (processing FALSE)
(OBJECT ?station&:(canBeginProcessing ?station)))
                    (MAIN::Controller(time ?time))
=>
(printout t "process-entity fired" crlf)
(bind ?entity (call ?station getProcessedEntity))
(call ?entity setQueued FALSE)
(call ?entity setStation ?station)
(call ?station setProcessing TRUE)
(objectMessage ?time ?station ?fact "Station"))

canBeginProcessing (see above in LHS) is a Jess function with a guard condition. This function calls a Java method in the Station class (i.e. Station.beginProcessing()), which returns an entity that can be processed and assigned to the current station. Note that the processedEntity field is not in the LHS and as I said above, the SlotSpecific property is assigned as true for the Station template, so it is not the reason why my rule fire twice. Here is the Jess function :

(deffunction canBeginProcessing(?station)
(if (and (neq ?station nil)) then
    ;; Get the entity that can be processed.
    (bind ?entity (call ?station beginProcessing))
    ;; Assign the entity to the current station.
    (call ?station setProcessedEntity ?entity)
    ;; Return true if there is an entity.
    (return (neq ?entity nil))
else
    (return FALSE)))

Now here is the interesting part that confuses me a bit :
1) I am pretty sure that the second activation is not caused by some facts changing in another rule, because every one have a printout message and I can't retrace any of these ones. 2) I noticed that if I remove the Controller template from the LHS, the rule fire once. After all, the ?time variable has only a tracking purpose. 3) If I a rewrite the rule and the Jess function in order that there is pattern binding between Controller and Station, the rule fire also once :

(defrule PROCESS::process-entity
                    (MAIN::Controller(time ?time))
       ?fact <- (MAIN::Station (disabled FALSE)
                                             (processing FALSE)
(OBJECT ?station&:(canBeginProcessing ?station ?time)))
=>
(printout t "process-entity fired" crlf)
...)

(deffunction canBeginProcessing(?station ?time)
..)

Finally, if it can help, I am using Jess 7.0b2.

Thanks a lot for your time, once again any hint would be great !

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