Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Cheng A.Real-time systems.Scheduling,analysis,and verification.2002.pdf
Скачиваний:
64
Добавлен:
23.08.2013
Размер:
3.68 Mб
Скачать

CHENG–TSAI TIMING ANALYSIS METHODOLOGY

393

c and d, which are already pessimistic firing estimations. It makes the prediction of rule b’s firing bound looser. The estimation of rule a’s firings is even worse than that of rule b’s. Generally, the greater the number of nodes chained before node v in the ER graph, the worse the estimation of node v’s firings. Hence, we may not expect a tight estimation from static analysis. We propose another technique in the following section.

11.2.5 WM Generation

Instead of using static analysis, we generate a set of WMEs as the initial WM which maximizes the program execution time. In this manner, we are not only providing the timing bound of the OPS5 programs but also finding the most time-consuming part from the timing report generated in the OPS5 environment. This report can assist programmers in the optimization of programs through the modification of rules that are computationally expensive. Preliminary results in the automated optimization of rule-based systems can be found in [Zupan and Cheng, 1994a; Zupan and Cheng, 1998].

Maximizing Matching Time The set of WMEs that can maximize matching time is the set of all possible WMEs in the data domain. In the Rete network, the most expensive computation is to compare the WMEs in the left input node of a twoinput node to the WMEs in the right input node. This is the so-called cross-product effect [Kuo and Moldovan, 1992]. If each one-input node that is at the top level of the Rete network has a maximum number of tuples, we can ensure the beta memories are full. Thus each two-input node will have the highest timing consumption.

Maximizing Rule Firings To trigger the program to have a maximum number of rule firings, one way is to generate an initial WM that satisfies the LHS condition of each rule as many times as possible. The initial WM can be formed as the union of all positive condition elements of each rule. Consider the following rules:

(p p1

 

 

(c1

^a1 <x> ^a2 <y>)

(c2

^a1

3)

-(c3

^a1

<y> ^a2 <z>)

-->

action ...

(p p1a

(c1 ^a1 <x> ^a2 <y>)

(c2 ^a1 3) -->

action ...

The LHS condition of rule p1 is a subset of that of rule p1a. We take rule p1a instead of rule p1 as our test rule. In this way, we are making a conservative estimation since the number of firings of p1a is at least that of p1.

Example 13. An example of the union of positive condition elements.

394 TIMING ANALYSIS OF PREDICATE-LOGIC RULE-BASED SYSTEMS

(p p1

(c1 ^a1 <x> ^a2 { <y> << 1 2 >> } ) (c2 ^a1 3 ^a2 <x>)

-->

action ...

(p p2

(c1 ^a1 3 ^a2 1) -(c2 ^a1 <x> ^a2 2) -->

action ...

In example 13, the union of the positive condition elements of the above two rules is

(c1 ^a1 <x> ^a2 { <y> << 1 2 >> } )

(c2 ^a1 3 ^a2 <x>)

These are the symbolic forms of the initial WM. The actual WMEs are obtained by expanding the variables according to the attributes’ domains. For example, if the domain of attribute ^a1 in class c1 ranges over a, b, and c, and the domain of attribute ^a2 in class c1 ranges over b and c, the WMEs are generated as follows:

(c1 ^a1 b ^a2 1)

(c1 ^a1 b ^a2 2)

(c1 ^a1 c ^a2 1)

(c1 ^a1 c ^a2 2)

(c2 ^a1 3 ^a2 b)

(c2 ^a1 3 ^a2 c)

Note that attribute ^a1 in class c1 does not generate value a because its variable <x> is bound with the value of attribute ^a2 in class c2, which ranges over b and c.

The WMEs we generate can match all positive condition elements of the program. However, some of the WMEs may not be used during execution since the instantiations they are associated with may be removed by firing other instantiations. Consider the following rule.

(p a

(c1 ^a1 <x> ^a2 1)

(c2 ^b1 <z> ^b2 <y> ^b3 <x>)

(c3 ^c1 <y> ^c2 4) -->

(remove 2)

(modify 1 ^a2 <x>))

Suppose variables <x>, <y>, and <z> each have 10 items. Potentially, 10, 1000, and 10 WMEs match the first, second, and third condition elements, respectively. Let w be one of the 10 WMEs matching the first condition element, (c1 ^a1 <x> ^a2 1). So, w actually associates with 100 instantiations of this rule. After the first instantiation associated with w executes, the first action removes those WMEs, W2, which match the second condition element. Thus, at most 10 instantiations of this rule in the initial

CHENG–TSAI TIMING ANALYSIS METHODOLOGY

395

WM can be executed. The second action of this rule changes w’s content. Variables <y> and <z> actually do not affect the timing properties of this rule. Since we do not have negative condition elements in our test programs, this action to remove W2 will not cause additional rule firings. Thus, it is unnecessary to generate all WMEs satisfying the second condition element, (c2 ^b1 <z> ^b2 <y> ^b3 <x>). The action of rule a does not modify those WMEs, W3, which match the third condition element. If W3 also matches other positive condition elements of rule b, W3 can be generated in rule b. Otherwise, there is no need to generate all WMEs satisfying (c3 ^c1 <y> ^c2 4).

From the above analysis, we know that we need only to expand <x> to generate the needed WMEs. Variables <y> and <z> can be changed to any constant value in their data domain. The positive condition elements of rule a are rewritten as

(c1 ^a1 <x> ^a2 1)

(c2 ^b1 7 ^b2 5 ^b3 <x>)

(c3 ^c1 5 ^c2 4)

Variables <y> and <z> are changed to 5 and 7, respectively. There are 10, 10, and 1 WMEs associated with these three condition elements, respectively.

We now describe the algorithm to generate the initial WM. We limit the data type to literal, since most rule-based programs are used in symbolic data applications.

Algorithm 3. Generating WMEs to cause a maximum number of rule firings.

Premise: The data domain of each attribute is “literal.”

Purpose: Given an OPS5 program P, find a set of positive condition elements C. Expand the set C to a set of WMEs, W , that causes P to have a maximum number of rule firings.

1.Initialize C to the empty set.

2.For each rule r, do the following:

For each positive condition element c of rule r, if c is not a subset of any element in C, do the following steps:

(a)if the action of rule r does not modify the WMEs that satisfy c, then for each variable v associated with attribute a in c, if v does not appear in the action part of rule r, change v to a constant x, where x is in the data domain of attribute a.

(b)add c to C.

(c)for every element pc in C, if pc is a subset of c, remove pc from C.

3.Expand the positive condition elements in C to W .

In cases where rules do not generate any instantiations but they have a very high match cost, the match time must be examined with techniques proposed in [Chen and Cheng, 1995a]. Note that the critical point in this algorithm is step (a).

396 TIMING ANALYSIS OF PREDICATE-LOGIC RULE-BASED SYSTEMS

Complexity and Space Reduction We now analyze the complexity of algorithm 3. In general, O(n2) is needed to generate the positive condition elements C with n positive condition elements in the program since we check the subset relationship each time we insert a new positive condition element c into C.

The size of the set of WMEs, W , is in general exponential. If W has k variables and each variable has m data items, we will have mk WMEs as our initial WM. This size can be reduced as described in algorithm 3.

In our analysis, we consider the entire domain of each variable. However, in a real application, it is unlikely that the initial WM ranges over the whole data domain. Since rule-based programs are data-driven, certain input data are required to direct the control flows in the programs. Programmers usually embed control techniques that require the absence of or a specific order of WMEs in the program. Hence, it is more helpful if we can know the timing order of the initial WMEs or which WMEs should not appear in the initial WM.

Our solution to this is ad hoc. We allow the programmer to provide this information in terms of negative condition elements, causing the algorithm to remove the WMEs associated with these condition elements from the initially generated WM, and hence to reduce the size of the initial WM. In addition to providing negative condition elements, programmers can directly (manually) eliminate some of the WMEs we generate before their use in determining the firing sequence.

The Ordering of the Initial WMEs To find the maximal execution time (in terms of the number of rule firings and match time) of a rule base, we need to determine the firing sequences of the rules, given an initial WM. Since the strategy of selecting an instantiation from the conflict set is based on the recency of WMEs, the order in which the initial WMEs are generated becomes a factor in determining the firing sequence unless the LHS conditions of each rule are independent. Consider the following example:

(p p1

(c1 ^a1 <x> ^a2 <y>)

(c2 ^a1 3 ^a2 <x>) -->

(remove 1)) (p p2

(c1 ^a1 <x> ^a2 1)

(c2 ^a1 <x> ^a2 <y>) -->

(modify 1 ^a2 <y>))

Suppose I1 and I2 are two instantiations of rules p1 and p2, respectively. The WME (c1 ^a1 1 ^a2 1) associates with both I1 and I2. Firing one of these two instantiations will remove the other from the conflict set. Deciding which rule to fire first depends on the time tag of WMEs satisfying the second condition element of both rules, that is, (c2 ^a1 3 ^a2 <x>) and (c2 ^a1 <x> ^a2 <y>). Hence, different timing analysis results are produced if we generate the WMEs satisfying these two condition elements in different orders.

Соседние файлы в предмете Электротехника