On Tue, Aug 19, 2008 at 8:52 AM, Jan Willem Lokin <[EMAIL PROTECTED]> wrote:
> I'd like to use a rule of the following form:
>
> (defrule rule557
>    (logical
>        (is-active (name "Some name"))
>        (in-coverage (tid ?tid) (cid ?cid) (distance ?distance&:(> 2
> (count-query-results in-coverage-nearer-query ?tid ?distance))))
>        )
>    =>
>    (assert (tracking-actual (tid ?tid) (cid ?cid)))
>    )
>
> The idea here is to limit the number of 'tracking-actual' facts w.r.t.
> to the number of 'in-coverage' facts. It doesn't work, since I still
> get a 'tracking-actual' fact for every 'in-coverage' fact.
>

I don't quite get what you really want. You'll get a match for each
distinct pairing of is-active and in-coverage, so you can't limit your
asserted tracking-actuals by the number of *either* of those two.

I'm *assuming* that you want to assign one fact of the second
category to each fact from the first, and create an actual-tracking
for each such pair. This would limit the number of dependent facts
by the minimum number of facts from the "input" facts.

So I've tried to guess, and I've come up with the code given below.
Of course, the field asgn or busy) in the remaining (not retracted)
input fact would have to be reset by an additional rule, but that's
simple.

(clear)
(reset)
(deftemplate Target   (slot name)(slot asgn))
(deftemplate Resource (slot rid)(slot busy (default FALSE)))
(deftemplate Tracker  (slot rid)(slot name))

(defrule assign
   ?t <- (Target   (name ?name)(asgn nil))
   ?r <- (Resource (rid ?rid)(busy FALSE))
=>
   (modify ?t (asgn ?rid))
   (modify ?r (busy TRUE))
)
(defrule hunt
   (logical
     ?t <- (Target   (name ?name)(asgn ?rid))
     ?r <- (Resource (rid ?rid)))
=>
   (assert (Tracker (rid ?rid)(name ?name)))
)

(bind ?targ1 (assert (Target (name "targ1"))))
(bind ?targ2 (assert (Target (name "targ2"))))
(bind ?res1 (assert (Resource (rid res1))))
(bind ?res2 (assert (Resource (rid res2))))
(bind ?res3 (assert (Resource (rid res3))))
(bind ?res4 (assert (Resource (rid res4))))

(run)
(facts)

(retract ?targ1)
(facts)


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