Optimizing the Evaluation of Knowledge Expert Rule Bases    

This topic is designed to show you how to improve performances when working with Knowledge Expert rules in large models.

Methodology

The proposed solutions to improve performances are the following:

Decrease the number of times the rules are solved

To do so, it is highly recommended to use the > operator when working with 2 identical types.

WireA : Wire;WireB : Wire
if (Elec_DistanceCommon(WireA,WireB) > 100mm)
Message ("Problem")
Not recommended: In the example opposite, the same type (wire) is used twice to compute the distance between two wires :

we go through the rule n² times, n being the number of wires in the document. We have three wires (wire1,wire2, and wire3), so 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")

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 (see opposite.) The rule is then solved n*(n+1)/2 times.

Warning: The weight of each variable cannot be foreseen. In the 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. It is a a way to eliminate combinations that are not interesting.

Change the way you use the And or Or condition

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

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

WireA : Wire; WireB : Wire

if (WireA.Elec_Color == "blue" AND WireB.Elec_Color == "red" AND Elec_DistanceCommon(WireA,WireB) > 100mm)

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 Elec_DistanceCommon(WireA,WireB) > 10mm)

Message("Problem")

Use attributes instead of the GetAttribute method

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

So, instead of writing:

P:Part
if P->GetAttributeString("PartNumber") == "Part.1"
Message("Probleme")

Write:

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

 

Use the Knowledge Expert language

When creating rules, use the Knowledge Expert language. Its scope is limited because it allows the use of the If...then keywords only, but only in this case the process time will be optimized.
Therefore avoid using the following constructs:

Use less variables as possible

It is recommended to 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, we may 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, the rule 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

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

Use Manual Update when working with complex Rule Bases

Prefer Manual Update instead of Automatic Update when working in a Part context. Using the Automatic Update increases the global computation time when using a complex Rule Base.

You can manually update a Rule Base by:

Make sure you want to run the Rule Base

A Rule base runs globally on a whole document. i.e. a Rule Base takes into account the whole document and not a single modified item.