;; Can you do do something like this? Each firing of
;; calculate-center-of-gravity increments ?n in partial result and
;; adds in some more data. report-center-of-gravity then finishes the
;; calculation up. If this doesn't quite work, I'm sure there's a
;; slight variation that would. To kick off a calculation, you assert
;; (entities 1 2 3 5 7) and (partial-result 0 0 0 ).
(defrule calculate-center-of-gravity
(entities $? ?one-entity-id $?)
(entity (id ?one-entity-id) (X ?x1) (Y ?y1))
?p <- (partial-result ?n ?x ?y)
=>
;; update partial-result by accumulating one more entity)
(defrule report-center-of-gravity
(declare (salience -1))
?p <- (partial-result ?n ?x ?y)
?c <- (entities)
=>
(retract ?p ?c)
(assert (result (calculate-final-result ?n ?x ?y))))
I think Neeraj - Khandelwal wrote:
>
>
>
> I need to calculate the center of mass (an average of all their positions)
> for some number n of entities. I have a template of the form
> (ENTITY(ID)(X)(Y)). How can I write a rule to calculate it without having to
> hardcode every entity into the left side of the rule? This is not possible
> because entities may be added or deleted and I can't write a rule for every
> combination of entities. The other idea I had was to keep a field in the
> template and mark it as each entity is figured into the calculation. Once
> the calculation is complete, reset all those fields for the next time. I am
> sure there is a better way to go about this. Any help?
>
> Keith.
>
---------------------------------------------------------
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]
---------------------------------------------------------------------