Hi,
Short answer: yes, the restrictions are cumulative. In your last rule,
a patient is checked only against beds in their own unit -- or only
units containing the patient's own bed are considered (we can't know
just from this which way Jess will decide to evaluate the rule.)
But note that in no case would Jess actually do the full 2 million
comparisons. In the first rule, the beds would be hashed into some
number of buckets (depending on the total number of beds and how the
ids are distributed,) and the patient's bed id checked only against
the beds in one of those buckets. Likewise, when you add the unit
pattern, first the units will be divided into buckets, the beds
checked against units in one bucket each, and then those pairs would
be in buckets, with each patient checked only against the contents of
one bucket.
On Jul 2, 2008, at 8:44 AM, Florian Fischer wrote:
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]
.
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com
--------------------------------------------------------------------
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]
--------------------------------------------------------------------