Title: Application of AspectJ to Genetic Algorithm Module Development
1Application of AspectJ to Genetic Algorithm
Module Development
- Cs5382 Topics in Software Development
- Myoung Yee Kim
2Problem
- Complete automation of unit testing for Java
programs - Test data
- Genetic algorithms
- Test oracle
- Specification,
- e.g., Java Modeling Language (JML)
- Test execution
- Testing framework, e.g., JUnit
- Extending of the existing random unit testing
tool (UTJML) by applying genetic algorithms.
3Production
- Genetic Algorithm Framework
- Initial test set
- Fitness calculation
- Parents selection
- Genetic operation
- Next generation
- Development Aspects (Algorithm investigation)
-
- Log Aspect
- Dynamic Code Aspect
- Product Aspects (Add new algorithms)
- Framework Aspect
4Example
public class Course private final int
maxSize private int size 0
public Course(int maxSize) this.maxSize
maxSize public boolean isClosed()
return size gt maxSize
public boolean enroll(Student s) if
(isClosed()) return false
else // add s to this course ...
size return true
public void unenroll() if (size gt 0)
size-- public
int maxSize() return maxSize
public int size() return size
public String toString() return ""
size "/" maxSize "" public
class Student
5Random Genetic AlgorithmTest Data Generation
Course c1 new Course(10) c1.enroll(new
Student()) c1.enroll(new Student()) c1.unenroll()
c1.size() Course c2 new Course(5) c2.enroll(new
Student()) c2.enroll(new Student()) c2.enroll(new
Student()) Course c3 new Course(50) c3.enroll(
new Student()) c3.enroll(new Student()) c3.maxSize
() c3.enroll(new Student()) c3.unenroll()
c1.IsClosed() ? c2.IsClosed() ? c3.IsClosed() ?
Fitness Value C1 1/10 C2 3/5 C3 3/50
6Main Functional Module
GA
Log Aspect
ltltusegtgt
Initial
Fitness
Parent
Operator
Found
CourseInit
CourseFit
CoursePar
CourseOpr
CourseFound
Dynamic Code Aspect
ltltgeneratedgtgt
Crinit
CrFit
CrPar
CrOpr
CrFound
ltltusegtgt
Framework Aspect
CrGA
Tool Module
7Log Aspect
public aspect Log int a0, b0, c0, d0,
e0 pointcut init(List oba) execution (
Initial.run(..)) args(oba, ..) after(List
oba) init(oba) System.out.println("After Init
" a) System.out.println(oba) poin
tcut fit(List oba) execution (
Fitness.run(..)) args(oba) after(List
oba) fit(oba) System.out.println("After
Fitness " b) System.out.println(oba)
8Dynamic Code Aspect
public aspect TryAlgorithm pointcut
init(List pop, int num) execution (
CourseInit.run(List, int)) args(pop,num) voi
d around(List pop, int num) init(pop,num) //
pop.clear() for (int i 0 i lt num/ 1 i)
Course c new Course(5 (int)
(Math.random() 5)) / int asize
(int) (Math.random() (50 (int)
(Math.random() 50))) for (int j 0 j
lt asize j) c.enroll(new
Student()) / pop.add(new
PEntry(c)) return pointcut
opr(Course c) execution ( CourseOpr.mutate(Cours
e)) args(c) void around(Course c)
opr(c) if (Math.random() lt (double)0/6)
c.toString() else if (Math.random() lt
(double)1/6) c.size() else if
(Math.random() lt (double)2/6) c.isClosed()
else if (Math.random() lt (double)3/6)
c.maxSize() else if (Math.random() lt
(double)4/6) c.enroll( new Student()) else
if (Math.random() lt (double)5/6) c.unenroll(
new Student()) / if (Math.random()
lt (double)1/2) c.enroll( new Student())
else c.unenroll( new Student()) /
//c.enroll( new Student()) return
9Framework Aspect
public aspect ChangeFit pointcut
mainFunc(String ob, String mt) execution
(String CrFit.algorithm(String, String))
args(ob, mt) String around(String ob, String
mt) mainFunc(ob, mt) return "\t\t for
(Iterator i pop.iterator() i.hasNext() ) "
"\n" "\t\t\t p (PEntry) i.next()" "\n"
"\t\t\t c (" ob ")p.entry" "\n"
"\t\t\t p.fitness ((float)
c.size() / c.maxSize())" "\n"
"\t\t" "\n"
10Test1 Course.IsClosed()
After Found 377 0.01/9, 0.04/5,
0.02/7, 0.00/9, 0.01/7, 0.03/8,
0.03/6, 0. 00/8, 0.00/5,
0.01/8 After Fitness 377 0.01/9,
0.04/5, 0.02/7, 0.00/9, 0.01/7,
0.03/8, 0.03/6, 0. 00/8, 0.00/5,
0.01/8 After Init 378 0.04/5, 0.02/7,
0.00/9, 0.01/7, 0.03/8, 0.03/6,
0.00/8, 0. 00/5, 0.01/8,
0.00/5 After Parent 377 0.04/5,
0.02/7, 0.00/9, 0.01/7, 0.03/8,
0.03/6, 0.00/8, 0. 00/5, 0.01/8,
0.00/5 After Operator 377 0.05/5,
0.03/7, 0.00/9, 0.01/7, 0.03/8,
0.03/6, 0.00/8, 0. 00/5, 0.01/8,
0.00/5 After Found 378 0.05/5, 0.03/7,
0.00/9, 0.01/7, 0.03/8, 0.03/6,
0.00/8, 0. 00/5, 0.01/8, 0.00/5
11Test2 Course. IsClosed()
After Found 19 0.166666671/6,
0.333333343/9, 0.333333342/6, 0.3753/8,
0.3753/8, 0.428571433/7, 0.64/5,
0.63/5, 0.84/5, 0.00/5 After Fitness
19 0.166666671/6, 0.333333343/9,
0.333333342/6, 0.3753/8, 0.3753/8,
0.428571433/7, 0.84/5, 0.63/5,
0.84/5, 0.00/5 After Init
20 0.166666671/6, 0.333333343/9,
0.333333342/6, 0.3753/8, 0.3753/8,
0.428571433/7, 0.63/5, 0.84/5,
0.84/5, 0.00/9 After Parent
19 0.166666671/6, 0.333333343/9,
0.333333342/6, 0.3753/8, 0.3753/8,
0.428571433/7, 0.63/5, 0.84/5,
0.84/5, 0.00/9 After Operator
19 0.166666671/6, 0.333333343/9,
0.333333342/6, 0.3753/8, 0.3754/8,
0.428571434/7, 0.64/5, 0.85/5,
0.84/5, 0.00/9 After Found
20 0.166666671/6, 0.333333343/9,
0.333333342/6, 0.3753/8, 0.3754/8,
0.428571434/7, 0.64/5, 0.85/5,
0.84/5, 0.00/9
12Test3 BookStack. IsIdeal()
After Found 98 0.0\Theory\Software\Theory,
0.0\Theory, 0.0, 0.0, 0.0, 0.0\Algorithm\Theo
ry\Software, 0.0, 0.0\Theory, 0.0,
0.0 After Fitness 98 0.0\Theory\Software\Theor
y, 0.0\Theory, 0.0, 0.0, 0.0,
0.0\Algorithm\Theo ry\Software, 0.0,
0.0\Theory, 0.0, 0.0 After Init
99 0.0\Theory, 0.0, 0.0, 0.0,
0.0\Algorithm\Theory\Software, 0.0,
0.0\Theor y, 0.0, 0.0, 0.0 After Parent
98 0.0\Theory, 0.0, 0.0, 0.0,
0.0\Algorithm\Theory\Software, 0.0,
0.0\Theor y, 0.0, 0.0, 0.0 After Operator
98 0.0\Theory\System, 0.0, 0.0, 0.0,
0.0\Algorithm\Theory\Software\System, 0. 0,
0.0\Theory, 0.0, 0.0, 0.0\Software After
Found 99 0.0\Theory\System, 0.0, 0.0, 0.0,
0.0\Algorithm\Theory\Software\System, 0. 0,
0.0\Theory, 0.0, 0.0, 0.0\Software
13Evaluation of Aspect
- How effectively new algorithms are investigated
- Log Aspect
- Convenient to debug
- Dynamic Code Aspect
- One place of code modification
- How effectively it extend with new genetic
algorithms ( new fitness and genetic operation
algorithm). - Framework Aspect
- Easy to replace algorithm
- Errors
- Errors when we apply more than one advices
14Conclusion and Future work
- The application of AspectJ to genetic algorithm
module development provides convenience and
efficiency - Application of Aspect to main functional module
instead of creating tool separately. - Test with more various genetic algorithm modules
- Tool module must be powerful enough to accept all
classes