Παρουσίαση του PowerPoint

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
• The design (in any technical field) consists in:
System
• The decomposition into modules
Design
• The design (in any technical field) consists in:
System
• The decomposition into modules
• The definition of the relationships among them
Design
• The design (in any technical field) consists in:
Functionality A
Fields: X, Y
Functionality B
Fields: Y, Z
System
• The decomposition into modules
• The definition of the relationships among them
• 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
1η
3η
2η
A
B
A
B
-x
+m1()
-y
+m2()
-y
+m2()
-x
+m1()
4η
A
-x
-y
+m1()
A
B
+m1()
-y
-x
+m2()
5η
B
+m2()
A
-x
-y
+m1()
+m2()
6η
B
A
B
-x
+m2()
-y
+m1()
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
Evaluate
the fitness
of each
individual
in that
population
Select initial
population of
individuals
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
Elements of chromosomes are called genes
The values that a gene can take are called alleles
The positions of genes in the chromosome are called loci
loci
0
1
2
1
2
1
genes
3
4
5
6
7
8
9
2
3
chromosome
alleles
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
dis tance A, B   1 
A B
A B
Example of Distance Calculation
Source
field
m(Target t) {
field;
t.f1;
t.m2();
}
Target
f1
m1()
m2()
Sm = {Source.field, Target.f1, Target.m2}
STarget = {Target.f1, Target.m2, Target.m1}
Sm  STarget = {Target.f1, Target.m2}
Sm  STarget = {Source.field, Target.f1, Target.m2, Target.m1}
distance(Sm , STarget) = 1 – 2/4 = 0.5
16
Global Measure of Entity Placement
 distancee , C 
i
ei C
entities  C
EntityPlacementC 
 distancee j , C 
e j C
cohesion
coupling
entities  C
EntityPlacementSystem  
Ci
entities  Ci
all entities
EntityPlacementCi
Simplified Case Studies
Class 0
A
0 -x
1 +m1()
• Entity Sets
Sx = {m2} => S0 = {3}
Sm1 = {y} => S1 = {2}
Sy = {m1} => S2 = {1}
Sm2 = {x} => S3 = {0}
Class 1
B
2
3
-y
+m2()
Class Sets
SA = { x, m1} => S0 = {0,1}
SB = { y, m2} => S1 = {2,3}
Simplified Case Studies
• Chromosome of the initial model
A
A
B
B
0
0
1
1
x
m1
y
m2
0
1
2
3
Αποκωδικοποιημένη
Decoded Form μορφή
Κωδικοποιημένη
Encoded Formμορφή
• System Entity Placement = 2
• Number of possible arrangements: 24 = 16
Optimal Placement
• Placing 4 entities into 2 classes
1η
3η
2η
A
B
A
B
-x
+m1()
-y
+m2()
-y
+m2()
-x
+m1()
A
B
+m1()
-y
-x
+m2()
A
A
B
B
B
B
A
A
B
A
B
B
x
m1
y
m2
x
m1
y
m2
x
m1
y
m2
4η
5η
A
B
-x
-y
+m1()
+m2()
6η
A
B
-x
-y
+m1()
+m2()
A
B
-x
+m2()
-y
+m1()
A
A
A
B
A
A
A
A
A
B
B
A
x
m1
y
m2
x
m1
y
m2
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
A
B
B
A
0
1
1
0
x
m1
y
m2
0
1
2
3
Αποκωδικοποιημένη μορφή
Κωδικοποιημένη μορφή
• Resulting Entity Placement value = 0
– Average execution time: 14 ms (Pentium IV 3,2GHz)
– Average number of generations : 3
Simplified Case Studies
Optimal Class Diagram
Class 0
A
0 -x
3 +m2()
Class 1
B
2 -y
1 +m1()
Evolution of the fitness function
Simplified Case Studies - #2
Queue
22
23
24
25
26
27
28
29
3
+addOrder()
+getFirstOrder()
+removeFirstOrder()
+getOrderCodes()
+calculateTime()
+findPosition()
+calculatePlatesWaiting()
+getOrders()
1
31
32
-ordersWaiting
33
+addToPlateCatalog()
+getPlate()
+getPlateNames()
21
1
*
13
15
16
17
18
19
20
-code
+Order()
+getCode()
+pickPlate()
+addPlate()
+getPlates()
+getNumberOfPlates()
-catalogPlates
30
*
-plates
Order
4
PlateCatalog
14
2
0
Plate
1
*
0
2
3
4
5
6
-plateName
+setPlateName()
+getPlateName()
+storeIngrendient()
+isAvailable()
+pick()
1
*
-map
Ingredient
7
8
9
10
11
12
-ingredientName
-amount
+Ingredient()
+checkQuantity()
+removeIngredient()
+getIngredientName()
1
1
*
1
-ingredients
34
IngredientCatalog 5
35
36
37
+addToIngredientCatalog()
+getIngredient()
+getIngredientNames()
Simplified Case Studies - #2
• Chromosome for OrderManagement
0
0
0
0 0
0
0
1
1 1 1 1
1
2 2
2 2 2 2
2
2
3
3
3
3
3 3 3
3
3 4
4 4
4
0
1
2
3
5
6
7
8
12
13 14
15 16 17
19
20
21
22
23
24
25 26
28
29 30
31 32
33
4
9
10 11
18
27
5 5
34
35
5 5
36 37
Κωδικοποιημένη κατανομή οντοτήτων στις κλάσεις του συστήματος
• Entity Placement OrderManagement = 0,7141
• Number of possible arrangements: 638
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
Results of
the GA
Project
to be
analyzed
Analysis by
clicking here
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)