Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PROBLEMS
begin
INITIALIZE population with random candidate solutions;
EVALUATE each candidate;
repeat
SELECT parents;
RECOMBINE pairs of parents;
MUTATE the resulting children;
EVALUATE children;
SELECT individuals for the next generation
until TERMINATION-CONDITION is satisfied
end
Parent selection
Parents
Initialization
Recombination
Population
Mutation
Termination
Children
Survivor selection
1
It’s clear that this scheme falls in the category of generate-and-test algorithms. The
evaluation function represents a heuristic estimation of solution quality and the search
process is driven by the variation and the selection operator. GA has a number of
features:
- GA is population-based
- GA uses recombination to mix information of candidate solutions into a new
one.
- GA is stochastic.
Representation
Objects forming possible solution within original problem context are called
phenotypes, their encoding, the individuals within the GA, are called genotypes.
The representation step specifies the mapping from the phenotypes onto a set of
genotypes.
Candidate solution, phenotype and individual are used to denotes points of the space of
possible solutions. This space is called phenotype space.
Chromosome, and individual can be used for points in the genotye space.
Variation Operators
The role of variation operators is to create new individuals from old ones. Variation
operators form the implementation of the elementary steps with the search space.
Mutation Operator
A unary variation operator is called mutation. It is applied to one genotype and delivers
a modified mutant, the child or offspring of it.
Crossover Operator
2
A binary variation operator is called recombination or crossover. This operator merges
information from two parent genotypes into one or two offspring genotypes.
The principle behind crossover is simple: by mating two individuals with different but
desirable features, we can produce an offspring which combines both of those features.
The role of parent selection (mating selection) is to distinguish among individuals based
on their quality to allow the better individuals to become parents of the next generation.
Parent selection is probabilistic. Thus, high quality individuals get a higher chance to
become parents than those with low quality. Nevertheless, low quality individuals are
often given a small, but positive chance, otherwise the whole search could become too
greedy and get stuck in a local optimum.
The role of survivor selection is to distinguish among individuals based on their quality.
In GA, the population size is (almost always) constant, thus a choice has to be made on
which individuals will be allowed in the next generation. This decision is based on their
fitness values, favoring those with higher quality.
Initialization
Initialization is kept simple in most GA applications. Whether this step is worth the
extra computational effort or not is very much depending on the application at hand.
Termination Condition
Notice that GA is stochastic and mostly there are no guarantees to reach an optimum.
3
Note: Premature convergence is the well-known effect of loosing population diversity
too quickly and getting trapped in a local optimum.
Population
In almost all GA applications, the population size is constant, not changing during the
evolutional search.
3.1 Initialization
While genetic algorithms are generally stated with an initial population that is
generated randomly, some research has been conducted into using special techniques to
produce a higher quality initial population. Such an approach is designed to give the GA
a good start and speed up the evolutionary process.
Example: Some authors propose a GA for exam timetabling problem in which the GA
works only with feasible solutions, implying that the initial population must also be
made up of feasible solution. Then the GA is run to improve the fitness of the initial
population.
Example 3.1: In a simple exam timetabling problem, we can use a non-binary bit string
representation to represent the chromosome because it is easy to understand and
represent. We use six positions representing six exams with each position’s value as the
time slot assigned to the exam. We can generate the population randomly to assign each
exam a timeslot.
Day AM PM
time1 time2 time3 time4
Day1 e1 e3
Day2 e5 e6 e2,e4
If we randomly generate six numbers 3, 8, 4, 8, 6, 7 as six timeslots for e1-e6, then the
chromosome is 3 8 4 8 6 7.
4
index chromosome fitness
1 384867 0.005
2 737613 0.062
3 535558 0.006
4 767722 0.020
5 174522 0.040
3.2 Reproduction
Generational Reproduction
Steady-state Reproduction
The steady-state method selects two chromosomes according to the current selection
procedure, performs crossover on them to obtain one or two children, perhaps applies
mutation as well, and installs the result back into that population; the least fit of the
population is destroyed.
Fitness-based selection
The standard, original method for parent selection is Roulette Wheel selection or
fitness-based selection. In this kind of parent selection, each chromosome has a chance
of selection that is directly proportional to its fitness. The effect of this depends on the
range of fitness values in the current population.
Example: if fitness range from 5 to 10, then the fittest chromosome is twice as likely to
be selected as a parent than the least fit.
If we apply fitness-based selection on the population given in example 3.1, we select the
second chromosome 7 3 7 6 1 3 as our first parent and 1 7 4 5 2 2 as our second parent.
Rank-based selection
5
In the rank-based selection method, selection probabilities are based on a chromosome’s
relative rank or position in the population, rather than absolute fitness.
Tournament-based selection
The original tournament selection is to choose K parents at random and returns the
fittest one of these.
The crossover operator is the most important in GA. Crossover is a process yielding
recombination of bit strings via an exchange of segments between pairs of
chromosomes. There are many kinds of crossover.
One-point Crossover
Example: With the two parents selected above, we randomly generate a number 2 as
the crossover position:
Parent1: 7 3 7 6 1 3
Parent2: 1 7 4 5 2 2
Then we get two children:
Child 1 : 7 3| 4 5 2 2
Child 2 : 1 7| 7 6 1 3
Example: With the two parents selected above, we randomly generate two numbers 2
and 4 as the crossover positions:
Parent1: 7 3 7 6 1 3
Parent2: 1 7 4 5 2 2
Then we get two children:
Child 1 : 7 3| 4 5| 1 3
Child 2 : 1 7| 7 6| 2 2
Uniform Crossover
The procedure of uniform crossover : each gene of the first parent has a 0.5 probability
of swapping with the corresponding gene of the second parent.
6
Example: For each position, we randomly generate a number between 0 and 1, for
example, 0.2, 0.7, 0.9, 0.4, 0.6, 0.1. If the number generated for a given position is less
than 0.5, then child1 gets the gene from parent1, and child2 gets the gene from parent2.
Otherwise, vice versa.
Parent1: 7 *3 *7 6 *1 3
Parent2: 1 *7 *4 5 *2 2
3.5 Inversion
3.6 Mutation
Mutation has the effect of ensuring that all possible chromosomes are reachable. With
crossover and even inversion, the search is constrained to alleles which exist in the
initial population. The mutation operator can overcome this by simply randomly
selecting any bit position in a string and changing it. This is useful since crossover and
inversion may not be able to produce new alleles if they do not appear in the initial
generation.
Example: Assume that we have already used crossover to get a new string: 7 3 4 5 1 3.
Assume the mutation rate is 0.001 (usually a small value). Next, for the first bit 7, we
generate randomly a number between 0 and 1. If the number is less than the mutation
rate (0.001), then the first bit 7 needs to mutate. We generate another number between 1
and the maximum value 8, and get a number (for example 2). Now the first bit mutates
to 2. We repeat the same procedure for the other bits. In our example, if only the first bit
mutates, and the rest of the bits don’t mutate, then we will get a new chromosome as
below:
234513
There are many ways to handle constraints in a GA. At the high conceptual level we can
distinguish two cases: indirect constraint handling and direct constraint handling.
7
Direct constraint handling means that we leave the constraints as they are and ‘adapt’
the GA to enforce them.
Notice that direct and indirect constraint handling can be applied in combination, i.e.,
in one application we can handle some constraints directly and others indirectly.
Treating constraints directly implies that violating them is not reflected in the fitness
function, thus there is no bias towards chromosomes satisfying them. Therefore, the
population will not become less and less infeasible w.r.t. these constraints. This means
that we have to create and maintains feasible chromosomes in the population. The basic
problem in this case is that the regular operators are blind to constraints, mutating one
or crossing over two feasible chromosomes can result in infeasible offspring. Typical
approaches to handle constraints directly are the following:
Decoding can simplify the problem search space and allow an efficient genetic
algorithm. Formally, decoding can be seen as shifting to a search space that is different
from the Cartesian product of the domains of the variables in the original problem
formulation.
In the case of indirect constraint handling the optimization objectives replacing the
constraints are viewed penalties for constraint violation hence to be minimized. In
general penalties are given for violated constraints although some GAs allocate
penalties for wrongly instantiated variables or as the distance to a feasible solution.
8
- possibility of embedding user preferences by means of weights.
A chromosome is a permutation of the number 1,…,8 and a given g = < i1,…, i8>
denotes the board configuration where the k-th column contains exactly one queen
placed on the ik th row.
Example: the permutation g = < 1,2,3,4,5,6,7,8> represents a board where the queens
are placed along the main diagonal. The solution space is now the set of all
permutations of 1,…,8.
Given two parents, which are two permutations, the following mechanism will create
two child permutations.
Example: parent1 1 3 5| 7 6 2 4 8
Parent2 2 1 8| 6 4 3 5 7
Child1: 1 3 5| 2 8 6 4 7
Child2: 2 1 8| 3 5 7 6 4
We select two positions in a given chromosome and swaps the values standing on those
positions.
9
Note that mutation will cause a small undirected change and crossover creates children
that inherit genetic material from both parents.
Parent selection (best 2 out of random 5) choosing 5 individuals randomly from the
population and taking the best two as parents that undergone crossover. This ensures a
bias towards using parents with relatively high fitness.
Survivor selection: (replace worst) after merging the population and offsprings, then
ranks them according to fitness and deletes the worst two.
Burke et al., 1995 [1] proposed a genetic algorithm for solving exam timetabling
problem. This algorithm combines direct representation and heuristic crossover
operators to ensure that the most fundamental constraints are never violated. Heuristic
crossover operators are used to propagate the most desirable features of the timetable to
produce good quality solutions.
When using GA to solve an combinatorial optimization problem, the first important step
is to choose how to represent a solution of the problem as a chromosome. In applying
GA to exam timetabling problem, the most logical approach is to directly encode
solutions with events matched to periods. Figure 5.1 shows such an encoding for n
events where each gene in the chromosome represents which period in which a
particular event is to be scheduled.
10
6.2 The Creation of an Initial Population
The following algorithm is used to generate conflict-free graph colorings which form
the initial population.
This algorithm can quickly produce large populations of random feasible exam
timetables.
The random sequential graph coloring algorithm is used to generate the starting
population. It uses on average about twice as many periods as the optimal amount.
Then the GA evolves new timetables, possibly reducing the length. This approach
guarantees a feasible timetable and does not create a search space in which no solution
exists.
It is clear that the crossover operator should satisfy the properties of respect and
assortment given by Radcliffe.
Respect is the property that if an exam is timetabled to the same period in both parents
then it will be scheduled to that period in the child.
Assortment is the property that the operator can generate a child such that if Exam1 is
scheduled to Period 1 in the first parent and Exam2 is scheduled to Period 2 in the
second parent then the child may have Exam 1 in Period 1 and Exam 2 in Period 2
providing that these are compatible.
11
Figure 5.2 A Heuristic Crossover Operator
Once an exam is selected, all other exams that clash with it are labeled as unscheduled
for that period.
The authors construct a number of different crossover operators based on the same
framework but using alternative selection algorithms. The operators are as follows.
• Random
Exams are selected at random. This is closest to the standard uniform crossover.
• Largest Degree
Exams are selected according to the number of other exams they conflict with.
• Most Similar Exams
Exams are selected according to how many conflicting exams they have in common
with those already scheduled.
• Latest Scheduled in other Parent.
Exams are selected according to where the same exam is scheduled in the other
parent. Since unplaced exams are passed on the next period, this increases the chances
of shortening the length of the timetable.
• Least Conflicting with Previous Period
Exams are selected so as to minimize the number of conflicts with exams in the
previously scheduled period.
Mutation, like crossover, must also ensure that a timetable remains feasible after its
action. It cannot take any exam and shift it to another period at random, since this may
cause a conflict between the moved exams and ones already scheduled.
We choose to incorporate mutation into the crossover algorithm. This is done by adding
exams to the current search that would otherwise not be considered until a later period.
The evaluation function can be made up of any timetabling related factors. For example,
we may focus on two particular common requirements:
- The length of the timetable
- The number of conflicts between exams in adjacent periods.
Notice that the quality of a solution p may not vary smoothly as the genes comprising p
vary since the genetic operators such as crossover and mutation do not vary the gene
values smoothly.
12
f(p) = 1/(1 + V(p))
so that the range of f(p) is from 0 to 1.
If we have n kinds of soft constraints, the penalty associated with constraint-type i is wi,
p is a timetable, and ci(p) is the number of violations of constraints of type i in p, then
the fitness function becomes:
n
f(p) = 1/(1 + ∑ wici(p))
i =1
6.7. Remarks
Burke et al. [1] combines traditional CSP solving heuristics with genetic algorithms.
The underlying motivation is to get the best of two worlds. The greediness of the
heuristics (which can lead to dead-ends) and the blindness of the stochastic genetic
search. The heuristics can be incorporated into the genetic operators mutation and
crossover.
VII CONCLUSIONS
However, genetic algorithms can be effective constraint solvers when knowledge about
the constraints is incorporated either into the genetic operators, in the fitness function,
or in repair mechanisms.
References
[1] Burke, E. K., Elliman, D.G., Weave, R. F., A Hybrid Genetic Algorithm for Highly
Constrained Timetabling Problems, Proc. of 6th International Conference on the
Practice and Theory of Automated Timetabling, Napier University, Edinburgh, UK,
1995.
[2] Craenen, B. C. W., Eiben, A. E. and Marchiori, E., How to Handle Constraint with
Evolutionary Algorithms. In L. Chambers (Ed.), The Practical Handbook of Genetic
Algorithms: Applications, 2nd Edition, volume 1, Chapman & Hall/CRC, 2001, pp. 341
– 361.
13
APPENDIX: Randomly Sequential Graph Coloring Algorithm
A coloring of a graph is an assignment of a color to each vertex of the graph so that no
two vertices connected by an edge have the same color.
Initially we try to color as many as vertices as possible with the first color, then as many
as possible of the uncolored with the new color, then as many as possible of the un-
colored vertices with the second color, and so on.
1. Select some uncolored vertex and color it with the new color.
2. Scan the list of uncolored vertices. For each uncolored vertex, determine
whether it has an edge to any vertex already colored with the new color. If there
is no such edge, color the present vertex with the new color.
Example: In figure A1 having colored vertex 1 red, we can color vertices 3 and 4 red
also.
3
red
red
2
1 5
4 red
14