Sei sulla pagina 1di 14

GENETIC ALGORITHMS TO CONSTRAINT SATISFACTION

PROBLEMS
Genetic algorithm is a population-based search method. Genetic algorithms are
acknowledged as good solvers for tough problems. However, no standard GA takes
constraints into account. This chapter describes how genetic algorithms can be used for
solving constraint satisfaction problems.
I. WHAT IS A GENETIC AGORITHM ?
The general scheme of a GA can be given as follows:
begin
IITIA!I"# population with random candidate solutions$
#%A!&AT# each candidate$
repeat
'#!#(T parents$
)#(*+,I# pairs of parents$
+&TAT# the resulting children$
#%A!&AT# children$
'#!#(T individuals for the ne-t generation
until T#)+IATI*.(*/ITI* is satisfied
end

The GA can be represented in form of a diagram:
0igure 1 The general scheme of Genetic Algorithm
2arents
(hildren
2opulation
Initiali3ation
Termination
)ecombination
+utation
2arent selection
'urvivor selection
1
It4s clear that this scheme falls in the categor5 of generate-and-test algorithms. The
evaluation function represents a heuristic estimation of solution 6ualit5 and the search
process is driven b5 the variation and the selection operator. GA has a number of
features:
. GA is population.based
. GA uses recombination to mi- information of candidate solutions into a new
one.
. GA is stochastic.
II COMPONENTS OF GENETIC ALGORITHMS
The most important components in a GA consist of:
7 representation 8definition of individuals9
7 evaluation function 8or fitness function9
7 population
7 parent selection mechanism
7 variation operators 8crossover and mutation9
7 survivor selection mechanism 8replacement9
Repreentati!n
*b:ects forming possible solution within original problem conte-t are called
phenotypes, their encoding, the individuals within the GA, are called genotypes.
The representation step specifies the mapping from the phenot5pes onto a set of
genot5pes.
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.
#lements of a chromosome are called genes. A value of a gene is called an allele.
"ariati!n Operat!r
The role of variation operators is to create new individuals from old ones. %ariation
operators form the implementation of the elementar5 steps with the search space.
Mutati!n Operat!r
A unar5 variation operator is called mutation. It is applied to one genot5pe and delivers
a modified mutant, the child or offspring of it.
In general, mutation is supposed to cause a random unbiased change. +utation has a
theoretical role: it can guarantee that the space is connected.
Cr!!#er Operat!r
;
A binar5 variation operator is called recombination or crossover. This operator merges
information from two parent genot5pes into one or two offspring genot5pes.

'imilarl5 to mutation, crossover is a stochastic operator: the choice of what parts of
each parent are combined, and the wa5 these parts are combined, depend on random
drawings.
The principle behind crossover is simple: b5 mating two individuals with different but
desirable features, we can produce an offspring which combines both of those features.
Parent Sele$ti!n Me$%ani&
The role of parent selection 8mating selection9 is to distinguish among individuals based
on their 6ualit5 to allow the better individuals to become parents of the ne-t generation.
2arent selection is probabilistic. Thus, high 6ualit5 individuals get a higher chance to
become parents than those with low 6ualit5. evertheless, low 6ualit5 individuals are
often given a small, but positive chance, otherwise the whole search could become too
greed5 and get stuck in a local optimum.
Sur#i#!r Sele$ti!n Me$%ani&
The role of survivor selection is to distinguish among individuals based on their 6ualit5.
In GA, the population si3e is 8almost alwa5s9 constant, thus a choice has to be made on
which individuals will be allowed in the ne-t generation. This decision is based on their
fitness values, favoring those with higher 6ualit5.
As opposed to parent selection which is stochastic, survivor selection is often
deterministic, for instance, ranking the unified multiset of parents and offspring and
selecting the top segment 8fitness biased9, or selection onl5 from the offspring 8age.
biased9.
Initiali'ati!n
Initiali3ation is kept simple in most GA applications. <hether this step is worth the
e-tra computational effort or not is ver5 much depending on the application at hand.
Ter&inati!n C!nditi!n
otice that GA is stochastic and mostl5 there are no guarantees to reach an optimum.
(ommonl5 used conditions for terminations are the following:
1. the ma-imall5 allowed (2& times elapses
;. The total number of fitness evaluations reaches a given limit
=. for a given period of time, the fitness improvement remains under a threshold
value
>. the population diversit5 drops under a given threshold.
=
ote: Premature convergence is the well.known effect of loosing population diversit5
too 6uickl5 and getting trapped in a local optimum.
P!pulati!n
The role of the population is to hold possible solutions. A population is a multiset of
genot5pes.
In almost all GA applications, the population si3e is constant, not changing during the
evolutional search.
III HOW (O GENETIC ALGORITHMS WOR) *
The details of how Genetic Algorithms work are e-plained below.
+., Initiali'ati!n
<hile genetic algorithms are generall5 stated with an initial population that is
generated randomly, some research has been conducted into using special techniques to
produce a higher 6ualit5 initial population. 'uch an approach is designed to give the GA
a good start and speed up the evolutionar5 process.
#-ample: 'ome authors propose a GA for e-am timetabling problem in which the GA
works onl5 with feasible solutions, impl5ing 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.
#-ample =.1: In a simple e-am timetabling problem, we can use a non.binar5 bit string
representation to represent the chromosome because it is eas5 to understand and
represent. <e use si- positions representing si- e-ams with each position4s value as the
time slot assigned to the e-am. <e can generate the population randoml5 to assign each
e-am a timeslot.
/a5 A+ 2+
time1 time; time= time>
/a51 e1 e=
/a5; e? e@ e;,e>
If we randoml5 generate si- numbers =, A, >, A, @, B as si- timeslots for e1-e6, then the
chromosome is 3 8 4 8 6 .
If the population si3e is ?, an initial population can be generated randoml5 as follows:
>
inde- chromosome fitness
1 3 8 4 8 6 C.CC?
; B = B @ 1 = C.C@;
= ? = ? ? ? A C.CC@
> B @ B B ; ; C.C;C
? 1 B > ? ; ; C.C>C
+.- Repr!du$ti!n
There are two kinds of reproduction: generational reproduction and stead5.state
reproduction.
Generati!nal Repr!du$ti!n
In generational reproduction, the whole of a population is potentiall5 replaced at each
generation. The most often used procedure is to loop D; times, where is the
population si3e, select t!o chromosomes each time according to the current selection
procedure, producing t!o children from those two parents, finall5 producing new
chromosomes.
Stead./tate Repr!du$ti!n
The stead5.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 destro5ed.
+.+ Parent Sele$ti!n &e$%ani&
The effect of selection is to return a probabilisticall5 selected parent. Although this
selection procedure is stochastic, it does not impl5 GA emplo5 a directionless search.
The chance of each parent being selected is in some wa5 related to its fitness.
Fitne/baed ele$ti!n
The standard, original method for parent selection is )oulette <heel selection or
fitness.based selection. In this kind of parent selection, each chromosome has a chance
of selection that is directl5 proportional to its fitness. The effect of this depends on the
range of fitness values in the current population.
#-ample: if fitness range from ? to 1C, then the fittest chromosome is twice as likel5 to
be selected as a parent than the least fit.
If we appl5 fitness.based selection on the population given in e-ample =.1, we select the
second chromosome B = B @ 1 = as our first parent and 1 B > ? ; ; as our second parent.
Ran0/baed ele$ti!n
?
In the rank.based selection method, selection probabilities are based on a chromosome4s
relative rank or position in the population, rather than absolute fitness.
T!urna&ent/baed ele$ti!n
The original tournament selection is to choose E parents at random and returns the
fittest one of these.
+.1 Cr!!#er Operat!r
The crossover operator is the most important in GA. (rossover is a process 5ielding
recombination of bit strings via an e-change of segments between pairs of
chromosomes. There are man5 kinds of crossover.
One/p!int Cr!!#er
The procedure of one.point crossover is to randoml5 generate a number 8less than or
e6ual to the chromosome length9 as the crossover position. Then, keep the bits before
the number unchanged and swap the bits after the crossover position between the two
parents.
#-ample: <ith the two parents selected above, we randoml5 generate a number ; as
the crossover position:
2arent1: B = B @ 1 =
2arent;: 1 B > ? ; ;
Then we get two children:
(hild 1 : B =F > ? ; ;
(hild ; : 1 BF B @ 1 =
T2!/p!int Cr! O#er
The procedure of two.point crossover is similar to that of one.point crossover e-cept
that we must select two positions and onl5 the bits between the two positions are
swapped. This crossover method can preserve the first and the last parts of a
chromosome and :ust swap the middle part.
#-ample: <ith the two parents selected above, we randoml5 generate two numbers ;
and > as the crossover positions:
2arent1: B = B @ 1 =
2arent;: 1 B > ? ; ;
Then we get two children:
(hild 1 : B =F > ?F 1 =
(hild ; : 1 BF B @F ; ;
3ni4!r& Cr!!#er
The procedure of uniform crossover : each gene of the first parent has a C.? probabilit5
of swapping with the corresponding gene of the second parent.
@
#-ample: 0or each position, we randoml5 generate a number between C and 1, for
e-ample, C.;, C.B, C.G, C.>, C.@, C.1. If the number generated for a given position is less
than C.?, then child1 gets the gene from parent1, and child; gets the gene from parent;.
*therwise, vice versa.
2arent1: B H= HB @ H1 =
2arent;: 1 HB H> ? H; ;
Then we get two children:
(hild 1 : B BH >H @ ;H =
(hild ; : 1 =H BH ? 1H ;
+.5 In#eri!n
Inversion operates as a kind of reordering techni6ue. It operates on a single
chromosome and inverts the order of the elements between two randoml5 chosen points
on the chromosome. <hile this operator was inspired b5 a biological process, it re6uires
additional overhead.
#-ample: Given a chromosome = A > A @ B. If we randoml5 choose two positions ;, ?
and appl5 the inversion operator, then we get the new string: = @ A > A B.
+.6 Mutati!n
+utation has the effect of ensuring that all possible chromosomes are reachable. <ith
crossover and even inversion, the search is constrained to alleles which e-ist in the
initial population. The mutation operator can overcome this b5 simpl5 randoml5
selecting an5 bit position in a string and changing it. This is useful since crossover and
inversion ma5 not be able to produce new alleles if the5 do not appear in the initial
generation.
#-ample: Assume that we have alread5 used crossover to get a new string: B = > ? 1 =.
Assume the mutation rate is C.CC1 8usuall5 a small value9. e-t, for the first bit B, we
generate randoml5 a number between C and 1. If the number is less than the mutation
rate 8C.CC19, then the first bit B needs to mutate. <e generate another number between 1
and the ma-imum value A, and get a number 8for e-ample ;9. ow the first bit mutates
to ;. <e repeat the same procedure for the other bits. In our e-ample, if onl5 the first bit
mutates, and the rest of the bits don4t mutate, then we will get a new chromosome as
below:
; = > ? 1 =
I". CONSTRAINT HAN(LING IN GENETIC ALGORITHMS
There are man5 wa5s to handle constraints in a GA. At the high conceptual level we can
distinguish two cases: indirect constraint handling and direct constraint handling.
Indirect constraint handling means that we circumvent the problem of satisf5ing
constraints b5 incorporating them in the fitness function f such that f optimal implies
that the constraints are satisfied, and use the power of GA to find a solution.
B
/irect constraint handling means that we leave the constraints as the5 are and Iadapt4
the GA to enforce them.
otice that direct and indirect constraint handling can be applied in combination, i.e., in
one application we can handle some constraints directl5 and others indirectl5.
0ormall5, indirect constraint handling means transforming constraints into optimi3ation
ob:ectives.
1., (ire$t $!ntraint %andling
Treating constraints directl5 implies that violating them is not reflected in the fitness
function, thus there is no bias towards chromosomes satisf5ing 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. T5pical
approaches to handle constraints directl5 are the following:
eliminating infeasible candidates
repairing infeasible candidates
preserving feasibilit5 b5 special operators
decoding, i.e. transforming the search space.
#liminating infeasible candidates is ver5 inefficient, and therefore hardl5 applicable.
)epairing infeasible candidates re6uires a repair procedure that modifies a given
chromosome such that it will not violate constraints. This techni6ue is thus problem
dependent.
The preserving approach amounts to designing and appl5ing problem.specific operators
that do preserve the feasibilit5 of parent chromosomes. ote that the preserving
approach re6uires the creation of a feasible initial population, which can be 2.
complete.
/ecoding can simplif5 the problem search space and allow an efficient genetic
algorithm. 0ormall5, decoding can be seen as shifting to a search space that is different
from the (artesian product of the domains of the variables in the original problem
formulation.
1.- Indire$t C!ntraint Handling
In the case of indirect constraint handling the optimi3ation ob:ectives replacing the
constraints are viewed penalties for constraint violation hence to be minimi3ed. In
general penalties are given for violated constraints although some GAs allocate
penalties for wrongl5 instantiated variables or as the distance to a feasible solution.

Advantages of indirect constraint handling are:
. generalit5
. reduction of the problem to Isimple4 optimi3ation
A
. possibilit5 of embedding user preferences b5 means of weights.
/isadvantages of indirect constraint handling are:
. loss of information b5 packing ever5thing in a single number
. does not work well with sparse problems.
". GENETIC ALGORITHM FOR 7/83EENS PROBLEM
5., S!luti!n Repreentati!n
A chromosome is a permutation of the number 1,J,A and a given g K L i
1
,J, i
A
M
denotes the board configuration where the ".th column contains e-actl5 one 6ueen
placed on the i
"
th row.
#-ample: the permutation g K L 1,;,=,>,?,@,B,AM represents a board where the 6ueens
are placed along the main diagonal. The solution space is now the set of all
permutations of 1,J,A.
,5 using such chromosome we restrict the search to board configurations where
hori3ontal constraint violation 8two 6ueens on the same column9 and vertical constraint
violation 8two 6ueens on the same row9 do not occur. In other words, the representation
guarantees NhalfO number of the constraints and what remains to be minimi3ed is the
number of diagonal constraint violations.
5.- Cr!!#er !perat!r
8cut and crossfill9
Given two parents, which are two permutations, the following mechanism will create
two child permutations.
1. select a random position, crossover point, i P1, J, BQ
;. cut both parents in two segments after this position
=. cop5 the first segment of parent 1 into child 1 and the first segment of parent ;
into child ;
>. scan parent ; from left to right and fill the second segment of child 1 with values
from parent ; skipping those that alread5 contained in it.
?. do the same for parent 1 and child ;.
#-ample: parent1 1 = ?F B @ ; > A
2arent; ; 1 AF @ > = ? B
(hild1: 1 = ?F ; A @ > B
(hild;: ; 1 AF = ? B @ >
5.+ Mutati!n !perat!r
<e select two positions in a given chromosome and s!aps the values standing on those
positions.
G
ote that mutation will cause a small undirected change and crossover creates children
that inherit genetic material from both parents.
5.1 Parent ele$ti!n and ur#i#!r ele$ti!n
Parent ele$ti!n 8best # out of random $9 choosing ? individuals randoml5 from the
population and taking the best two as parents that undergone crossover. This ensures a
bias towards using parents with relativel5 high fitness.
Sur#i#!r ele$ti!n: 8replace !orst9 after merging the population and offsprings, then
ranks them according to fitness and deletes the worst two.
5.5 Ot%er iue
)ecombination probabilit5 1CCR
+utation probabilit5 ACR
2opulation si3e 1CC
Initiali3ation random
Termination 'olution or 1CCCC evaluations
"I. A GENETIC ALGORITHM FOR E9AM TIMETABLING PROBLEM
,urke et al., 1GG? S1T proposed a genetic algorithm for solving e-am 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 6ualit5 solutions.
6., S!luti!n Repreentati!n
<hen using GA to solve an combinatorial optimi3ation problem, the first important step
is to choose how to represent a solution of the problem as a chromosome. In appl5ing
GA to e-am timetabling problem, the most logical approach is to directl5 encode
solutions with events matched to periods. 0igure ?.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.
0igure ?.1 A direct representation of a timetable
1C
2eriod 2eriod
1 =
2eriod 2eriod
; B
#vent 1 #vent ; #vent n.1 #vent n
6.- T%e Creati!n !4 an Initial P!pulati!n
The following algorithm is used to generate conflict.free graph colorings which form
the initial population.
0or each population member:
Generate a random ordering of e-ams
Take each e-am in turn according to that ordering:
0ind the first period in which the e-am ma5 be placed without conflict and so that
the number of students does not go above a predefined ma-imum.
2lace the e-am in that period.
This algorithm can 6uickl5 produce large populations of random feasible e-am
timetables.
ote: The method allows the length of the timetable to var5.
The random se6uential graph coloring algorithm is used to generate the starting
population. It uses on average about twice as man5 periods as the optimal amount.
Then the GA evolves new timetables, possibl5 reducing the length. This approach
guarantees a feasible timetable and does not create a search space in which no solution
e-ists.
6.+ Cr!!#er Operat!r
It is clear that the crossover operator should satisf5 the properties of respect and
assortment given b5 )adcliffe.
%espect is the propert5 that if an e-am is timetabled to the same period in both parents
then it will be scheduled to that period in the child.
&ssortment is the propert5 that the operator can generate a child such that if '(am1 is
scheduled to Period 1 in the first parent and '(am# is scheduled to Period # in the
second parent then the child ma5 have '(am 1 in Period 1 and '(am # in Period #
providing that these are compatible.
The crossover operator works for the period i as follows:
The operator starts b5 looking at the first period. It takes e-ams scheduled in that period
8in both parents9 and then uses an algorithm to select other e-ams so that none clash
with those alread5 scheduled and the limit on the number of spaces is not violated. *nce
this is completed, the crossover looks at period two and so on until all e-ams are placed.
2eriod i of child Timetable:
Take those e-ams schedules in period i in both parents 1 and ;.
'elect e-tra e-ams from the e-ams scheduled in period i in either parent 1 or
parent ; or left over from period i-1.
8An5 unscheduled e-ams are passed onto period i)19.
11
0igure ?.; A Heuristic (rossover *perator
*nce an e-am is selected, all other e-ams 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.
%andom
#-ams are selected at random. This is closest to the standard uniform crossover.
*argest +egree
#-ams are selected according to the number of other e-ams the5 conflict with.
,ost -imilar '(ams
#-ams are selected according to how man5 conflicting e-ams the5 have in common
with those alread5 scheduled.
*atest -cheduled in other Parent.
#-ams are selected according to where the same e-am is scheduled in the other
parent. 'ince unplaced e-ams are passed on the ne-t period, this increases the chances
of shortening the length of the timetable.
*east Conflicting !ith Previous Period
#-ams are selected so as to minimi3e the number of conflicts with e-ams in the
previousl5 scheduled period.
6.1 Mutati!n Operat!r
+utation, like crossover, must also ensure that a timetable remains feasible after its
action. It cannot take an5 e-am and shift it to another period at random, since this ma5
cause a conflict between the moved e-ams and ones alread5 scheduled.
<e choose to incorporate mutation into the crossover algorithm. This is done b5 adding
e-ams to the current search that would otherwise not be considered until a later period.
6.5 Fitne Cal$ulati!n and Sele$ti!n
The evaluation function can be made up of an5 timetabling related factors. 0or e-ample,
we ma5 focus on two particular common re6uirements:
. The length of the timetable
. The number of conflicts between e-ams in ad:acent periods.
Given a space 2 of candidate solutions to a problem, fitness function f8p9 for p 2
measures the 6ualit5 of a solution p.
otice that the 6ualit5 of a solution p ma5 not var5 smoothl5 as the genes comprising p
var5 since the genetic operators such as crossover and mutation do not var5 the gene
values smoothl5.
It seems reasonable to distinguish between timetables in terms of fitness based on the
numbers and kinds of different constraints violated. 0or instance, if %8p9 is the number
of violated soft constraints in candidate p, one could choose:
1;

f8p9 K 1D81 7 %8p99
so that the range of f8p9 is from C to 1.
If we have n kinds of soft constraints, the penalt5 associated with constraint.t5pe i is !
i
,
p is a timetable, and c
i
.p/ is the number of violations of constraints of t5pe i in p, then
the fitness function becomes:
n
f8p9 K 1D81 7 w
i
c
i
8p99
i K1
6.6 Ot%er Iue
The Genetic algorithm for e-am timetabling problem uses:
. Generational )eproduction
. 2opulation si3e K ;CC
. )ank.based selection mechanism
6.:. Re&ar0
,urke et al. S1T combines traditional ('2 solving heuristics with genetic algorithms.
The underl5ing motivation is to get the best of two worlds. The greediness of the
heuristics 8which can lead to dead.ends9 and the blindness of the stochastic genetic
search. The heuristics can be incorporated into the genetic operators mutation and
crossover.
"II CONCL3SIONS
(onstraint handling is not straightforward in a GA because the search operators such as
mutation and recombination are Iblind4 to constraints. There is no guarantee that if the
parents satisf5 some constraints, the offspring will satisf5 them as well.
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.
Re4eren$e
S1T ,urke, #. E., #lliman, /.G., <eave, ). 0., A H5brid Genetic Algorithm for Highl5
(onstrained Timetabling 2roblems, Proc. of 6
th
0nternational Conference on the
Practice and 1heory of &utomated 1imetabling, apier &niversit5, #dinburgh, &E,
1GG?.
S;T (raenen, ,. (. <., #iben, A. #. and +archiori, #., How to Handle (onstraint with
#volutionar5 Algorithms. In !. (hambers 8#d.9, 1he Practical 2andboo" of 3enetic
&lgorithms4 &pplications5 #
nd
'dition, volume 1, (hapman U HallD()(, ;CC1, pp. =>1
V =@1.
1=
APPEN(I9; Rand!&l. Se<uential Grap% C!l!ring Alg!rit%&
A coloring of a graph is an assignment of a color to each verte- of the graph so that no
two vertices connected b5 an edge have the same color.
*ne strateg5 for graph coloring is the following Ngreed5O algorithm.
Initiall5 we tr5 to color as man5 as vertices as possible with the first color, then as man5
as possible of the uncolored with the new color, then as man5 as possible of the un.
colored vertices with the second color, and so on.
To color vertices with a new color, we perform the following steps.
1. 'elect some uncolored verte- and color it with the new color.
;. 'can the list of uncolored vertices. 0or each uncolored verte-, determine
whether it has an edge to an5 verte- alread5 colored with the new color. If there
is no such edge, color the present verte- with the new color.
#-ample: In figure A1 having colored verte- 1 red, we can color vertices = and > red
also.
0igure A1. (oloring vertices of a graph b5 randoml5 se6uential graph coloring
algorithm
There are some heuristics on the order of selecting one verte- from the list of uncolored
vertices.
? 1
>
=
;
red
red
red
1>

Potrebbero piacerti anche