I have the following as a forward chaining example I am working on.
(deftemplate order-late (slot orderNumber) (slot timeDiff))
(defrule late-order
(order (orderNumber ?orderNum) (scheduledDeliveryDate ?schDeliveryDate) (expectedDeliveryDate ?expDeliveryDate))
=>
(printout t "rule fired" crlf)
(if (call ?schDeliveryDate after ?expDeliveryDate) then
(assert (order-late (orderNumber ?orderNum) (timeDiff 500)))))
(defrule late-order-subscription
(order-late (orderNumber ?orderNum) (timeDiff ?howLate))
=>
(printout t "evaluating subscription" crlf)
(if (> ?howLate 300) then (printout t ?orderNum \" is late\" crlf)))
For the example right now, order is a simple Java bean. The dates are java.util.Date. The time difference is hard coded.
Imagine I have many rules like late-order with many different facts that may be asserted. I really only care if my subscription type rules fire. It would seem like a reasonable optimization (and perhaps it just makes more sense) to transform this into a backward chaining approach.
I think I would start with:
(do-backward-chaining order-late)
Then I would add some kind of (need-late-order) to my late-order rule. However, I've tried a few different permutations of that and I haven't been able to get it to work. I'm thinking that I don't have to make any changes to my late-order-subscription rule.
Am I headed in the right direction? When I tried the changes that I mentioed, the rules do not fire. Perhaps I am messing up some syntax?
Thanks for your pointers.
Jay Baker
