placement of entities in object-oriented systems by means of a single-objective genetic algorithm...
TRANSCRIPT
Placement of Entities in Object-oriented Systems by means of a Single-objective Genetic
Algorithm
Margaritis Basdavanos Alexander Chatzigeorgiou
University of Macedonia
Thessaloniki, Greece
5th International Conference on Software Engineering Advances (ICSEA’2010)
Design
System
• The decomposition into modules
• The design (in any technical field) consists in:
Design
• The design (in any technical field) consists in:
• The decomposition into modules
System
• The definition of the relationships among them
Design
• The design (in any technical field) consists in:
• The decomposition into modules
System
• The definition of the relationships among them
Functionality AFields: X, Y
Functionality BFields: Y, Z
• The assignment of responsibilities and state information
“Old” problem
• The distribution of responsibilities and state information among system modules is an “old” problem in SE
How to achieve an optimal design?
“Old” problem – Why is it important?
Coupling Cohesion
Why is coupling and cohesion important?
• Empirical studies have shown that they affect a large number of –ilities in OO design
• comprehensibility
• maintainability
• testability
• reusability
Attributes in Quality Models €
Software Ageing
well-designed code
Design quality decays
Problem
• Given a system S : (methods, attributes, classes)
• Find an optimal assignment that
• minimizes coupling and
• maximizes cohesion
• Search problem in the space of alternative
arrangements
Optimal Placement
• Placing 4 entities into 2 classes
+m1()
-x
A
+m2()
-y
B1η
+m2()
-y
A
+m1()
-x
B2η
+m1()
A
+m2()
-y-x
B3η
+m1()
-x-y
A
+m2()
B4η
+m1()+m2()
-x-y
A B
5η
+m2()
-x
A
+m1()
-y
B6η
For x classes and n entities the search space consists of xn possible allocations !!
Crash Course on Genetic Algorithms
GAs are heuristics that can generate useful solutions to optimization and search problems
Inspired by evolution and natural selection (Darwin's theory)
Crash Course on GAs – Brief Overview
Select initial population of individuals
Evaluate the fitness
of each individual
in that population
Breed new individuals through
crossover and mutation operations
Crash Course on Gas - Terminology
Potential Solutions are usually encoded as binary or integer strings called chromosomes
chromosome
Elements of chromosomes are called genes
genes
The values that a gene can take are called alleles
1 2 1 2 3
alleles
The positions of genes in the chromosome are called loci
0 1 2 3 4 5 6 7 8 9loci
Our fitness function: Entity Placement
• Constituents of an OO system: methods and attributes
• Methods can access attributes and methods of the class that they belong to directly and also attributes and methods of other classes through references.
•Attributes can be accessed directly from methods of the class that they belong to and also from methods of other classes that have reference to that class.
• For each entity it is possible to define a set of entities that it accesses (if it is a method) or a set of entities that it is accessed from (if it is an attribute).
• Entity Set of a Class: contains all of its members
Entity Placement
• It is reasonable to assume that the similarity between an entity and a class is high when the number of common entities is large
• Jaccard Distance
BA
BABAcetandis
1,
Example of Distance Calculation
16
f1
Sm = {Source.field, Target.f1, Target.m2} STarget = {Target.f1, Target.m2, Target.m1}
field
Sm STarget = {Target.f1, Target.m2}
Sm STarget = {Source.field, Target.f1, Target.m2, Target.m1}
distance(Sm , STarget) = 1 – 2/4 = 0.5
Global Measure of Entity Placement
Centities
Cecetandis
Centities
Cecetandis
ementEntityPlac
Cej
Cei
C
j
i
,
,
i
i
CC
iSystem ementEntityPlac
entitiesall
CentitiesementEntityPlac
cohesion
coupling
Simplified Case Studies
• Entity Sets Class SetsSx = {m2} => S0 = {3} SA = { x, m1} => S0 = {0,1}Sm1 = {y} => S1 = {2} SB = { y, m2} => S1 = {2,3}
Sy = {m1} => S2 = {1} Sm2 = {x} => S3 = {0}
+m1()
-x
A
+m2()
-y
BClass 0 Class 1
0
1
2
3
Simplified Case Studies
• Chromosome of the initial model
• System Entity Placement = 2
• Number of possible arrangements: 24 = 16
A A BB
x m1 y m2
0 0 1 1
0 1 2 3
Αποκωδικοποιημένη μορφή Κωδικοποιημένη μορφήDecoded Form Encoded Form
Optimal Placement
• Placing 4 entities into 2 classes
+m1()
-x
A
+m2()
-y
B1η
+m2()
-y
A
+m1()
-x
B2η
+m1()
-x-y
A
+m2()
B4η
+m1()+m2()
-x-y
A B
5η
+m2()
-x
A
+m1()
-y
B6η
+m1()
A
+m2()
-y-x
B3η
A A BB
x m1 y m2
B B AA
x m1 y m2
B A BB
x m1 y m2
A A BA
x m1 y m2
A A AA
x m1 y m2
A B AB
x m1 y m2
Simplified Case Studies
• GA population size 2*m = 2*4 = 8• Crossover Rate:50%, Mutation Rate: 12,5% Selection rate: 80%
– Chromosome of the optimal solution
• Resulting Entity Placement value = 0– Average execution time: 14 ms (Pentium IV 3,2GHz)
– Average number of generations : 3
A B AB
x m1 y m2
0 1 1 0
0 1 2 3
Αποκωδικοποιημένη μορφή Κωδικοποιημένη μορφή
Simplified Case Studies
0
1
2
3 +m2()
-x
A
+m1()
-y
BClass 0 Class 1
Optimal Class Diagram
Evolution of the fitness function
Simplified Case Studies - #2
+addOrder()+getFirstOrder()+removeFirstOrder()+getOrderCodes()+calculateTime()+findPosition()+calculatePlatesWaiting()+getOrders()
Queue
+Order()+getCode()+pickPlate()+addPlate()+getPlates()+getNumberOfPlates()
-code
Order
-ordersWaiting1
*
+setPlateName()+getPlateName()+storeIngrendient()+isAvailable()+pick()
-plateName
Plate-plates
1 *
+Ingredient()+checkQuantity()+removeIngredient()+getIngredientName()
-ingredientName-amount
Ingredient
-map1*
+addToPlateCatalog()+getPlate()+getPlateNames()
PlateCatalog
-catalogPlates1
*
+addToIngredientCatalog()+getIngredient()+getIngredientNames()
IngredientCatalog
-ingredients
1*
2
0
3
4
5
6
1
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 35
36
37
0
1
2
4
5
3
Simplified Case Studies - #2
• Chromosome for OrderManagement
Κωδικοποιημένη κατανομή οντοτήτων στις κλάσεις του συστήματος
• Entity Placement OrderManagement = 0,7141
• Number of possible arrangements: 638
10 110 0 0 00 10 11 2 22 22 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 52
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
Simplified Case Studies - #2
• GA population [1,2*38] = 46
– Configuration: pc = 50% pm = 2,63% ps = 60%
• Final Entity Placement value = 0,6878
– Average execution time: 15,7 s (Pentium IV 3,2GHz)
– Number of generations : 86
Simplified Case Studies - #2
Evolution of Entity Placement
Eclipse Plugin
Project to be
analyzed
Analysis by clicking here
Results of the GA
Eclipse Plugin
Conclusions
• Optimal solutions can be reached within reasonable time
(much faster than Multi-Objective GAs)
• Feasible distribution of entities among classes avoiding the
generation of “God” classes
• Entity Placement captures efficiently coupling and
cohesion
Future Work
• Handling of user constraints
• Proper handling of inheritance
• Empirical Studies on large systems
Thank you for your attention !!
5th International Conference on Software Engineering Advances (ICSEA’2010)