• 沒有找到結果。

Chapter 5. Incremental Algorithms for Anomalies Detection

5.3. Algorithms to Update an Artifact Flow Diagram

5.3.1. Construction of XBNodes

In this section, an algorithm for the construction of XBNodes is proposed. The construction is done according to the activities in input set S. Since the algorithm for the construction is complex, three sub-functions are introduced before illustrating the algorithm.

activities in n.cv_set are not located in the same branch of x. Hence, the activities/XBNodes in S located in the same deepest XOR control blocks and branches are identified. In these identified activities/XBNodes, only one is selected to stay in S. The remainders are moved to another set for constructing another XBNode. Algorithm 5.7 shows how to identify whether the activities are located in the same deepest XOR control blocks and branches.

Algorithm 5.7 (Searching the Activities Located in the Same Deepest XOR Control Blocks and Branches)

Algorithm SearchIdenticalBranch(S){

//Input: S is a set of activities to build XBNodes.

//Output: 𝑆𝑠𝑎𝑚𝑒: The set of activities/XBNodes located in the same deepest XOR control // blocks and branches.

1. 𝑆𝑠𝑎𝑚𝑒 = ∅;

2. for each u∈S{

3. for each w∈S and w≠u{

4. if(𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢.getTopXOR() == 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑤.getTopXOR()){

5. if(w is an XBNode and w.isUncond==false){

6. 𝑆𝑠𝑎𝑚𝑒 = 𝑆𝑠𝑎𝑚𝑒 ∪ {w};

7. S = S \ {w};

8. }else if(u is an XBNode and u.isUncond==false){

9. 𝑆𝑠𝑎𝑚𝑒 = 𝑆𝑠𝑎𝑚𝑒 ∪ {u};

For an activity v, if a control block x is the deepest control block containing v, x is associated with the top element in 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑣. The function getTopXOR() gets the first element from the top of an ABStack and the type of the block associated with the element is XOR. Hence, if the results of getTopXOR() of the activities are the same, they are located in the same deepest XOR control blocks and branches. In Algorithm 5.7, the condition at line 4 identifies whether the activities/XBNodes are located in the same deepest XOR control blocks and branches. The conditions at lines 5 to 14 decide who is added into 𝑆𝑠𝑎𝑚𝑒. If u is a conditional XBNode, u is moved to 𝑆𝑠𝑎𝑚𝑒 from S. It is similar for w.

During construction of XBNodes, the activity contained in the deepest XOR control blocks is first selected to construct an XBNode. For an activity v, let xlevel denote the number of XOR control blocks containing v; hence, the activity with the maximal xlevel is selected first. The computation of xlevel of an activity/XBNode is illustrated in Algorithm 5.8.

Algorithm 5.8 (Computing xlevel for an Activity/XBNode) Algorithm XLevel(u, v){

//Input: u is an activity/XBNode in S.

// v is the activity where XBNodes are attached.

//Output: 𝑥𝑠𝑒𝑡 is the number of XOR control blocks which contain u but not v.

1. 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢 = 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢.removeIdenticalElements(𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑣);

2. xset = {e ∈ 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢| e.blockID.type = XOR};

3. return 𝑥𝑠𝑒𝑡 ; }

In Algorithm 5.8, u is an activities/XBNodes in S. At line 1, the same elements in 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢 and 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑣 are removed because the XOR control blocks containing both u and v are not needed to build XBNodes. The rest elements are stored in 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢. The number of XOR control blocks containing u but not v is equal to the number of elements

whose branchID.type is XOR in 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢. At lines 2 to 3, 𝑥𝑠𝑒𝑡 is equal to the number of elements whose branchID.type is XOR in 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑢. Therefore, 𝑥𝑠𝑒𝑡 represents the number of XOR control blocks containing u but not v.

The XBNodes are categorized into two types: unconditional and conditional. Let an XBNode n is constructed in 𝑃𝐼𝑁𝑣𝑑/𝑃𝑂𝑈𝑇𝑣𝑑 for expressing an XOR control block x. XBNode n is unconditional if each branch of x contains an activity receiving/passing d from/to v.

Otherwise, n is conditional. Algorithm 5.9 shows how to identify whether an XBNode is conditional or not.

Algorithm 5.9 (Identifying an Unconditional/Conditional XBNode) Algorithm IsUnconditional(cv_set, blockID){

//Input: cv_set is a set of activities/XBNodes which are contained in an XBNode.

// blockID is the id of an XOR control block represented by an XBNode.

//Output: true is returned if the XBNode is unconditional. Otherwise, false is returned.

1. Boolean flag = true;

2. for each u∈ cv_set {

3. if(u is an XBNode and u.isUncond == false){

4. flag = false;

5. }

6. }

7. if(blockID.totalbranches == 𝑐𝑣_𝑠𝑒𝑡 and flag == true){

8. return true;

9. }else{

10. return false;

11. } }

In Algorithm 5.9, if an XBNode contains another conditional XBNode, it is also viewed as a conditional XBNode. The for loop at lines 2 to 6 decides the Boolean value of flag by checking each element in S. The flag is false if there is a conditional XBNode in cv_set.

Otherwise, the flag is true. At lines 7 to 11, when flag is true and the number of elements in cv_set is equal to the number of branches in blockID, this function returns true; otherwise, false is returned.

Based on the sub-functions above, a complete algorithm of building XBNodes is proposed. Algorithm 5.10 shows how to build XBNodes.

Algorithm 5.10 (Building XBNodes) Algorithm BuildXBNodes(S, v, 𝑋𝐵𝑁𝑣𝑑){

//Input: S is a set of activities to build XBNodes which are attached to v.

// 𝑋𝐵𝑁𝑣𝑑 = 𝑋𝑂𝑈𝑇𝑣𝑑 or 𝑋𝐼𝑁𝑣𝑑. Each constructed XBNode is added into 𝑋𝐵𝑁𝑣𝑑. //Output: A set of XBNodes which are built completely.

1. 𝑆𝑠𝑎𝑚𝑒 = ∅;

16. n.isUncond = IsUnconditional(n.cv_set, x);

17. 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑛 = 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑥.𝑠𝑡𝑎𝑟𝑡;

23. }

24. if(𝑆𝑠𝑎𝑚𝑒≠∅)

25. XLevelList = XLevelList ∪ BuildXBNodes(𝑆𝑠𝑎𝑚𝑒, v);

26. S = XLevelList;

27. return S;

}

In Algorithm 5.10, 𝑋𝐵𝑁𝑣𝑑 is equal to 𝑋𝐼𝑁𝑣𝑑 or 𝑋𝑂𝑈𝑇𝑣𝑑. 𝑋𝐼𝑁𝑣𝑑 is a set of XBNodes, of which each is contained in 𝐸𝐼𝑁𝑣𝑑/𝑃𝐼𝑁𝑣𝑑 or contained in the XBNode in 𝐸𝐼𝑁𝑣𝑑/𝑃𝐼𝑁𝑣𝑑. On the other hand, 𝑋𝑂𝑈𝑇𝑣𝑑 is a set of XBNodes, of which each is contained in 𝐸𝑂𝑈𝑇𝑣𝑑/𝑃𝑂𝑈𝑇𝑣𝑑 or contained in the XBNode in 𝐸𝑂𝑈𝑇𝑣𝑑/𝑃𝑂𝑈𝑇𝑣𝑑.

XLevelList is a linked list and all elements in this list are sorted according to their xlevel.

The element with large xlevel, it is closer to the front side in the list. Therefore, the element obtained by XLevelList.getFirst() has the maximal xlevel in the list. At line 2, all elements in S are added into XLevelList. At line 3, m is the element which has the maximal xlevel. The while loop at lines 4 to 23 repeats until the xlevel of m becomes 0, which means all XBNodes in S are completely built. At lines 5 to 6, the activities/XBNodes identified by function SearchIdenticalBranch() are moved to 𝑆𝑠𝑎𝑚𝑒 from XLevelList. If the 𝑆𝑠𝑎𝑚𝑒 is not empty, the activities/XBNodes in 𝑆𝑠𝑎𝑚𝑒 are used to construct another XBNode recursively at lines 24 to 25.

At line 7, XOR control block x is the deepest XOR control block containing m. An XBNode n is created to represent x at lines 8 to 9. All activities/XBNodes located in x are added into n.cv_set at line 10. The for loop at lines 11 to 15 updates the properties Parent of XBNodes in n.cv_set. The function IsUncondtional() is executed to identify whether n is conditional or not at line 16. 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑛 represents the location of x; thus, 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑛 is equal to 𝐴𝐵𝑆𝑡𝑎𝑐𝑘𝑥.𝑠𝑡𝑎𝑟𝑡 at line 17. Finally, the activities/XBNodes in cv_set are removed

from S at line 18. At lines 19 to 21, n is added into XLevelList, 𝐴𝐹𝑁𝑝𝑑, and 𝑋𝐵𝑁𝑣𝑑 respectively. While all XBNodes are constructed completely, S is returned.

相關文件