Optimizing BizVR Collection Processing Using Pattern Matching and Iteration - Gnorion/BizVR GitHub Wiki

Optimizing BizVR Collection Processing

Iteration may be used when the actions of the rules do none of the following

  • modify a variable that is tested in the conditions
  • delete an item from collection currently being processed
  • add an item to the collection currently being processed

Otherwise, pattern matching is probably necessary

Single Collection

In the rulesheet

{x in COLLECTION}
if x.age>18 then x.eligible=true

Implementated in Aion

var X is &COLLECTION
for COLLECTION,x
	if x.age>18 then x.eligible=true end
end

Two Independent Collections

In the rulesheet

{x in COLLECTION}
if x.age>18 then x.eligible=true
{item in CART}
if item.type=’fresh’ then item.tax=0 

Implementated in Aion

var X is &COLLECTION
for COLLECTION,x
	if x.age>18 then x.eligible=true end
end
var item is &CART
for CART,item
	If item.type=’fresh’ then item.tax=0  end
end

One Collection two bind variables (Cartesian product)

Where DIGIT={1,2,3,4,5}

{x,y in DIGIT}
If x>3 and y<x then message
var x,y is &DIGIT
for DIGIT,x					// the  independent loop
    if x>3 then					// condition that applies only to x
	for DIGIT, y				// the dependent loop
		if y<x then message end		// condition that applies to y and x
	end
    end
end
  1. Every bind variable becomes a loop
  2. Multiple bindings in one statement will become nested loops
  3. The order of the loops will be determined as follows
  1. Any bind variables with no constraints can come first
  2. Each new loop added should be immediately followed by all the conditions it’s tested against (as long as the bind vars are available in the higher loops)
  3. if they aren’t then we have to wait until after the appropriate bind loop has been added
  1. If “distinct “ was specified then we need to add the extra conditions for distinctness
  2. Breakif stop condition needs to be added unless the user wants to process all bindings

Something along these lines anyway.

Examples where pattern matching is necessary