Hello,

I have a question about optimizing a query in Jess.

I have (let's take round numbers) 100 care units.  Each care unit has 20
beds and on average 10 patients.
I want to match patients to their beds.  A patient has an attribute
giving its current bed.

I could write something like
(defrule ...
   (bed (id ?b))
   (patient (id ?p) (bed ?b))
   (not (the patient is attached to the bed))
   =>
   (attach the patient to the bed)
)

but then, each patient is compared to each bed, which takes 2 millions
comparisons.  I'd like to optimize that by first matching a patient to
its care unit and then comparing the patient with the beds of that care
unit.  That would take 1000*100 tests to match patients to care units
and then 1000*20 tests to find the right bed.  That is 120'000 instead
of 2'000'000 comparisons.

So I would write something like this:

(defrule ...
   (care-unit (id ?u))
   (bed (id ?b) (unit ?u))
   (patient (id ?p) (unit ?u) (bed ?b))
   (not (the patient is attached to the bed))
   =>
   (attach the patient to the bed)
)

but will it work?  Will the matching of patients to care units be
factored out and then compared only to the beds matching the care unit,
or will each patient be checked against each of the 20000 intermediates
results of the first 2 lines?

Best regards,
Florian Fischer





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