No, I’m not concerned with the order in this particular case – just trying to figure out what I should be taking into account or rely on when doing the design. Thanks for taking the time to go through (now that I scrolled through it myself J ) this quite lengthy email.

 

Vlad

 


From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Michael Neale
Sent: 12 February 2007 23:53
To: Rules Users List
Subject: Re: [rules-users] fact tuples selection - what are the principles - a bit confused?

 

that sounds correct.

No you can't really depend on things happening in a certain order. of course it will be consistent between executions for the same data, but you can't count on that. It would mostly be effected by the order in which you assert facts.

I guess the question is why are you concerned in what order it does things?

Michael

On 2/13/07, Olenin, Vladimir (MOH) < Vladimir.Olenin@moh.gov.on.ca> wrote:

Hi,

I was trying to find more detailed explanation on how the fact tuples for
activations are being selected based on the constraints, but couldn't find
much. So, I guess I just want to assert my understanding of this process is
correct.

Assuming I have the following set of 'Accounts' with the fields:

ID  | Province       | City        | Type        | Balance
----------------------------------------------------------------
1  | ON             | Toronto     | Checking    | 1000
2  | BC             | Vancouver   | Checking    | 100
3  | ON             | Toronto     | Visa        | 2000
4  | ON             | Toronto     | Checking    |-100
5  | BC             | Vancouver   | Checking    | 100
6  | BC             | Vancouver   | Visa        | 150
7  | AB             | Calgary     | Checking    | 100
7  | AB             | Toronto     | Checking    | 300

I have two rules to process:

1) within each province, the sum of balances on Visa accounts should less
then 10 times the sum of balances on Checking accounts (within the same
province)
2) within each province, the sum of balances on Checking accounts should be
a positive number
3) within each province and within each city, the number of visa accounts
should be no more than 2 times the number of checking accounts

If I model my business objects like this:

1) Account  (id, province, city, type, balance)
2) Province (province)
3) City     (province, city)


And WorkingMemory will be initialized (for the data above) with:
        - 7 Account instances (ids 1 through 7)
        - 3 Province instances (ON, AB, BC)
        - 3 City instances (Toronto, Vancouver, Calgary)


Then the rules containing 'within province' would read like:
-----------------
Rule '1'
When
        Province($prov: province)
        $a: Account(province == $prov)
Then
        // accumulate sums on Checking and Visa accounts as Edson showed in
previous emails
End
-----------------


The rule containing 'within province, within city' would have then:
-------------
Rule '3'
When
        Province($prov: province)
      City($city: city, province = $prov)
        $a: Account(province = $prov, city = $city)
Then
        // accumulate sums on Checking and Visa accounts as Edson showed in
previous emails
-------------


Is this correct business object model to achieve the goal? Do I understand
correctly that the LHS statement:


        Province($prov: province)
      City($city: city, province = $prov)
        $a: Account(province = $prov, city = $city)


Can be read as:

        For each province
                For each city within the province
                        For each account for the given city and province



What 'guides' the order in which fact tuples are selected from the set of
all facts in the WorkingMemory? Can any particular sequence be guaranteed?

Thanks!

Vlad
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users