Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Clustering Using Bunch

Similar presentations


Presentation on theme: "Software Clustering Using Bunch"— Presentation transcript:

1 Software Clustering Using Bunch
Reverse Engineering (Bunch)

2 Software Clustering Environment
Source Code Source Query Source Analyzer Code Script Code (e.g., Chava) Database (e.g., AWK) Module Dependency Graph Graph Layout & Bunch Clustered Visualization Output Clustering Graph Utility File Tool (e.g., dotty) Reverse Engineering (Bunch)

3 The Structure of a Graphical Editor
main Event boxParserClass boxClass error stackOfAnyWithTop boxScannerClass Fonts Globals Mathlib EdgeClass ColorTable stackOfAny Lexer hashedBoxes hashGlobals GenerateProlog NodeOfAny Reverse Engineering (Bunch)

4 The Software Clustering Problem
“Find a good partition of the Software Structure.” A partition is the decomposition of a set of elements (i.e., all the nodes of the graph) into mutually disjoint clusters. A good partition is a partition where: highly interdependent nodes are grouped in the same clusters independent nodes are assigned to separate clusters Reverse Engineering (Bunch)

5 Not all Partitions are Created Equal ...
Good Partition! N2 N4 N1 Bad Partition! N2 N4 N3 N5 N1 N2 N4 N3 N5 N6 N3 N5 N6 N6 Reverse Engineering (Bunch)

6 Reverse Engineering (Bunch)
Our Assumption “Well designed software systems are organized into cohesive clusters that are loosely interconnected.” Reverse Engineering (Bunch)

7 Problem: There are too many partitions of the MDG…
The number of MDG partitions grows very quickly, as the number of modules in the system increases… î í ì + = Ú - otherwise kS S n k if , 1 1 = 1 2 = 2 3 = 5 4 = 15 5 = 52 6 = 203 7 = 877 8 = 4140 9 = 21147 10 = 11 = 12 = 13 = 14 = 15 = 16 = 17 = 18 = 19 = 20 = A 15 Module System is about the limit for performing Exhaustive Analysis Reverse Engineering (Bunch)

8 Reverse Engineering (Bunch)
Edge Types With respect to each cluster, there are two different kinds of edges:  edges (Intra-Edges) which are edges that start and end within the same cluster  edges (Inter-Edges) which are edges that start and end in different clusters CLUSTER Other Clusters a b c Reverse Engineering (Bunch)

9 A Partition of the Structure of the Graphical Editor
Main Generate Prolog boxParserClass Event boxScanner Class Globals boxClass error stackOfAnyWithTop Lexer stackOfAny hashedBoxes edgaClass MathLib colorTable Fonts NodeOfAny hashGlobals Reverse Engineering (Bunch)

10 Example: The Structure of the dot System
Reverse Engineering (Bunch)

11 Example: The Structure of the dot System
4/26/2017 Example: The Structure of the dot System The Module Dependency Graph (MDG) We represent the structure of the system as a graph, called the MDG The nodes are the modules/classes The edges are the relations between the modules/classes Consistant way to represent the system, independent of the programming language Reverse Engineering (Bunch)

12 Example: The Structure of the dot System
4/26/2017 Example: The Structure of the dot System Dot is a reasonably small system, but its structure is complex and hard to understand… Consistant way to represent the system, independent of the programming language Reverse Engineering (Bunch)

13 The dot System after Clustering and Filtering
The clustered view highlights… Identification of “special” modules (relations are hidden to improve clarity) Subsystems that group common features Relations Between the Modules Modules From the Source Code Reverse Engineering (Bunch)

14 The dot System after Clustering and Filtering
The Partitioned Module Dependency Graph (MDG) The partitioned MDG contains clusters that group related nodes from the MDG. The clusters represent the subsystems The subsystems highlight high-level features or services provided by the modules in the cluster. Reverse Engineering (Bunch)

15 The dot System after Clustering and Filtering
The clustered view of dot (its partitioned MDG) is easier to understand than the unclustered view… Reverse Engineering (Bunch)

16 Example: The MDG for Apache’s Regular Expression class library
4/26/2017 Step 1: Creating the MDG Example: The MDG for Apache’s Regular Expression class library Source Code void main() { printf(“hello”); } Source Code Analysis Tools Acacia Chava Different MDG inputs, produce different partitioned outputs. This is good for understanding different views of the software system. How to create an MDG is still an open area. Weights, especially. Ex: How do you weight a global variable access versus calling through a public interface. What if subsystem interfaces were available --- high edge weights would be good here, but bad in other circumstances… The MDG can be generated automatically using source code analysis tools Nodes are the modules/classes, edges represent source-code relations Edge weights can be established in many ways, and different MDGs can be created depending on the types of relations considered Reverse Engineering (Bunch)

17 Example: The MDG for Apache’s Regular Expression class library
4/26/2017 Step 1: Creating the MDG Example: The MDG for Apache’s Regular Expression class library Source Code void main() { printf(“hello”); } Automatic MDG Generation We provide scripts on the SERG web page to create MDGs automatically for systems developed in C, C++, and Java. The MDG eliminates details associated with particular programming languages Source Code Analysis Tools Acacia Chava Can create MDGs manually if needed, or using other tools for languages besides C/C++/Java The relations may vary also depending on the ways that the relations are defined The MDG is the input, so how it is created biases the clustering output The MDG can be generated automatically using source code analysis tools Nodes are the modules/classes, edges represent source-code relations Edge weights can be established in many ways, and different MDGs can be created depending on the types of relations considered Reverse Engineering (Bunch)

18 Why do we want to Cluster?
To group components of a system. Grouping gives some semantic information We find out which components are strongly related to each other. We find out which components are not so strongly connected to each other. This gives us an idea of the logical subsystem structure of the entire system. Reverse Engineering (Bunch)

19 Clustering useful in practice?
Documentation may not exist. As software grows, the documentation doesn’t always keep up to date. There are constant changes in who uses and develops a system. Reverse Engineering (Bunch)

20 Our Approach to Automatic Clustering
“Treat automatic clustering as a searching problem” Maximize an objective function that formally quantifies of the “quality” of an MDG partition. We refer to the value of the objective function as the modularization quality (MQ) MQ is a Measurement and not a Metric Reverse Engineering (Bunch)

21 Why automatic clustering?
Experts are not always available. Gives the previously mentioned benefits without costing much. Reverse Engineering (Bunch)

22 How does clustering help?
Helps create models of software in the absence of experts. Gives the new developers a ‘road map’ of the software’s structure. Helps developers understand legacy systems. Lets developers compare documented structure with some ‘inherent’ structure of the system. Reverse Engineering (Bunch)

23 Module Dependency Graph
Represents the dependencies between the components of a system. Nodes are components: Classes, modules, files, packages, functions… Edges are relationships between components: Inherit, call, instantiate, etc… Reverse Engineering (Bunch)

24 Software Clustering Problem
For a given mdg, and a function that determines the quality of a partitioning of that mdg, find the best partition. Reverse Engineering (Bunch)

25 Reverse Engineering (Bunch)
Possible Answer? We could look at every possible partition… Exhaustive search always gives the best answer. The number of partitions of a set are equal to the recurrence given by Sterling: S(n, k) = 1 if k = 1 or k = n S(n – 1, k – 1) + k S(n – 1, k) Reverse Engineering (Bunch)

26 Reverse Engineering (Bunch)
Exhaustive Search… If Exhaustive search is optimal, then why not use it? The recurrence to the Sterling recurrence grows very rapidly. The search for partitioning for n nodes must go through partitions for all k in S(n, k). Thus the size of the search space is:  S(n, k), for k = 1..n … enormous Reverse Engineering (Bunch)

27 Reverse Engineering (Bunch)
Other Answers If we don’t use Exhaustive search, then we have to use a sub-optimal strategy. Just because a strategy is sub-optimal, though, doesn’t mean it won’t give good results. Reverse Engineering (Bunch)

28 Software Clustering with Search Algorithms
4/26/2017 Software Clustering with Search Algorithms SEARCH SPACE Set of All MDG Partitions M1 M2 M3 M5 M4 M6 M8 M7 Total = 4140 Partitions Software Clustering Search Algorithms bP = null; while(searching()) { p = selectNext(); if(p.isBetter(bP)) bP = p; } return bP; Source Code Analysis Tools MDG void main() { printf(“hello”); } Acacia Chava M1 M2 M3 M5 M4 M6 M7 M8 “GOOD” MDG Partition M1 M2 M3 M5 M4 M6 M7 M8 STEP 1: Create the MDG using source code analysis tools STEP 2: The MDG defines the search space of all MDG partitions STEP 3: Search algorithms process the search space Reverse Engineering (Bunch)

29 Software Clustering with Search Algorithms
SEARCH SPACE Set of All MDG Partitions M1 M2 M3 M5 M4 M6 M8 M7 Total = 4140 Partitions Software Clustering Search Algorithms bP = null; while(searching()) { p = selectNext(); if(p.isBetter(bP)) bP = p; } return bP; Source Code Analysis Tools MDG File void main() { printf(“hello”); } Acacia Chava M1 M2 M3 M5 M4 M6 M7 M8 Search Algorithm Requirements Must be able to compare one partition to another objectively. We define the Modularization Quality (MQ) measurement to meet this goal. Given partitions P1 & P2, MQ(P1) > MQ(P2) means that P1 “is better than” P2 “GOOD” MDG Partition M1 M2 M3 M5 M4 M6 M7 M8 Reverse Engineering (Bunch)

30 Reverse Engineering (Bunch)
Hill-Climbing Hill-Climbing refers to how to travel along the contour of the solution space. The idea is to find a starting position, and then move to a better state. What if there is more than one state that we could move to? What happens when we find a local maximum? Can we do anything about getting a bad start? Reverse Engineering (Bunch)

31 Bunch Hill Climbing Clustering Algorithm
A neighbor partition is created by altering the current partition slightly. Neighbor Partition Generate a Random Decomposition of MDG Best Neighboring Partition for Iteration Current Partition Iteration Step Generate Next Neighbor Measure MQ Compare to Best Neighboring Partition Measure MQ Best Neighboring Partition Neighboring Partition New Best Convergence Better Better? Reverse Engineering (Bunch)

32 Bunch Hill Climbing Clustering Algorithm
A neighbor partition is created by altering the current partition slightly. Neighbor Partition Generate a Random Decomposition of MDG Best Neighboring Partition for Iteration Current Partition Iteration Step Generate Next Neighbor Measure MQ Compare to Best Neighboring Partition Measure MQ Best Neighboring Partition Neighboring Partition New Best Convergence Hill-Climbing Algorithm Features We have implemented a family of hill-climbing algorithms Control the “steepness” of the climb Simulated Annealing Population Size Better Better? Reverse Engineering (Bunch)

33 Reverse Engineering (Bunch)
Genetic Algorithms Genetic Algorithms take a problem, and model solution finding after nature. Selection Crossovers Mutations Genetic Algorithms tend not to get stuck at local maxima. Reverse Engineering (Bunch)

34 Bunch Genetic Clustering Algorithm (GA)
Favor Partitions with Larger MQ Values for Crossover Operation RANDOM SELECTION Generate a Starting Population from the MDG Iteration Step Current Population P1 P2 P3 Pn Next Population P1 P2 P3 Pn P1 P2 P3 Pn Mutation Operation Crossover Operation P2 Next Generation Mutate (Alter) a Small Number of Partitions RANDOM SELECTION Best Partition from Final Population All Generations Processed Reverse Engineering (Bunch)

35 Reverse Engineering (Bunch)
Tools for Clustering Bunch – Automatic Clustering Performs automatic clustering. Automatically produced results are often suboptimal. Allows user-directed clustering: Users can help the search for a good clustering with their knowledge. Reverse Engineering (Bunch)

36 Reverse Engineering (Bunch)
Using Bunch… Bunch is a tool written in Java that will work on any machine supporting the JVM. The first step in using Bunch will be finding out how to make those mdg files mentioned earlier. Reverse Engineering (Bunch)

37 Reverse Engineering (Bunch)
Creating mdg files… To create an mdg, we use the mdg script: Used to create mdg files for Java, C, and C++. Can view various relations (extends, implements, method-variable, method-method). Can also give weights to each relation, along with providing its type. Reverse Engineering (Bunch)

38 Reverse Engineering (Bunch)
Syntax of mdg mdg –(java|c|c++) –(eivmA)+ -(wltA)* The first set of parameters represents the language to use. The second set of parameters describes the types of relationship to display. The last set determines what extra information to produce. Reverse Engineering (Bunch)

39 Reverse Engineering (Bunch)
Syntax of bmdg bmdg –f <file> –i -a -v The first parameter specifies the XML file created by bat during source code analysis. The –i (optional) parameter includes the “class A subclasses or implements class B” relations in the mdg. The –a (optional) parameter includes the “class A calls method in class B” and “class A accesses public variable in class B” relations in the mdg. The –v (optional) parameter includes the “class A has variables of type class B” relations in the mdg. Reverse Engineering (Bunch)

40 Reverse Engineering (Bunch)
MDG Results The mdg script produces a series of pairs that represent directed edges. These edges can have extra information along with them, such as weight and type, if desired. Reverse Engineering (Bunch)

41 Reverse Engineering (Bunch)
Bunch Features Bunch is a tool to perform automatic clustering of module dependency graphs. Has various algorithms for finding a good solution. Allows users to assist in automatic clustering. Provides methods to exclude omnipresent libraries and consumers in clustering (provides a more succinct clustering). Reverse Engineering (Bunch)

42 Reverse Engineering (Bunch)
The Bunch Algorithms Provides use for exhaustive search. Has hill-climbing algorithms Steepest Ascent (greedy) Nearest Ascent A genetic algorithm is also available. Reverse Engineering (Bunch)

43 Hill-Climbing Algorithms
Hill-Climbing algorithms get their names because they ‘climb’ to the top of ‘the hills’ of a solution space. Given the current solution, and some transition function, find some better solution. Sub-optimal: Can get caught on one of ‘the smaller hills’ a.k.a. local maximum. Reverse Engineering (Bunch)

44 Reverse Engineering (Bunch)
Steepest Ascent Steepest Ascent is a ‘greedy’ algorithm. Greedy Algorithms take the most of what they want whenever possible. Steepest Ascent computes all the states it can transition to, and takes the best one. Greedy algorithms aren’t always optimal overall, even though they take the optimal step at each state. Reverse Engineering (Bunch)

45 Reverse Engineering (Bunch)
Nearest Ascent Nearest Ascent is a non-greedy hill-climbing algorithm Does not compute the set of all possible states to transition to. Computes states until a better one is found. Much faster in practice than Steepest Ascent. Reverse Engineering (Bunch)

46 Helping Hill-Climbers
Hill-Climbing algorithms are inherently sub-optimal. They still tend to give good results, though. Even with good results, there are ways of improving the quality of the results, without that much effort (relatively). Reverse Engineering (Bunch)

47 Reverse Engineering (Bunch)
Bunch Clustering Bunch, as it may already seem, views clustering as an optimization problem. The bunch objective function trades off between two things: Cohesiveness of clusters (how intra-related is a cluster?) Coupling of clusters (how inter-related are clusters?) Reverse Engineering (Bunch)

48 Reverse Engineering (Bunch)
Random Restart One way to help Hill-Climbing algorithms is to restart the algorithm at some random state after finding a local maximum. The idea is to get various local maxima. After finding a set of various solutions, return the best one. The cost isn’t really that much, in comparison to the cost in terms of system size. Reverse Engineering (Bunch)

49 Reverse Engineering (Bunch)
Simulated Annealing Simulated Annealing is another technique used to assist Hill-Climbing algorithms. Occasionally take a transition that is not an increase in quality. The hope is that this will lead to climbing a better hill. Reverse Engineering (Bunch)

50 Reverse Engineering (Bunch)
Genetic Algorithms A totally different approach is to use Genetic Algorithms. Genetic Algorithms tend to converge to a solution quickly when the solution space is small relative to the search space. Genetic Algorithms tend to provide good results. Genetic Algorithms don’t get stuck at local maxima. Reverse Engineering (Bunch)

51 Reverse Engineering (Bunch)
Genetic Algorithms… Genetic Algorithms work by representing each state as a string, and then doing ‘genetic manipulation’ on a ‘generation’ in ways analogous to nature. Crossing Over Mutations Selection Reverse Engineering (Bunch)

52 Measuring MQ – Step 1: The Cluster Factor
The Cluster Factor for cluster i, CFi, is: CF increases as the cluster’s cohesiveness increases Subsystem 1 Subsystem 2 Subsystem 3 M1 M6 M1 M4 M6 M3 M7 M3 M7 M2 M8 M2 M5 M8 M4 M5 CF1 = 4/6 CF2 = 2/5 CF3 = 6/7 Reverse Engineering (Bunch)

53 Modularization Quality (MQ):
k represents the number of clusters in the current partition of the MDG. Modularization Quality (MQ) is a measurement of the “quality” of a particular MDG partition. Reverse Engineering (Bunch)

54 Modularization Quality (MQ):
We have implemented a family of MQ functions. MQ should support MDGs with edge weights Faster than older MQ (Basic MQ) TurboMQ » O(|V|) ITurboMQ » O(1) ITurboMQ incrementally updates, instead of recalculates, the CFi k represents the number of clusters in the current partition of the MDG. Modularization Quality (MQ) is a measurement of the “quality” of a particular MDG partition. Reverse Engineering (Bunch)

55 The Clustering Problem: Algorithm Objectives
“Find a good partition of the MDG.” A partition is the decomposition of a set of elements (i.e., all the nodes of the graph) into mutually disjoint clusters. A good partition is a partition where: highly interdependent nodes are grouped in the same clusters independent nodes are assigned to separate clusters The better the partition the higher the MQ Reverse Engineering (Bunch)

56 The Bunch Tool: Automatic Clustering
Other Tools and Utilities Clustering Services MDG Clustering Algorithm Clustering Algorithm Options Output Format START Reverse Engineering (Bunch)

57 Reverse Engineering (Bunch)
Starting Bunch Now that we know some of the stuff that Bunch does ‘under the hood,’ let’s start to use it. Bunch is a Java program held in a jar file. To run it, type the following: java –classpath Bunch.jar bunch.Bunch Reverse Engineering (Bunch)

58 Reverse Engineering (Bunch)
Basic Controls Reverse Engineering (Bunch)

59 Basic Controls Description
Input Graph File: The mdg to be clustered. Clustering Method: Which algorithm to use? (Hill-Climbing, Genetic, etc). Output Cluster File: Where to put the results? Output File Format: Dotty? Text? Reverse Engineering (Bunch)

60 Reverse Engineering (Bunch)
Clustering Actions Agglomerative Clustering: Bunch will cluster until the system is together in one large cluster. User-Driven Clustering: Here, the user clicks ‘Generate Next Level’ to proceed with each level of clustering. Reverse Engineering (Bunch)

61 Reverse Engineering (Bunch)
Clustering Options Reverse Engineering (Bunch)

62 Clustering Options Description
Clustering Algorithm: Which ‘clustering’ algorithm to use. Graph File Delimiters: Specify delimiting characters in MDG files. Limiting Runtime: Used to limit the amount of time Bunch will run. Agglomerative Output Options: What type of output for agglomerative clustering. Generate Tree Format: Show clustering hierarchy. Reverse Engineering (Bunch)

63 Reverse Engineering (Bunch)
Libraries Reverse Engineering (Bunch)

64 Reverse Engineering (Bunch)
Libraries Some Modules are just libraries used by the system. These don’t add any semantics to the system. While being a part of what makes the system, they are just small tools that the designers decided to use. Reverse Engineering (Bunch)

65 Reverse Engineering (Bunch)
Omni-Present Modules Reverse Engineering (Bunch)

66 Reverse Engineering (Bunch)
Omni-Present Modules Some systems have internal modules that are use across a large portion of the system. Including such modules in a decomposition is pointless. Bunch gives the option of removing such modules from the decomposition. Reverse Engineering (Bunch)

67 User-Directed Clustering
Reverse Engineering (Bunch)

68 User-Directed Clustering
Sometimes, there will exist a priori knowledge about a system. Such knowledge, when used as constraints on a decomposition, makes it a better decomposition. Bunch allows pre-cluster grouping of modules. Reverse Engineering (Bunch)

69 Reverse Engineering (Bunch)
Results… Reverse Engineering (Bunch)

70 Reverse Engineering (Bunch)
System Evolution Systems change constantly. New developers add to chaos in the maintenance. New features do so, too. Reverse Engineering (Bunch)

71 Reverse Engineering (Bunch)
Out with the old? Even though systems change, out of date decompositions don’t have to be thrown away. There still may be some relations that the decomposition represents. An old decomposition may be better than some random start state for clustering a system. Reverse Engineering (Bunch)

72 Reverse Engineering (Bunch)
Orphan Adoption When a change is applied to one module of a system, the amount of change is relatively small. We can take the module that changed, and see how it fits in with every cluster. We can also see how good of a system we get when it’s alone. Taking the best solution out of these solutions is how Bunch handles this. Reverse Engineering (Bunch)

73 Hierarchical Clustering (1): Tree View
1. 4. 2. Default 3. Reverse Engineering (Bunch)

74 Hierarchical Clustering (2): Standard View
1. 4. 2. Default 3. Reverse Engineering (Bunch)

75 Distributed Clustering
Distributed clustering allows large MDGs to be clustered faster… Bunch User Interface (BUI) Bunch Clustering Service (BCS) Neighboring Servers (NS) Reverse Engineering (Bunch)

76 Distributed Clustering
Distributed clustering allows large MDGs to be clustered faster… Distributed Clustering Features Multiple Clustering Algorithms Heterogeneous Platforms Adaptive Load Balancing Bunch User Interface (BUI) Bunch Clustering Service (BCS) Neighboring Servers (NS) Reverse Engineering (Bunch)

77 Reverse Engineering (Bunch)
‘Good’ Clusterings Even with all these features, only the Exhaustive Search gives us the optimal clustering. How do we know how good of a clustering we have? Reverse Engineering (Bunch)


Download ppt "Software Clustering Using Bunch"

Similar presentations


Ads by Google