Genetic algorithms (GA) have been successfully applied in development of software but GA for Object oriented software development is limited. This paper proposes a method to generate classes in object oriented software using a genetic programming approach. It uses a tree representation of statements in development. Strategies for encoding the coding and using the objective function to evolve them as suitable development are proposed. This paper focuses on the automated generation of modules using a random code generator and can be used to create many modules without following any specific criteria.
Keywords- Genetic Algorithm,; Object-Oriented Software development; Unit Software development; Chromosome; Mutation; Objective Function
Introduction
Software development is program development for customer requirements with a subset of modules. Relevance of created modules is a critical activity. Test data is generated through a test data generation tool [1][2][3], while a test adequacy criterion assures the quality of modules generated and gives information about the end of software development process. Modules follow predefined software development criteria like code coverage [4], path coverage [1][5] statement coverage [2] and branch coverage [3]. Advanced heuristic search techniques based on evolutionary algorithms can be applied in finding good modules [6]. These techniques are referred to as evolutionary software development [7]. Evolutionary Software development uses a Genetic Algorithm (GA), to convert the task of module generation into an optimal problem. A cost function measures generated optimization parameters for modules. This paper proposes a new approach to automate the generation of object-oriented programming modules. Genetic programming is used to formulate the task of sequence generation as a search problem. This approach enables module generation of object oriented classes by appropriately designing the objective function that is used to guide the genetic programming search. This paper proposes a method to generate modules for classes in object oriented software. Section II introduces genetic algorithms while section III describes it with reference to a object oriented software development. Section IV explains chromosomes and section V describes to encode them. Section VI, VII and VIII describe about selecting initial population, their crossover & mutation and then decoding them back to generate modules respectively. Section IX describes about the objective function to guide the selection for next generation. Section X describes the experimental results and finally section XI describes limitations and future research directions.
Genetic Programming (GP)
Natural evolution is determined by competition for resources in the environment and better Individuals survive and propagate their genes through sexual reproduction which results in offsprings that are genetically identical to the parent. This reproduction allows exchange and re-ordering of chromosomes in offspring’s with a combination of parental genes. This recombination is often called crossover for the way strands of chromosomes cross over in the exchange. Diversity in population is achieved by mutation. Evolutionary algorithms are applied to numerous problems in different domains, including optimization, automatic programming, machine learning, operations research, bioinformatics, and social systems. Mathematical functions describe unknown problems and obtain values from simulations. Evolutionary computation is advantageous in solving optimization problems, due to its simplicity in approach, robustness and flexibility. The approach can be applied to problems where heuristic solutions result in improper results. Evolutionary computational applications applied to practical problem solving has evoked research interest for long, though there are many variants of genetic programming. Genetic algorithms based on natural evolution can be implemented in computers called Genetic Programming [8]. GP techniques provide a framework for automatically creating a computer program from a high-level problem statement [9] and achieve the goal by using Darwinian natural selection principles and genetically breeding a population of computer programs. It differs from genetic algorithms in the representation of the solution. Genetic programming is an extension of evolutionary learning in computer programming where individual population members are not fixed length character strings but executable computer programs and can be expressed as parse trees. For example consider a simple program X + Y∗ Z(4, x, z). Terminal, function sets which are important components of genetic programming, here are the alphabet of the programs to be made. The terminal set consists of the variables x,y and z and constant 4. Function with two arguments are connected with the operation symbol between them in infix format i.e. x + y or x ∗ y. Genetic Programming Tree Structure is depicted in Fig. 1
Fig. 1 Genetic Programming Structure
Genetic algorithm (GA) is one of the simplest and best evolutionary algorithms. GA is an optimization algorithm. The most common definition of a GA is that it is a sequence of exactly defined steps for a solution to the given problem. Evolutionary computation [10] or evolutionary algorithms contain genetic algorithms [11], evolutionary programming [12], strategies [13][14] and genetic programming [9]. They evolve individual structures through the processes of selection, mutation and reproduction, which depend on the supposed performance of individual structures defined by the problem. Candidate solutions (Population) for task optimization are initialized and solutions are created by applying mutation/crossover operators (Reproduction). Resulting solutions are evaluated and a selection strategy is applied to determine solutions for the next generation (Fitness). This procedure is iterated where each iteration is called a generation. GA is generic and many aspects of GA can be implemented based on the problem like representation of chromosomes, encoding, selection, crossover and mutation operators. They are implemented as an arrays of bits or characters which represent chromosomes. Individuals go through a simulated evolution and bit manipulations allow crossover implementation, mutation and other operations. The bits of every gene (parameter) and the decimal range in which they decode are usually the same but nothing precludes the utilization of a different number of bits or range for every gene. An important GA feature is its focus on fixed-length character strings even if variable-length strings are used. A GA is depicted in Fig. 2.
Initialize Population
Evaluate Fitness Reproduction
Solution no
Found? Selection
yes
End
Fig. 2. Genetic Algorithm Iteration
The Canonical GA (pseudo code):
choose initial population
evaluate each individual’s fitness
determine population’s average fitness
repeat
select best-ranking individuals to reproduce
mate pairs at random
apply crossover operator
apply mutation operator
evaluate each individual’s fitness
determine population’s average fitness
until terminating condition (e.g. until at least one individual has
the desired fitness or enough generations have passed)
The Algorithm
In the genetic algorithm process is as follows[1]:
Step 1. Determine the number of chromosomes, generation, and mutation rate and crossover rate value
Step 2. Generate chromosome-chromosome number of the population, and the initialization value of the genes chromosome-chromosome with a random value
Step 3. Process steps 4-7 until the number of generations is met
Step 4. Evaluation of fitness value of chromosomes by calculating objective function Step 5. Chromosomes selection
Step 5. Crossover
Step 6. Mutation
Step 7. New Chromosomes (Offspring)
Step 8. Solution (Best Chromosomes)
The flowchart of algorithm can be seen in Figure 1.
Figure 1. Genetic algorithm flowchart
Genetic Algorithm for Object Oriented Software Development
Object oriented software development is complex. Objects interact with each other by passing messages whose representation differs from procedural software. The complexity can be dealt by enriching the chromosomes to deal with entities that are complex [15]. Grammar can also be added the chromosome during evolution and mapped directly to an executing program. The author in [15], introduced notations for structuring GA chromosomes in object oriented software. The proposed approach treats modules as trees [16]. Modules in object oriented paradigm are a sequence of method which can contain numeric and constructors [17]. Multiple objects may be involved in a single module and are passed as parameters. New objects may also be created in a module thus creating a cluster class. Thus any module in object oriented software is based on the definition of software development prerequisites with parameters, types, values, method calls and sample results. Modules can be considered as a sequence of statements with essential components like target object, method, parameters and the receiver A method can be a class method or constructor. Parameters may be primitive or user defined while the receiver may be a variable or an object. Any statement Si can only be executed if an appropriate target object and all the required parameter objects for its method have been created in advance. The call dependency between methods has to considered in a module implying an arbitrary sequence of statements is not feasible. Modules have to be encoded into an individual or as a chromosome.
Numerical Example
Object oriented programming has a four dimensional problem. Programmers expertise (i), User Requirements and Specification (2j), Creating Objects, Interfaces and Modules (3k), Testing for user specs, module objectives, object creation and object behavior (4l). The genetic algorithm can be used to find the value of i, j, k, l to satisfy for 30 objects as
i+2j+3k+4l=30 (1)
The objective function that minimizes the value of function f(x) is
f (x) = ((x + 2i + 3i + 4k) – 30).
Since there are four variables in the equation, namely i, j, k, l.
The chromosome is follow:
i j k l
For faster computation, the values of variables i, j, k, and l are integers between 0 and 30.
Step 1. Initialization
Let the number of chromosomes in population be 6 with the generated random value of gene i, j, k, l as
Chromosome[1] = [i;j;k;l] = [11;06;22;09]
Chromosome[2] = [i;j;k;l] = [03;20;19;04]
Chromosome[3] = [i;j;k;l] = [12;06;15;16]
Chromosome[4] = [i;j;k;l] = [19;01;9;05]
Chromosome[5] = [i;j;k;l] = [01;06;11;16]
Chromosome[6] = [i;j;k;l] = [17;08;14;04]
Chromosome[7] = [i;j;k;l] = [01;03;05;07]
Chromosome[8] = [i;j;k;l] = [02;06;08;10]
Chromosome[9] = [i;j;k;l] = [03;05;07;09]
Step 2. Evaluation
The objective function value for each chromosome produced in initialization step:
obj[1] = Abs(1+( 11 + 2*06 + 3*22 + 4*09 ) – 30)
=Abs(1+(11 + 12 + 66 + 36 ) – 30)
= Abs(127 – 30)
= 97
obj[2] = Abs(2+(03 + 2*20 + 3*19 + 4*04) – 30)
= Abs(2+(03 + 40 + 57 + 16) – 30)
= Abs(118 – 30)
= 88
F_obj[3] = Abs(3+(12 + 2*06 + 3*15 + 4*16) – 30)
= Abs(3+(12 + 16 + 45 + 64) – 30)
= Abs(140 – 30)
= 110
obj[4] = Abs(4+(19 + 2*01 + 3*9 + 4*05) – 30)
= Abs(4+(19 + 02 + 27 + 20) – 30)
= Abs(72 – 30)
= 42
obj[5] = Abs(5+(01 + 2*06 + 3*11 + 4*16) – 30)
= Abs(5+(01 + 12 + 33 + 64) – 30)
= Abs(115 – 30)
= 85
obj[6] = Abs(6+(17 + 2*08 + 3*14 + 4*04) – 30)
= Abs(6+(17 + 16+ 42 + 16) – 30)
= Abs(97 – 30)
= 67
obj[7] = Abs(7+(01 + 2*03 + 3*05 + 4*07) – 30)
= Abs(7+(1 + 6+ 15 + 28) – 30)
= Abs(57 – 30)
= 27
obj[8] = Abs(8+(02 + 2*06 + 3*08 + 4*10) – 30)
= Abs(8+(2 + 12+ 24 + 40) – 30)
= Abs(86 – 30)
= 56
obj[9] = Abs(9+(03 + 2*05 + 3*07 + 4*09) – 30)
= Abs(9+(3 + 10+ 21 + 36) – 30)
= Abs(79 – 30)
= 49
Step 3. Selection
Since, the fittest chromosomes have higher probability to be selected for the next generation, the fitness of each chromosome is computed and to avoid Zero divide the value of obj is added by 1.
Fitness_obj1[1] = 1 / (1+ obj[1])
1 / 98
= 0.01020
Fitness_obj2[2] = 1 / (1+ obj[2])
= 1 / 89
= 0.01123
Fitness_obj3[3] = 1 / (1+ obj[3])
= 1 / 111
= 0.00900
Fitness_obj4[4] = 1 / (1+ obj[4])
= 1 / 43
= 0.02325
Fitness_obj5[5] = 1 / (1+ obj[5])
= 1 / 86
= 0.01162
Fitness_obj6[6] = 1 / (1+ obj[6])
= 1 / 68
= 0.01470
Fitness_obj7[7] = 1 / (1+ obj[7])
= 1 / 28
= 0.03571
Fitness_obj8[8] = 1 / (1+ obj[8])
= 1 / 57
= 0.01754
Fitness_obj8[9] = 1 / (1+ obj[9])
= 1 / 50
= 0.02000
Total = 0.01020+0.01123+0.00900+0.02325+0.01162+0.01470+0.03571+0.01754+0.02000=0.15325
The probability for each chromosomes an be c formulated by: P[i] = Fitness[i] / Total
P[1] = 0.01020/ 0.15325= 0.0665
P[2] = 0.01123/ 0.15325= 0.0733
P[3] = 0.00900/ 0.15325= 0.0588
P[4] = 0.02325/ 0.15325= 0.1518
P[5] = 0.01162/ 0.15325= 0.0759
P[6] = 0.01470/ 0.15325= 0.0959
P[7] = 0.03571/ 0.15325= 0.2330
P[8] = 0.01754/ 0.15325= 0.1144
P[9] = 0.02000/ 0.15325= 0.1305
Chromosome 4 has the highest fitness and selection probability to the next generation chromosomes. In a roulette wheel selection process cumulative probability values are computed
C[1] = .01020
C[2] = .01020+0.01123= 0.02143
C[3] = 0.01020+0.01123+0.00900= 0.03043
C[4] = 0.01020+0.01123+0.00900+0.02325= 0.05368
C[5] = 0.01020+0.01123+0.00900+0.02325+0.01162= 0.0653
C[6] = 0.01020+0.01123+0.00900+0.02325+0.01162+0.01470= 0.08
C[7] = 0.01020+0.01123+0.00900+0.02325+0.01162+0.01470+0.03571= 0.11571
C[8] = 0.01020+0.01123+0.00900+0.02325+0.01162+0.01470+0.03571+0.01754= 0.13325
C[9] = 0.01020+0.01123+0.00900+0.02325+0.01162+0.01470+0.03571+0.01754+0.02000=0.15325
Since the calculated the cumulative probability of selection process using roulette-wheel is depicted below. The following table lists a sample population of 9 individuals as larger population would be difficult to illustrate.
No Chromosome Value F(x) Percent of Total Higher Fitness
1 [11;06;22;09] 0.0665 43.39315 Yes
2 [03;20;19;04] 0.0733 47.83034
3 [12;06;15;16] 0.0588 38.36868
4 [19;01;9;05] 0.1518 99.05383
5 [01;06;11;16] 0.0759 49.52692
6 [17;08;14;04] 0.0959 62.57749
7 [01;03;05;07] 0.233 152.0392
8 [02;06;08;10] 0.1144 74.64927
9 [03;05;07;09] 0.1305 85.15498
Example of 9 for f (x) = ((x + 2i + 3i + 4k) – 30).
those with higher fitness get selected wit a large probability
//return–>individuals with highest fitness. Pseudo code for roulette selection
def rou_sele(population, fitnesses, num):
“”” Roulette selection, implemented according to:
total_fitness = float(sum(fitnesses))
rel_fitness = [f/total_fitness for f in fitnesses]
# Generate probability intervals for each individual
probs = [sum(rel_fitness[:i+1]) for i in range(len(rel_fitness))]
# Draw new population
new_population = []
for n in xrange(num):
r = rand()
for (i, individual) in enumerate(population):
if r <= probs[i]:
new_population.append(individual)
break
return new_population
NewChromosome[1] = Chromosome[2]
NewChromosome[2] = Chromosome[3]
NewChromosome[3] = Chromosome[4]
NewChromosome[4] = Chromosome[5]
NewChromosome[5] = Chromosome[6]
NewChromosome[6] = Chromosome[7]
Step 4. Crossover
When one-cut point is used i.e. randomly selecting a position in the parent chromosome and then exchanging sub-chromosome. The Parent chromosome will mate with the randomly selected and the number of mate Chromosomes is controlled using crossover_rate (ρc). Pseudo-code for the crossover process is as follows:
begin k← 0;
while(k<population) do R[k] ← random(0-1); if (R[k] < ρc ) then
select Chromosome[k] as parent; end;
k = k + 1; end;
end;
Chromosome k will be selected as a parent if R [k] <ρc. When the crossover rate is 24%, then Chromosome number k will be selected for crossover if random generated value for Chromosome k below 0.24. The process is to generate a random number R as the number of population.
R[1] = 0.202
R[2] = 0.282
R[3] = 0.097
R[4] = 0.824
R[5] = 0.396
R[6] = 0.503
For random number R above, parents are Chromosome [1], Chromosome [3] and Chromosome [5] which will be selected for crossover.
Chromosome[1] >< Chromosome[3]
Chromosome[3] >< Chromosome[5]
Chromosome[5] >< Chromosome[1]
After chromosome selection, the next process is determining the position of the crossover point. This is done by generating random numbers between 1 to (length of Chromosome – 1). In this case, generated random numbers should be between 1 and 3. After we get the crossover point, parents Chromosome will be cut at crossover point and its gens will be interchanged. For example we generated 3 random number and we get:
C[1] = 1
C[2] = 1
C[3] = 2
Then for first crossover, second crossover and third crossover, parent’s gens will be cut at gen number 1, gen number 1 and gen number 3 respectively, e.g.
Chromosome[1] = Chromosome[1] >< Chromosome[3]
• [11;06;22;09]>< [12;06;15;16]
• [11;06;15;16]
Chromosome[3] = Chromosome[3] >< Chromosome[5]
= [12;06;15;16]>< [01;06;11;16]
= [12;06;11;16]
Chromosome[5] = Chromosome[5] >< Chromosome[1]
= [01;06;11;16] >< [11;06;22;09]
= [01;06;22;09]
Thus Chromosome population after crossover:
Chromosome[1] = [11;06;15;16]
Chromosome[2] = [03;20;19;04]
Chromosome[3] = [12;06;11;16]
Chromosome[4] = [19;06;11;16]
Chromosome[5] = [01;06;22;09]
Chromosome[6] = [17;08;14;04]
Step 5. Mutation
Number of chromosomes that have mutations in a population is determined by the mutation rate parameter. Mutation process is done by replacing the gen at random position with a new value. The process is as follows. First calculate the total length of gen in the population. In this case the total length of gen is total_gen = number_of_gen_in_Chromosome * number of population
= 4 * 6 = 24
Mutation process is done by generating a random integer between 1 and total_gen (1 to 24). If generated random number is smaller than mutation_rate(ρm) variable then marked the position of gen in chromosomes. Suppose we define ρm 10%, it is expected that 10% (0.1) of total_gen in the population that will be mutated:
number of mutations = 0.1 *24 = 2.4 ≈ 2
Suppose generation of random number yield 12 and 18 then the chromosome which have mutation are Chromosome number 3 gen number 4 and Chromosome 5 gen number 2. The value of mutated gens at mutation point is replaced by random number between 0-30. Suppose generated random number are 2 and 5 then Chromosome composition after mutation are:
Chromosome[1] = [11;06;15;16]
Chromosome[2] = [03;20;19;04]
Chromosome[3] = [12;06;11;16]
Chromosome[4] = [19;06;11;16]
Chromosome[5] = [01;06;22;09]
Chromosome[6] = [17;08;14;04]
Finishing mutation process then we have one iteration or one generation of the genetic algorithm. We can now evaluate the objective function after one generation:
Chromosome[1] = [11;06;15;16]
obj[1] = Abs(( 11 + 2*06 + 3*15+ 4*16 ) – 30)
= Abs((11 + 12 + 45 + 64 ) – 30)
= Abs(132 – 30)
= 102
Chromosome[2] = [03;20;19;04]
obj[2] = Abs(( 03 + 2*20 + 3*19 + 4*04 ) – 30)
= Abs((03 + 40+ 57 + 16 ) – 30)
= Abs(116 – 30)
= 86
Chromosome[3] = [12;06;11;16]
obj[3] = Abs(( 12 + 2*06 + 3*11 + 4*16 ) – 30)
Abs((12 + 12 + 33 + 64 ) – 30)
Abs(121 – 30)
91
Chromosome[4] = [19;01;9;05]
obj[4] = Abs(( 19 + 2*01 + 3*9 + 4*05 ) – 30)
= Abs((19 + 2 + 27 + 20 ) – 30)
= Abs(68 – 30)
= 38
Chromosome[5] = [01;06;22;9]
obj[5] = Abs(( 01 + 2*06 + 3*22 + 4*9) – 30)
= Abs((01 + 12 + 66 + 36 ) – 30)
= Abs(115 – 30)
= 85
Chromosome[6] = = [17;08;14;04]
obj[6] = Abs(( 17 + 2*08 + 3*14 + 4*04 ) – 30)
= Abs((17 + 16 + 42 + 16 ) – 30)
= Abs(91 – 30)
= 61
From the evaluation of new Chromosome we can see that the objective function is decreasing, this means that we have better Chromosome or solution compared with previous Chromosome generation. New Chromosomes for next iteration are:
Chromosome[1] = [11;06;15;16]
Chromosome[2] = [03;20;19;04]
Chromosome[3] = [12;06;11;16]
Chromosome[4] = [19;06;11;16]
Chromosome[5] = [01;06;22;09]
Chromosome[6] = [17;08;14;04]
These new Chromosomes will undergo the same process as the previous generation of Chromosomes such as evaluation, selection, crossover and mutation and at the end it produce new generation of Chromosome for the next iteration. This process will be repeated until a predetermined number of generations. For this example, after running 45 generations, best chromosome is obtained:
Chromosome = [06; 05; 04; 03] which implies i = 6, j = 5, k = 4, l = 3
If we use the number in the problem equation i +2 j +3 k +4 l = 30
6 + (2 * 5) + (3 * 4) + (4 * 3) = 30
We can see that the value of variable i, j, k and l generated by genetic algorithm can satisfy that equality.
Conclusions
In this paper, an approach for using GA in object orient programming has been introduced. Object creation and testing of object oriented software includes test program which create and manipulate objects in order to achieve a certain test goal. The approach described in this paper facilitates the automatic generation of object oriented program using genetic algorithms.
Essay: Genetic Algorithm For Object Oriented Software Development
Essay details and download:
- Subject area(s): Computer science essays
- Reading time: 12 minutes
- Price: Free download
- Published: 17 June 2021*
- Last Modified: 15 October 2024
- File format: Text
- Words: 2,392 (approx)
- Number of pages: 10 (approx)
Text preview of this essay:
This page of the essay has 2,392 words.
About this essay:
If you use part of this page in your own work, you need to provide a citation, as follows:
Essay Sauce, Genetic Algorithm For Object Oriented Software Development. Available from:<https://www.essaysauce.com/computer-science-essays/genetic-algorithm-for-object-oriented-software-development/> [Accessed 27-11-24].
These Computer science essays have been submitted to us by students in order to help you with your studies.
* This essay may have been previously published on EssaySauce.com and/or Essay.uk.com at an earlier date than indicated.