the example confuses me a bit. If I had to do the same thing the rule
might look like this.

(defrule assignBed
    ?patient <- (patient
        (id ?p)
        (unit ?u)
        (bed ?b&:(eq ?b 0) ) ;; if the patient hasn't been assinged.
assuming unassigned is zero
    )
    (care-unit
        (id ?u) ;; join on the patient's assigned care-unit
        (availableBeds ?beds&:(> ?beds 0) ) ;; checks to see if unit
has available bed
    )
    (bed
        (id ?bedid) ;; bind bed id to variable "?bedid"
        (unit ?u) ;; join on the care-unit
    )
=>
    (modify ?patient (bed ?bedid) )
)

The example in the email wouldn't work, since it would only match
patients that are already assigned to a bed in a care unit. I'm
guessing, you only want to assign beds to patients without an assigned
bed. The first pattern checks to make sure it doesn't try to find a
bed for patient that already has one.

doing it this way, the search space should be considerably smaller.

peter

On Wed, Jul 2, 2008 at 8:44 AM, Florian Fischer
<[EMAIL PROTECTED]> 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]
> --------------------------------------------------------------------
>
>


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