[rules-users] fact tuples selection - what are the principles - a bit confused?

Olenin, Vladimir (MOH) Vladimir.Olenin at moh.gov.on.ca
Mon Feb 12 15:33:32 EST 2007


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



More information about the rules-users mailing list