Techniques: Procedure for Optimizing the Evaluation of Quality Rules Reuse Rule Bases

This section is designed to show you how to improve performance when working with expert rules in large models.

This page discusses:

Decrease the Number of Times the Rules Are Solved

This is one solution proposed to optimize the evaluation of Quality Rules Reuse rule base.

Tip: It is highly recommended that you use the > operator when working with 2 identical types.
WireA : Wire;WireB : Wire

if (Elec_DistanceCommon(WireA,WireB) > 100mm) Message ("Problem")

This syntax is not recommended.

In this example, the same type (wire) is used twice to compute the distance between two wires.

The rule is executed n*n times, n being the number of wires in the document.

For example, if there are three wires (wire1,wire2, and wire3), the following combinations are possible: wire1/wire1, wire1/wire2, wire1/wire3, wire2/wire1, wire2/wire2, wire2/wire3, wire3/wire1, wire3/wire2, wire3/wire3 (the rule goes through each combination).

WireA : Wire;WireB : Wire

if (WireA>WireB AND Elec_DistanceCommon(WireA,WireB) > 100mm)

Message ("Problem")

This syntax is recommended.

The combination wire1/wire1 is not useful to compute the distance, and the distance between wire1/wire2, and wire2/wire1 is identical.

The only way to optimize the rule is to add the following statement: WireA>WireB. The rule is then solved n*(n+1)/2 times.

Warning: The weight of each variable cannot be foreseen. In this example, WireA is superior to WireB. With 3 wires (wire1, wire2, and wire3), it is impossible to know in advance if wire1 > wire2 or if wire2 > wire1. This is a solution to eliminate combinations that are of no interest.

Change the Way You Use the "and" or "or" Condition

This is a solution proposed to optimize the evaluation of Quality Rules Reuse rule bases.

When using the logical operators and/or in a condition, make sure that the condition is structured as follows:

  • Attribute
  • Methods or functions that are not time-consuming (HasAttribute or GetAttributeString)
  • Methods that are time consuming (such as Electrical functions for example.)

"And" Condition

In the example below, we use the Elec_DistanceCommon function, which is very time-consuming. So, before using this function, use conditions to eliminate some cases. If one of the wires is not blue, the other conditions (WireB.Elec_Color == red AND Elec_DistanceCommon(WireA,WireB) > 100mm) are not be examined.

WireA : Wire; WireB : Wire
if (WireA.Elec_Color == blue AND WireB.Elec_Color == red AND Message("Problem")

"Or" Condition

In the example below, if one of the wires is blue, the message is fired without evaluating the other conditions, that is to say Elec_DistanceCommon which is time-consuming.

WireA : Wire; WireB : Wire
if (WireA.Elec_Color == blue OR WireB.Elec_Color == red OR El
Message("Problem")

Use Attributes instead of the GetAttribute Method

This is a solution proposed to optimize the evaluation of rule bases.

It is strongly recommended to use attributes instead of using the GetAttribute method.

Instead of: P:Part if P.GetAttributeString(PartNumber) == Part.1 Message("Problem")

Enter: P:Part if P.PartNumber == Part.1 Message("Problem")

Use the Knowledge Language

This is a solution proposed to optimize the evaluation of rule bases.

When creating rules, use the Knowledge language. Its scope is limited because it only allows the use of keywords, but in this case the process is optimized. Therefore avoid using:

  • else
  • for
  • let
  • set
  • while

Use as Few Variables as Possible

This is a solution proposed to optimize the evaluation of rule bases.

It is recommended that you use at most 2 variables. A possible workaround consists in finding the second object using the first one.

For example, when working with electrical applications, you can use two objects, the bundle and the wire. The following rule is valid:

Bundle : BundleSegment ; Wire : Wire
if (Bundle.GetAttributeBoolean(HEAT_RESISTANT) == FALSE 
AND Wire.Owner == Bundle AND Wire.GetAttributeBoolean(HEAT_RESISTANT) == FALSE)
Message("Problem")

But this rule is not optimized. This is especially true if you have many bundles and wires. The rule below is optimized as it is solved a limited number of times:

Bundle : BundleSegment
if (Bundle.GetAttributeBoolean(HEAT_RESISTANT) == FALSE 
AND Bundle.Query(X:Wire, X.GetAttributeBoolean('HEAT_RESISTANT') == FALSE) -> Size() >1)
Message("Problem")

Use CAA to Launch the Solve

This is a solution proposed to optimize the evaluation of rule bases.

To reduce the process time, if you know the objects that you want to work on, use CAA to provide the solver with instances.

Make Sure You Want to Run the Rule Base

This is a solution proposed to optimize the evaluation of rule bases.

A rule base runs globally on a whole document, that is a rule base takes into account the whole document and not a single modified item.

Handling Conditions With One Type

This is a solution proposed to optimize the evaluation of rule bases.

If there are only conditions (after the "If" keyword) with one type in the body of a rule/check, create several rules with one type in the For all () box.

S:Shell;H:Hole
If (H.Activity == true) Message("All holes are activated")
If (S.Activity == true) Message("All shells are activated")
// You must write two rules:
H:Hole
If (H.Activity == true) Message("All holes are activated")
// And
S:Shell
If (S.Activity == true)
Message("All shells are activated")