Rochester Institute of Technology
RIT Scholar Works
Theses
Thesis/Dissertation Collections
1997
Teamwork in genetic programming
Michael LaLena
Follow this and additional works at:
http://scholarworks.rit.edu/theses
This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion
in Theses by an authorized administrator of RIT Scholar Works. For more information, please contact
Recommended Citation
Michael
LaLena
Masters Thesis
Rochester Institute of Technology
School of Computer Science and Technology
Teamwork in Genetic Programming
by
Michael LaLena
A thesis, submitted to
The Faculty of the School of Computer Science and Technology
in partial fulfillment of the requirement for the degree of
Master of Science in Computer Science
Approved by:
Prof. Anderson
Prof. Biles
Prof. Wolf
Thesis Reproduction
1, Michael LaLena, herl.'by
grant
permission to the Wallace Library of the Rochester
Institute of Technology to reproduce m)' t1h:sis in whole or in part.
Any reproduction will not be for COl11l11t'J'l'ial use or profit.
Abstract
This
thesis
attemptsto
solvefood
collection problemsusing
geneticprogramming.The
genetic program will evolve programsthat
mimicthe
way
ants can collectfood
andbring
it
back
to
a nest.There
aretwo
specialfactors in
this
geneticprogramthatmaketheants worktogether
in
orderto
solvethe problem,
as opposedto
each antacting
onits
own.First,
there
willbe
a streamin
the
environmentthat the
ants must crossto
getto the
food.
Although
all antshave
the
sameprogram,
some must moveinto
thewateranddie,
building
abridge for
the
other antsto
cross.The surviving
ants must realizethat
abridge
has already been built
that
they
canuse,
instead
ofkilling
themselves
by building
anotherbridge.
Second,
thefood
willbe
too
heavy
for
one antto
lift
alone.The
ants mustfind
thefood,
and callto
other antsfor help. If
all ofthe
ants areatfood
waiting
for
help,
some,
but
notall,
ofthe
ants must realizethat
they
arein
adeadlock
situation,
andleave
theirfood
to
help
other ants.Both
ofthese
problems requirethe
antsto
useteamwork tosolvethe
problem.The
ants must realizewhatother ants are
doing,
withoutdirect
communication ora state machine withintheants.Keywords
Genetic,
Programming, Artificial, Life, Emergent,
Behavior,
Food,
Collection,
Ant
Computing
Review
Subject Codes
1.2.6
Artificial Life
-Learning
1.2.2 Artificial
Life
-Automatic
Programming
1.6.1
Simulation
Modeling
-Simulation
Theory
Table
of
Contents
1
Introduction
1
1.1
Overview
1
1.2
Terminology
2
2
Genetic Algorithms
3
2.1
Definition
3
2.2
Example
4
2.3
Encoding
5
3
Genetic
Programming
8
3.1
Definition
8
3.2
Example
9
3.3
Encoding
15
4
Schemata
19
4.1
Partial Solutions
19
4.2
Schemata in Genetic
Programming
20
5
Search Space
21
5.1
Searching
21
5.2
Blind
21
5.2
Hill
Climbing
21
6
Emergent Behavior
23
7
The
Food Collection Problem
24
7.1
The Santa Fe Trail Problem
24
7.2
The
Single Ant Problem
25
7.3
The Water
Crossing
Problem
26
7.4
The
Heavy
Food Problem
27
8
The Ant Genetic Program
30
8.1
Program
Structure
30
8.2
Statements
30
8.3
Environment
32
8.4
Initial
Population
33
8.5
Fitness
33
8.6
Tournament Selection
34
8.7
Crossover
34
8.8
Mutation
35
8.9
Execution
35
9
Input
tothe
Genetic Program
36
9.1
Parameters
36
9.2
Instruction Set
37
9.3
Map
38
9.4
Program
38
9.5
First Program
38
10
Output
ofthe
Genetic Program
40
10.1
New Best
40
10.3
Program
Dump
41
11
Interface
42
11.1
Input
42
11-2
Configuration
42
11.3
Execution
43
12
Results
48
12.1
Simple Food Collection Problem (Test
1-4)
48
12.1.1
Input Parameters
48
12.1.2
Output Data
50
12.1.3
Synopsis
61
12.2
Simple Food Collection Problem (Test
5-6)
62
12.2.1
Input Parameters
62
12.2.2
Output Data
63
12.2.3
Synopsis
70
12.3
Simple Food Collection Problem (Test
7)
72
12.3.1
Input Parameters
72
12.3.2
Output Data
73
12.3.3
Synopsis
76
12.4
Water
Crossing
Problem (Test
8-9)
78
12.4.1
Input Parameters
78
12.4.2
Output Data
81
12.4.3
Synopsis
88
12.5
Water
Crossing
Problem (Test
10)
89
12.5.1
Input Parameters
89
12.5.2
Output Data
89
12.5.3
Synopsis
90
12.6
Heavy
Food Problem (Test 1
1-12)
91
12.6.1
Input Parameters
91
12.6.2
Output Data
94
12.6.3
Synopsis
99
12.7
Heavy
Food Problem (Test
13)
100
12.7.1
Input Parameters
100
12.7.2
Output Data
102
12.7.3
Synopsis
106
12.8
Heavy
Food Problem (Test
14)
107
12.8.1
Input Parameters
107
12.8.2
Output Data
108
12.8.3
Synopsis
112
12.9
Heavy
Food Problem (Test
15-16)
113
12.9.1
Input Parameters
113
12.9.2
Output Data
116
12.9.3
Synopsis
120
12.10
Water
Crossing
andHeavy
Food Problem (Test
17)
121
12.10.1
Input
Parameters
121
12.10.2
Output Data
124
12.1
1
Water
Crossing
andHeavy
Food Problem (Test
18)
127
12.11.1
Input Parameters
127
12.11.2
Output
Data
127
12.11.3
Synopsis
131
13
Unexpected
Results
132
14
Design
Issues
136
15
Conclusion
137
16
Future Research
138
1
Introduction
1.1
Overview
Genetic
Programming
is
a means ofevolving
solutionsto
difficult
problems,
wherethe
answeris
not obvious.Genetic
Programming
allows problemsto
be
solved withoutexplicitly programming
the
solution.This
is
done
by
way
of afitness
function. The fitness function
ratesthe
performance of a possible solution.Good
solutions are combinedwith othergood solutionstohopefully
create evenbetter
solutions.A
genetic program starts with a setoffunctions,
and continually
combinesthe
goodfunctions,
replacing
the
bad functions
withthe
newly
createdones.By
this process, the
genetic program can evolve a solution.This
thesis
is
aboutusing
geneticprogramming
to
create programsthatmimicthefood
collectionbehavior
of ants.The
thesis
willinclude
a programtotest
how
antscollectfood.
Many
other peoplehave
written genetic programsto
solvethefood
collection problem. The
ant problemis
almost abenchmark.
My
thesis
willdifferent from
other genetic programsin
one main way.I
amconcentrating
onfood
collection problems wheretheants must worktogether
in
orderto
succeed.Most
ant problemsinclude many
antssearching for food
andbringing
it back
to
a nest.The
same solutionthat
worksfor 20
ants will also workfor
one ant.20
ants areusedto
solvetheproblem20
timesfaster.
My
programwillbe
usedto
solve problemsslightly different in
that
what20
ants cando
to
solve aproblem,
1,
or even19,
will notbe
ableto
do
to
solvethe
same problem withthe
same solution.The
antswillhave
touseteamworkin
ordertosolvethe
problem.I
usedtwovariations ofthe
food
collection problem.The first
is adding
waterto theenvironment where
the
antswill collectfood.
By
putting
alake
ofwaterbetween
thenest andthe
food,
theants willhave
tofigure
outhow
to
go aroundthe
watertomovethefood
to thenest.This does
makethe
problem moredifficult,
but it
stilldoes
not require morethanoneant.
Placing
a streamin
the
environment, thatcompletely
separates theantsfrom
the water,will causethe
needfor
morethan
one ant.As in
nature, the
ants willbe
forced
to
build
an"ant
bridge"
to
crossthe
water.Some
ofthe
ants willhave
to
moveinto
the
streamand
die
to
build
abridge for
theother antscarrying food. The difficulties in
this
arehaving
the
antswithfood
find
thebridge,
and nothaving
alltheants runinto
thestream anddie.
The
secondvariationis
to
have
food
thatcanonly be lifted
by
morethanone ant.Several
ants willhave
to
lift
each piece offood
andbring
it back
to the
nesttogether.
Not
only do
theantshave
to
worktogether,
but
must alsofind
away
tocommunicatetheneedfor help. There is
alsothe
problemof all ofthe
antswaiting
atdifferent
pieces offood
for
other ants
to
help
lift. If
there
arethree
antstotal,
eachindividually
trying
to
lift
adifferent
piece of
food
thatrequirestwo
antsto
lift,
thennothing
will getdone. A way
mustbe found
for 1
or2 (not
all) ant(s) to
abandonhis food
andhelp
adifferent
ant.This is extremely dif
ficult
since allthe
antsarerunning
the
same program.1.2
Terminology
In
this
document,
there
willbe many
referencesto the3
types
ofprograms.To
simplify understanding,
these
willbe
referredto
asthe
geneticprogram, the
antprograms,andthe
display
program.The
genetic programis
theprogramwhich evolves theantprograms.The
display
program,
orinterface
programis
aseparateexecutablethatcanvisually
executeone ant program.
All
statementsin
the
ant programswillbe
typed
in
allCAPS. Statements
beginning
with
IF
willbe
conditions.Tabs
willbe
usedtoshow therelationship between
conditions andtheir
clauses.The if
and else clausestatementblocks
for
thecondition willbe
atleast
1
taboutfrom
thecondition statement.All
parametersto theprogram willbe in ITALIC CAPS. These
parameters are alltreatedas
integer defines for
all ofthesourcecode.They
determine how
thegenetic programwill
run,
and are providedto
the programin
a paramsfile.
An iteration is defined
as one round ofcrossover,
mutation, andfitness
evaluation.Every
iteration,
2
newant programsare producedby
thegeneticprogram.A
turnis defined
asevery
antexecuting
theant programoncein
afitness
evaluation.The
fitness
algorithm will runfor hundreds
ofturns toevaluatetheant program.Pheromones
area scentthatantscan releasetomarkan area or a path.The
same2
Genetic
Algorithms
2.1
Definition
Genetic
Algorithms
are a means ofsolving
problems withoutexplicitly stating
the
solution.This is done using
theidea
ofSurvival
oftheFittest.
Good
solutions are combined with eachother, to
hopefully
create abetter
solution.The Genetic Algorithm
canbe broken
up into 5
different
steps as shownin
the
following
pseudocode:Initial Population
Fitness
Evaluation
WHILE (best
solution notfound)
{
Tournament
Selection
Crossover
Mutation
Fitness Evaluation
When
the
Genetic Algorithm is
first
executed,anInitial Population
of solutionsis
created.
These
arerandomsolutionsto
the
problem,and most ofthemwillnotbe
good.Some
willevendo
theopposite ofthe
desired
effect.Fitness Evaluation
referstotesting
the
solution'sability
to
solve a problem.This
is
done
sothatdecisions
canbe
made on whether one solutionis better
than
another.Solutions
thatcanpartially
solvea problem are givenabetter fitness
than those thatdon't.
In
the
Tournament
Selection
stage,a small number of solutions are pickedfrom
the
populationofsolutions.Based
onthe
fitness
ofthesesolutions thebest
two
are chosenfor
Crossover. These best
two
solutions arethe
parents.The Crossover
operationtakes the two
parentsfrom
the tournament selection,
and combinesthem tocreatetwo
newsolutions, the
children.The
goalis
that
thecrossover will produce atleast
one childthat
is better
thanboth
ofthe
parent solutions.The
two
new children
will replacethe twoworstsolutionsfrom
the
Tournament
Selection. This
willkeep
the populationthesame size.The Mutation
operation makesasmallchangeto one,
both,
or none ofthe
children randomly.The
changeis done for
two
reasons.First,
it
might create abetter
solutionthat couldn'teasily be found
by
performing
acrossoveroperation.The
other,
and moreimpor
tantreason,
is
that
it keeps
afresh supply
of genetic materialin
the
population.If
thecross over operationis done
to the
populationlong
enough,
withoutmutation, then
eventually
every
solutionin
the
populationwillbe identical.
A
specialtype
ofMutation
is
Greedy
Mutation. In
this case,
if
the
mutated childis
not abetter
solutionthan the
unmutatedchild,
thenthe
mutationis
undone.Because greedy
mutationdoes
notnegatively
affectthepopulation, the
rate of mutationcanbe increased
whenusing
Greedy
Mutation.
In
the
pseudo code onthe
previouspage,
theGenetic Algorithm
willrun untilthebest
solutionis found.
This is
not alwaysthe
case.Many
times theGenetic
Algorithm
willfind
avery
goodsolution,
but
notthebest
one.Also,
if
theGenetic Algorithm is
runfor
along
enough period oftime,
all ofthestringsin
thepopulation willlook
thesame.To
somedegree
this
effect canbe
countered withMutation
oralarger
Population,
but
notcom pletely.The
number of stringsin
the
population willhave
aneffectonhow
fast
theGenetic
Algorithm
canfind
a solution.With
a smallpopulation,
agood solutionwillbe
found
quickly.With
alarge
population,
it
willtake
longer
to
find
agoodsolution,but
it
willhave
abetter
chanceoffinding
agreat,
orthe
best,
solution.The
reasonfor
thisis
simple.To quickly find
asolution,
thegenetic program needsto
usethe
best
stringsin
thepopulationtocreate abetter
solution.The best
stringsare probably
the
children ofa previouscrossover.If
thepopulationis
smaller,
thenthesechildren willbe
reusedto
make more stringsmorequickly.The
problemis
thatwithasmall population
the
Genetic Algorithm
takesa narrow minded approachtosolving
theproblem.Instead
ofhaving
many dissimilar
solutionsthathave
a goodfitness,
thereareonly
acoupleof solutions with a good
fitness,
andthey
arevery
similar.The Genetic Algorithm
willquickly find
thebest
solutionit
cangetwithwhatit has
towork with.Unfortunately,
thereis
not muchtoworkwith,
andthesolution will notbe
great.2.2
Example
A
simple example ofaGenetic Algorithm is
to
createastring
ofall1
's. The initial
population will
be
six random solutions(strings)
oflength
5,
whereeachelementofthestring is
a1
or0. The
fitness
willbe
thenumberofl's in
the
string.The
worstfitness is
0,
andthebest
fitness is 5.
String
Fitness
11010 3
01010 2
1 1000 2
01011 3
10101 3
01000 1
After
the
fitness
oftheinitial
populationis
known,
a smallgroup
ofstrings areselected
from
thepopulation,
andthe twowiththebest
fitnesses
are chosen.Say
thatsolu tion1, 2,
5,
and6
arechosen.The best
twoare1
and5,
both
withafitness
of3.
In
Genetic
Algorithms,
themostcommonform
of crossoveris
topick a crossoverpoint
in
theparentstrings,
and splittheparentstring into
two
parts.Say
for
this example,
thecrossoverpointis
afterthesecond element.Then,
thefirst
childis
the
first half
of parent1
andthesecondhalf
of parent2,
andthesecondchildis
the
first half
of parent2
andtheFitness
PARENT
1
110
10
3
PARENT
2
10
10 1
3
CHILD
1
1110
1
4
CHILD
2
10
0 10
2
One
ofthe
childrenhas
abetter
fitness
than
both
parents,
andoneis
worse.If
mutation
wasbeing
performed, then the
nextstep
wouldbe
to
possibly
toggle
one ofthenumbersin
each child.Since
this
is
a simple problemtosolve,
assumethatneitherchildis
mutated.Now
the two
children replacethe two
worstsolutionsfrom
the
Tournament Selec
tion.Child 1
replacesthe
solutionin
position2,
and child2
replacesposition6.
Now,
the
averagefitness
of all solutionshas
risen,
andthe
valueofthe
best
solutionin
the
populationhas
also risen.The
perfect solution of5 l's
canbe found
withjust
onemoreTournament
Selection.
2.3
Encoding
The
methodby
whichthe
solutions are encodedinto
stringsis very important. In
theabove
example, the
simpledirect encoding
ofthe
stringswillwork.In
otherexamples,
it
willnot.Consider
the
Travelling
Salesman Problem. In
this problem, the
goalis
tofind
theshortest
distance
between N
cities,
andback home. The fitness
wouldbe
thedistance
ofthe
path,
withtheshortest pathbeing
best. This
cannotbe simply
encoded astheorderin
which thecities aretravelled.Example:
PARENT1
12
345
PARENT
2
5 4 3 2 1
CHILD 1
12
3 2 1
CHILD 2
5 4 3 4 5
With
straight orderencoding,
normal crossover cannotbe
performed.The
crossoverwill
have
to
have built in
checkstopreventcitiesfrom
being
repeatedin
the
list. If
thisis
done,
then thesimplicity
ofthe
Genetic Algorithm
is lost.
Another
methodis
to
usethe
city
numbers as slots asbelow.
The city
tour:
14 2
6 5
3
is
stored as:13 13 2 1
City
1 selected. 1st free slotCity
4 selected. 3rd free slotCity
2 selected. 1st free slotCity
6 selected. 3rd free slotCity
5 selected. 2nd free slotIn
the encoding,
each number representsthe
city
numberofthecity
minusthe
number
of citiesbefore
thatnumberthathave
already been
visited.X
represents a visited city.O
represents anunvisited city.0 0 0 0 0 0 X o o o o o X O 0 X o o x x o x o o X X 0 X 0 X X X 0 X X X
X X X X X X
City
3 selected. 1st free slot.This encoding has
theproperty
thatelementX
in
astring
oflength N
willbe
less
than
or equaltoN-X+l. If
twoparentsstringshave
this property,
thenif
thestandard cross overis
used,
both
children strings will alsohave
this
property.This
meansthat thechildren strings are valid solutions.Also,
thelast
positionin
thestring is
always1.
This
meansthatthe
string is 1
numbersmallerthan thenumber of cities.This
decreases
thesearch spacefor
the
Genetic Algorithm.
This encoding
method also makes mutation easier.Only
onepositionneedsto
be
changedrandomly
tomutatethepath.In
the
previousexample,
twocities wouldhave
tohave
their
position switched.This encoding
methodhas
onemajorflaw. The
mostimportant
attributeofapossible
solutionis
the
orderin
whichthecitiesaretravelled.A
goodsolutionmay only have 2
out of10
citiesin
thewrong
order.With
theslotencoding,
theentirecity
order canbe lost
during
a crossover.The
encoding:13 13 2 1
is
thecity
tour:14 2 6 5 3
while encoding:
5 3 13 2 1
is
thecity
tour:5 3 16 4 2
There
are6 city
adjacenciesin
a6 city
tour.Although only
one number changedin
the tourencoding,
4
ofthe6 city
adjacencies where changed:5-3
and4-2
stayedthesame.Thus,
thisis
also abad
method.A
better,
but
more complicatedway
tostorethe touris
todirectly
storethe
city
adjacency list. The
numberat positionX in
thestring
representsthe
city
that
X
connects to.Thus,
the
tour:14
2 6 5 3
is
storedas:4
6 12 3 5
andthe tour:
14
6 2 5 3
In
these two
tours,
only
the
6
and2
arereversed,
andonly 3
out ofthe
6
adjacenciesare
different. The
standard crossover operation will not work withthis
example,for
the
same reasonit
doesn't
work withthe
straightcity list.
A
Greedy
Crossover Operation
will workhere. All
elementsfor both
encodingsthatare
the
same are movedinto both
childrenfrom
the
parents.Thus,
both
children will startas:
4 X 1 X 3 X. The
first
X in
slot2
is filled
in for Child 1
by
taking
slot2
from Parent 1.
The
first
X in
slot2 is
filled
in
for Child
2
by
taking
slot1
from Parent. The
secondX
slotis filled
in
for
each childby
the
opposite parent.This is
difficult,
because
the
crossover operation must make sure no numbers are repeated
in
eachchild,
whilealsotrying
to
keep
eachchild
different.
PARENT 1:
46 123
5
PARENT 2:
4 5 16 3 2
CHILD 1:
45 123 6
CHILD 2:
4 6 12 3 5
When
a conflictarises,
it is best
to take
anumberfrom
oneparent,
before picking
arandom
city
numberthathas
notbeen
used.Mutation
for
thismethod requirestwo
numbersto
be
switched.The Mutation
canbe
improved
by
allowing only
positionsthat the
parentsdidn't
agree ontobe
mutated.This
is
a goodencoding
method,
but
stillhas
oneminorflaw.
The city
tour:
12
3 4 5 6
is
encoded as:12
3 4 5 6
while
the
tour:6 5 4 3 2 1
is
encoded as:6
5 4 3 2 1
Both
ofthese
toursareidentical,
but
oneis in
the
opposite orderofthe
other.Thus,
the
Greedy
Crossover
willseenosimilaritiesin
theseidentical
solutions.A better
methodof
encoding
wouldstorecity
adjacenciesin
both
directions,
either astwo
city
lists,
or a2
dimensional adjacency bit
map.Either
methodwould make crossoverextremely difficult.
The
Travelling
Salesman Problem
showsthatselection ofanencoding
method,
andcrossovermethod can
be
criticaltosolving
theproblem.3
Genetic
Programming
3.1
Definition
Genetic
Programming
is simply Genetic Algorithms
wherethesolutionstrings are replaced with variablelength
programs.The
goalis
tofind
aprogramthatcan solve adesired
problem.The
programis
evaluatedfor fitness
by
executing
theprogram.Because
the
populationin
aGenetic Program
is
variablelength
solutions,
it
is
best
to
storethe
solutionsin
atree
format. A
tree
structurealso works wellwithstoring
and executing
programs,
especially
those
withconditions.For
this reason,
LISP
is
a goodlanguage
for Genetic Programming. LISP
stores alldata in
tree structures,
and can executethetree
data
structureif it
containsprograminstructions.
The Language
thatthe
solutions use canbe
avariety
oftypes.The
simplestlan
guageis
mathematics.In
this situation,
theleaf
nodesofthe treearenumbers orvariables,andthenon-leaf nodes are operators: +,-,*,/,%...
An
examplemathematicaltreewouldbe:
The
nextlevel
ofGenetic
Programming
Languages
arethose
languages
thathave
thesame statements as thelanguage
being
programmedin. This
wouldinclude
assignments,
conditionals,
andloop
constructs.This
mightalsoinclude
callsto
special prewrittenfunctions. This
typeofGenetic Program is
the most suitableto
LISP.
In
thefinal language type,
nosimilarities existbetween
conventionalprogramming
language
andtheGenetic
Programming
Language. This
couldbe implemented in LISP
as allfunction
calls.It
could alsobe implemented in
C,
orany
other conventionallanguage,
by
writing
anintepreter. The intepreter
wouldtake
theprogramtree
andtraverse the
tree,
acting
on eachstatement asit
reachesit.
Genetic
Programming
follows
the same steps asGenetic
Algorithms,
but
the
steps act alittle differently.
or an operator
like
+that
requiresparameters,
then therewillbe
adifference between leaf
nodes and non-leaf nodes.When creating
theinitial
population,
care mustbe
takento
create alegal
program.In
the
Fitness Evaluation
stage, the
programmustbe
executedtodetermine how
well
it
works.Depending
onthe application, the
programmay be
executedmorethanonceto
determine fitness.
Say
that the
Genetic
Problem
is
being
usedto
simulatethefood
collection
process of ants.The
goalis
to
have
the
ant collect all ofthe
food
within100
turns.The
program solutiondetermines
how
the
ant will actfor
eachofthe
100
turns.
The
pro gram mustbe
executed100
times to
determine fitness. If
there
are multiple antsin
the
problem,
then the
program mustbe
executed100
times
for
each ant.While
determining
thefitness,
the
Genetic
Program
mustkeep
track
ofthe
state of each ant and changesto the
pseudo environment
that
they
arein.
Tournament Selection
worksexactly
thesamefor
aGenetic Program
as aGenetic
Algorithm.The Tournament Selection
operationmay look
atthe
same programmany
timesbefore it is
replaced.In
anGenetic
Program,
mostofthe
CPU
timeis
spenttesting
thefit
ness of
the
programs.That is why
thefitness
is
calculated after eachprogramis
made,
not whenthefitness is
neededin Tournament Selection.
For
Crossover,
a crossover nodein
each parent programtree
mustbe
selected.Unlike Genetic
Algorithms,
the
crossover pointsin both
parentsdo
nothave
to
be
the same,
and
probably
cannotbe. It is
likely
that theparents willhave
adifferent
number ofnodes,
and
have
adifferent
configuration.To
be
truly
random,
thecrossover node musthave
anequal chance ofbeing
any
nodein
the
parenttree.
This
wouldbe done
by finding
the
number of nodesin
the treeN,
picking
arandomnumberR
from 1
toN,
andthendoing
an preordertraversalofthe
tree throughR-l
nodes.A
truly
randomcrossover node selectionmay
notbe
desired.
Maybe,
towards the
end of
the
Genetic
Program,
only
minorchangesto the
parent programs aredesired. This
can
be done
by
making it
morelikely
thataleaf
node oftheparenttree
willbe
selected asthecrossover node.
This
way,only
one node changesfrom
parentto
child.On
the
otherhand,
to
makelarge
changesto the
program,makeit
morelikely
a non-leaf nodewillbe
selected asthecrossover node.Usually,
in
aGenetic
Program,
theleaf
nodes and non-leaf nodes are notinter
changeable.
As
in
the
mathematicalexample, theleaf
nodes were operands andthe
non-leaf nodes wereoperators.This property
mustbe
preservedduring
Mutation. A leaf
node canonly be
mutatedinto
anotherlegal
leaf
node,
and a non-leaf node canonly be
mutatedinto
alegal
non-leafnode.3.2
Example
One
ofthemostbasic
Genetic
Programming
examplesis
the
food
collection problem. In
this problem,
theprogram must guide an antaround anenvironmentto
collectfood.
The
solution willbe
composedonstatementsthat
will movethe
ant around and searchfor
food. The
ant willcontinually
executetheprogram eachturn
until all ofthe
food
is
found.
Michael LaLena Page
9
Teamwork in Genetic
Assume
that the
programs are storedin
abinary
tree
format. No
node canhave 1
child,
just 0
or2. In
this problem, the
leaf
and non-leaf statementswillbe different. The leaf
statements will
be
operations:TURN LEFT
TURN RIGHTMOVE FORWARD
MOVE RANDOM DIRECTION PICK UP FOOD
DROP FOOD
NO OPERATION
These
operations will allowthe
anttomove around andpickup
anddrop
food. The
non-leaf statements will
be
conditionals.In
acondition, the
left
statementis
executedif
the
condition
is
true,
andthe
rightstatementis
executedif
the
conditionis false. Possible
non-leaf
statements are:IF FOOD AHEAD THEN
IF FOOD LEFT THEN
IF FOOD RIGHT THEN
IF FOOD HERE THEN
PROC2
The PROC2
statementis
nota condition.Both
children statements of aPROC2
node are executed.
This
exampleis
a programtree.
It
showshow PROC2
statements canbe
useful.If
there
is
food
to the
left,
then three
statements needtobe
executed:TURN LEFT
MOVE FORWARD
PICK UPFOOD
Two PROC2
statements allowthe
singleleft
statement ofthe
IF FOOD LEFT
condition
to
be
turned
into 3
statements.The MOVE
RANDOM
statementsimply
movesthe
antin
arandomdirection
to
simulate a random search
for food.
Usually,
not allofthese
statements wouldbe
usedin
thesameGenetic Program. A
perfect solution couldprobably be
found
just using half
ofthe
statementslisted. Although
the
solution wouldbe
slightly
morecomplicated,
because
ofthe
decrease
in
thenumberofpossible
statements, the
search spacefor
the
perfect program willbe
alot
smaller.There
fore,
the
Genetic Program
shouldfind
a solutionfaster.
Obviously,
whencreating
the
initial
population,
statementslike IF FOOD HERE
cannotbe leaf
nodes ofthe tree.The Genetic Program
must make surethat
all ofthe
pro gramsin
the
initial
populationarelegal
programs.The
programsin
the
initial
population willalsovary in
size.One
method ofcreating
the
initial
populationis
torecursively
pick a statementfrom
the
list
of possiblestatements,
and make
that the
nextstatement.If
the
statementis
a non-leafstatement,
thenrecursively
createchildrennodes
for
thatstatement.If
there
are morethan
twiceasmany leaf
state ments asnonleaf
statements, then this
methodwillwork.Otherwise,
theprograms could startbecoming infinitely
big.
If
this
is
thecase,
then thestatementselectionneedstobe
weightedin favor
ofleaf
statements.
How
muchtheselection processfavors leaf
nodes will affectthe
average size ofthe
programtrees.If
possible,
theselection process couldbe
weightedin
theotherdirec
tion tocreatebigger
trees.
The
programtreesmustbe
executedtoevaluatethemfor
fitness.
If
the
Genetic Pro
gram
is
not writtenin
LISP,
then theGenetic Program
musthave
anintepreter
toexecutethe
program.The
stepstoevaluatethe
programare:Set
Up
the Environment
to
runthe
simulationin.
WHILE (Goal Not
Achieved)
AND (Not Max
Turns)
{
Interpret
programonce.;
Michael LaLena Page 1 1
Teamwork in Genetic
In
this example, to
setup
the environment, the
pieces offood
are placedattheirstartpositions,
andthe
antis
placed atits
start position.If
the
environmentis
storedas a2-dimensional
array,
thenthis
step
is done
by
simply copying
thedata
from
amasterarray
into
the
temporary
one.The food
and ants cannotbe
placedrandomly
onthemap.Doing
thiscould causethe
fitness
ofa programto
change eachtimeit is
executed.A
morestable environmentis
neededto
find
the
best
solution.Depending
onthe application,it may
alsobe desirable
to
start withthe
same random number generator seedevery
timeaprogramis
executed.This intepreter
will run untiltheanthas found
allofthefood. This is
the
goal.The
intepreter
must also maketheassumptionthattheprogrammightnot gettheantto
find
allof
the
food,
no matterhow
muchtime the
antis
given.If
theprogramdoes
notcontaintheMOVE FORWARD
statement,
orthePICK UP FOOD
statement,
thenthe
antcannotgetany food. For
thisreason,
theprogramis usually only
executeda setnumberoftimes,
or turns.The
intepreter
willrecursively
traverse theprogramtree to
executeit.
Basically,
there
aretwomainactionsfor
the
intepreter:
void
statement(node)
{
if
(leafNode(node))
{
interp(node)
}
else
{
if (node.type
==PROC2)
{
statement(node.left)
statement(node.right)
}
else
{
if
(eval(node))
{
}
else{
}
statement(node.left)
The
codefor
the
intepreter is very
simple.Two
mainfunctions
needto
be
writtenfor
interpreting
eachstatement.interp()
will execute oneleaf
statement, andeval()
willevaluate one non-leaf statement.
Basically,
both
ofthese
function
willbe
onelarge
case statementfor
eachnodetype.
The
example programtree
from
above canbe
writtenas:IF
FOOD HERE
MOVE FORWARD
ELSE*
IF FOOD LEFT
PROC2
TURN LEFT PROC2
MOVE FORWARD PICK UP FOOD ELSE
MOVE RANDOM
Another
sampleprogramcouldlook like:
IF FOOD RIGHT PROC2
PROC2
TURN RIGHT MOVE FORWARD PICKUP FOOD
ELSE
IF FOOD LEFT PROC2
TURN RIGHT PROC2
MOVE RANDOM PICKUP FOOD ELSE
TURN LEFT
Say
that these twoprograms aretheparentsofa crossover operation.The
* marksthe
crossovernodein
eachprogram,andthe
-'sarethenodesthatarechildren ofthe
crossovernode.
The
crossover operation wouldproductthe
following
children programs:IF FOOD HERE
MOVE FORWARD ELSE
* PROC2
TURN RIGHT PROC2
MOVERANDOM PICK UP FOOD
and
IF FOOD RIGHT PROC2
PROC2
TURN RIGHT MOVE FORWARD PICK UP FOOD
ELSE
IF FOOD LEFT
IFFOOD LEFT PROC2
TURNLEFT PROC2
MOVE FORWARD PICK UP FOOD ELSE
MOVERANDOM ELSE
TURN LEFT
The
first
childprobably has
abad fitness. This
canbe
found
outby
simply
looking
attheprogram.There
is
noreasoning in
theordering
ofthestatements.In
someinstances,
theant would runaway from food.
The
second child program seemstobe
muchbetter. It
gainedtheability
tofind food
to the
left from
thefirst
parentprogram, andtheability
tofind food
to therightfrom
the second parent.Unfortunately,
theant cannot moveif
thereis
notfood
nexttoit. It
does
not execute aMOVE
FORWARD,
unlessit is moving
tofood it knows
about.It does have
aMOVE RANDOM
statement,
but
this
statement can neverbe
executed.The
first IF TURN
LEFT
wouldhave
to
be true,
whilethe
secondIF TURN LEFT
conditionwouldhave
tobe
false. If
thelast
statementwas somekind
ofMOVE
statement, thenthis
wouldbe
a good solution.Changes
tothe
programfrom
mutation mightbe
abletomakethisfix.
A very
good solution wouldlook like
theprogrambelow. PROC2
statementshave
been
removedfor
readability.It
canbe
assumedthatif
two
consecutive statements areonthesametab
level, they
have
ahidden PROC2
statementastheirparent.IF FOOD LEFT TURN LEFT ELSE
IF FOOD RIGHT TURN RIGHT ELSE
PICK UP FOOD IF FOOD AHEAD
MOVE FORWARD PICK UP FOOD ELSE
This
programis
a more concise solutionthan the
childrenofthecrossover operation.
There
aretwo
PROC2
statementsin
this
program.One connecting
theIF FOOD LEFT
and
IF
FOOD AHEAD
statements onthe
first
level,
and oneconnecting
the two
statementsin
the true
clause ofIF FOOD AHEAD.
Note
that the
IF FOOD HERE
statement was notused.If
there
is
food
atthecurrentlocation,
andthere
is
nofood
to the
left
orright,
thenthe
food
is
pickedup
by
the
first PICK
UP FOOD
statement.This
problem canbe improved
by
using
multiple ants.For
this,
each ant will executetheprogram once per
turn,
oneant after another.Each
ant wouldbe changing
the
environment
before
the
next ant ranthe
program.Using
thisfood
collectionexample,
adding
more ants would allow all ofthe
food
tobe found faster.
3.3
Encoding
All
ofthe
Genetic Programs discussed have
storedsolutionsin
binary
trees.This
is
done
to
simplify
the
writing
ofthe
Genetic Program.
An encoding
methodthat
allowed avariable numberofchildrenwould remove theneed
for
nestedPROC2
statements.One
PROC3
orPROC4
statement couldbe
usedinstead
toconnect3
or4
childrenrespectively.Non-binary
treeswouldalso allowfor
conditionsthathad
morethat tworesults,
and also case statements.While
these
are useful constructsin
arealprogramming
language, they
canbe
simulated withbinary
tree
programsto
achievethesame effect.Under
the
belief
thatsimpler
is
better,
this
encoding discussion
willbe limited
to
binary
trees.Since
the
encoding
methodis limited
to
binary
trees,
all ofthe
encoding
methods willbe limited
to
statement orinstruction
set selection.When selecting
the
instruction
set,
the
less
numberofdifferent
statementsusedthe
better,
aslong
asenoughdifferent
state ments are availableto solvetheproblem.The
simplest exampleofaGenetic Program
is
themathematical program.Here,
there
areonly 5
mainoperators:+,
,/,
*,
%. Other
more complex operators couldbe
added,
but
they
probably
wouldn'tbe
necessary.Assuming
thatnegativenumberoperandsareallowed,
the- operatoris
notnecessary
tosolvethe
problem.Also,
assuming
realnumbers areused,/
is
not needed.Now,
the
operatorsarelimited
to+,
*,
and%,
andthe
operands are signed real numbers. This
cutsthe
numberof operatorsby
40%,
whichwillhave
asimilar affectonthe
size ofthesearch space.Division
andMod
areboth
protected operations.This
meansthat
if
the
second operand
is
0,
the
Genetic Program
will notallowa mod ordivide
by
zero.The
result of a mod ordiv
by
zerowillbe 0. Since
oneoftheseprotectedoperations, the
divide,
is
one oftheunnecessary
statements, thenthis
also simplifiesthe
Genetic Program.
In
the
ant program exampleabove,
aNO
OPERATION
statement waslisted.
A
no-op
statement mightbe desired in
some cases.If
the
antonly
wantstoact onthe
if
clause of astatement,
thenthe
no-op
couldbe
theelse clause.But,
a specialNO
OPERATION
statement
is
not needed.In
this example,
PICK UP
FOOD
is
also ano-op
statement.When
aop
statementis
neededin
anif
or elseclause,
PICK
UP FOOD
canbe
used.It
willnotturnor move theant.
Even if it
is
already known
that there
is
nofood
topickup,
thePICK
UP
FOOD
statement canbe
executed.It
willjust
have
no effect.The IF FOOD HERE
statementis
also notnecessary.The
antcould executeaPICK
UP FOOD
statementevery
time
it
moved,
withoutlooking
to
seeif
food
wasthere.The IF FOOD LEFT
andIF FOOD RIGHT
statements couldbe
removed.The
antcouldturn
in
that
direction,
andthen
execute aIF FOOD AHEAD instead.
Technically,
TURN RIGHT
couldbe
replacedwiththreeconsecutiveTURN
LEFT'S,
but
this
would notbe
a solutionthat
wasfound
randomly.Thus,
6
statementstakethe
place of12,
cutting down
thecomplexity
ofthesearchspace.
More important
thanselecting
aninstruction
setis
deciding
how
conditionstatementswillwork.
Will
the
condition statementshave
an else clause?Will
theinverse
ofcondition
statementsbe
allowed?Will
theconditionshave
sideeffects?Conditions do
not needtohave
anelse clause.To
keep
theprogramin
abinary
tree,
both
children ofthecondition nodeswouldbe
executedif
thecondition wastrue.In very
simple
problems,
this mightbe desired.
Condition
statements could alsohave
theirinverses. If
theconditionIF FOOD
AHEAD
is in
theinstruction
set, thenIF NOT FOOD AHEAD
could alsobe
added.If
theconditions
have
elseclauses,
then thisis
notnecessary.The inverse
ofthecondition existsalready
by
switching
theif
andelse clausesofthe
condition.Adding
side effectstoa conditionwillgreatly improve
theability
ofthe
Genetic
Program
tofind
asolutionto theproblem.A
side effectis
anactionthatis done before
theif
orelse clause ofthecondition.The
action canbe done before
or afterthe
conditionis
evaluated,
ortheconditioncanbe
the whethertheactionwassuccessful.Example
sideeffects are:Without
sideeffectsWith
side effectsIF FOOD HERE IF PICK UP FOOD
PICK UP FOOD MOVE TO NEST
MOVE TO NEST
IF NEXT TO FOOD IF MOVE TO
ADJACENT
FOODMOVE TO FOOD PICK UP
FOOD
PICK UP FOOD or
IF PICK UP
ADJACENT
FOODMOVE TO NEST
IF AT NEST IF
DROP
FOOD AT NESTDROP FOOD MOVE
RANDOM
These
side effects willsimplify
the
instruction
set,
andthe
final
solution.Food
willbe
pickedup
anddropped
automatically,
sothese
statements canbe
removedfrom
theinstruction
set.For
the
PICK UP ADJACENT FOOD
example,
theant checksto
seeif it is
next
to
food,
turns toward the
food,
movesto
thefood,
and picksit
up,all as a side effect.The
if
and else clauses can act onwhetherthe
antdid
pickup
thefood
or not.These
side effects make certain assumptions.In
these cases,
they
assumethat
if
the
ant
finds
food,
it
wantstopickit
up.If
there
is
abetter
solution wherethe
antdoes
not pickup
the
food
whenit
finds
it,
aGenetic Program using
these
side effects would notbe
ableto
find
it.
This
canbe
shownin
the
following
multipleantfood
collectionproblem,
wherethe
food
is
setup in
piles,
anttheants arecarrying it back
to
thenest.Each
ant cancarry only
one piece of
food.
IF
CARRYING
FOODTHEN
MOVE TO NEST ELSEIF NEXT TO FOOD OR FOOD HERE THEN IF ANOTHER ANT HERE THEN
PICK UP FOOD MOVE TO NEST ELSE
CALL FOR ANOTHER ANT ELSE
IF I HEAR ANOTHER ANTS CALL THEN MOVE TOWARD CALL
ELSE
MOVE RANDOM
There
are several stepstothis
problem.1)
Move
arounduntil one antfinds
a pieceoffood.
2)
After
thefirst
antfinds
food,
he
calls otherants,
and all antsmovetoward that
ant.3)
If
otherants alsofind food
onthe
way
tothe
first
ant,
they
alsocallants.Ants
are attracted to theclosest call.3)
When
an ant meets acalling
ant, the
calling
ant picksup
food
andbrings
it
to the
nest4)
If
the
antthat
metthe
calling
antis
nextto
food
(likely
sincethe
food is
in
piles), then
thatant startscalling
otherants.In
thisexample,
antsdo
notpickup
food immediately.
The
antsdo
not wantto
for
get where
the
pile offood
is,
sothey
waitfor
another antto
markthe
spot.Then, they
take
a pieceof
food
to the
nest.If
the
antautomatically
pickedup food
and startedmoving
to
thenest withit,
thissolution would notexist.Perhaps,
no solution as good asthis
one couldbe found.
Michael LaLena
Page
17Teamwork in Genetic
Another important
part ofthis
programis
thesecondMOVE TO
NEST,
afterthePICK UP FOOD. If
this
statement were notthere,
thenboth
ants wouldleave
withfood.
First,
anant would answerthe
call.When
thatantarrived, theantswouldseeeachother, andboth
would pickup
food.
On
the
nextturn,
both
wouldseethat
they
have
food,
and4
Schemata
4.1
Partial
Solutions
Simply
put,
a schema(plural: schemata) is
a partial solutionto
a genetic problem.The
solutionis
encodedin
astring,
andthe
parts ofthe
string
that
contributetoward
solving
the
problem are schemata.In
orderto
solvethe
problem, theseschema mustbe
preservedduring
the
crossover operation.In
the
previousTravelling
Salesman
Problem,
the
schemata wouldbe
asectionofthe
shortest path.In
the
encoding
discussion
ofthe
Travelling
Salesman
Problem,
it
wasshown
that
certainencoding
methods preserved parts oftheparent stringsbetter
thanothers.
The
reasonthis
wasimportant
is
that
it
also allowedtheschematatobe
preservedfrom
parentto
child.For
example,
say
theshortesttouris:
123456789
and
the
parent strings are:23689
1457
and
674318295
In
thefirst
parent,
theschemata are2-3, 8-9,
and4-5. In
the
secondparent,
thereis
one
three-city
schema:5-6-7,
which wraps aroundtheend ofthe
string.Also,
4-3
canbe
considered a goodschema,
if
theencoding
methodcanrecognize abackwards
link. The
encoding
and crossover methods should allow asmany
ofthese
schematato
be
passedto thechildrenaspossible.Four encoding
methods werediscussed for
theTravelling
Salesman Problem. The
first
wasadirect encoding
ofthe
city
numbers.After performing
acrossover,
only
onecity
adjacency
willbe
separatedin
eachparent,
so at most one schemata willbe
disturbed.
How
ever, the
childwillmostlikely
notbe
alegal
solution.Some city
numbers willbe
repeated and others willbe
missing.Correcting
thiswilldisrupt many
more schemata.The
secondencoding
methodwasthe
free
slot method.Instead
ofputting
the
city
number
in
the string,
thenumber of unusedcitiesbefore
the
nextcity is
putin
the
string.This
method removedthespecial casechecking for
the
crossoveroperation,
but it
wasshown
that
asingle crossover coulddestroy
all schematain
thestring.The
othertwoencoding
methodsstoredcity
adjacencies(single
andbi-directional),
anduseda
greedy
crossover.The bi-directional adjacency list
recognizestwice
asmany
schemataas
the
singleadjacency
method.Both
methodsfor
both
children will preserve all schematathat
existin both
parents.Most
ofthe
other schemata willbe
preservedin
atleast
one of
the
children.Michael LaLena
Page 19
Teamwork in Genetic
4.2
Schemata in Genetic
Programming
In Genetic
Programming,
theschemata are portions ofthe program,
instead
ofasubstring
ofthe
solution.This
partial solutionis
aseries of statementsthatsolve part ofthe problem.For
the
antproblem,
some examples wouldbe:
IF FOOD HERE
PICK UP FOOD
IF FOOD LEFT TURN LEFT MOVE FORWARD PICK UP FOOD
The
schemata can evenbe less
complicatedthan
this.In
thesecondexample, theand
does
not needtopickup
thefood for it
to
be
a schema.Seeing
thefood
to
theleft
andthen
turning
left is
also a schema.The PICK UP FOOD
statementaloneis
aschema.The
inclusion
ofthis
statementin
the program,
whetherit
eversuccessfully
picksup food
ornot,
makes
the
programbetter
than
other programs withoutthisstatement.If
theparentsdo
nothave
thePICK UP FOOD
statement,
thenwithoutmutation, thechildren will neverbe
abletosolvetheproblem.
5
Search
Space
5.1
Searching
Genetic Algorithms
& Programs
searchfor
a solutionto the
problem.The
searchspace where
they
look
for
the
solutionis
the
set of all possible stringsorprograms.The
searching analogy
canbest be
envisionedby having
every
solutionin
the
search space graphedthree-dimensionally,
wherethe
Z
axiswasthefitness
ofthesolution at point(X,Y).
Assuming
that
good solutions were near greatsolutions,
it
wouldlook like
atopography
withhills
and valleys.The hills
wouldrepresentthecollections of goodsolutions,
andthe
valleys would
be
bad
solutions5.2
Blind
Blind
searching
refersto
searching for
a solution without regardfor
theresults ofprevious attempts at searching.
The
two
mostbasic forms
ofblind searching
are exhaustiveand random.
In
an exhaustivesearch,
every
element ofthesetis
tested to
seeif it is
thebest.
In
theTravelling
Salesman
Problem,
for
a10 city tour,
thisset size wouldbe 10!
=3628800.
This
is
the
amountofdifferent
possibletours.For
eachofthese3628800
possiblesolutions,
the
search program must add10
numberstogether.
Adding
1 city
to the
tour,
making it
an1 1 city
tour,
willincrease
thesize ofthesetby
1 1
times.It
canbe easily
seenthat this
problem
cangetquickly
out ofhand. A large
tourcouldtake
a computer eons tosolve.Random searching is just
asbad. Based
onhow
goodandbad
solutions aregrouped,
a random searchmay find
a goodsolutionfaster
thanan exhaustivesearch,
but it
willtakejust
aslong
to
find
the
best
solution.This is
thereasonthatGenetic Algorithms
are used.They
try
to
movetoward the
best
solution withinthesearch space.This is done
by building
uponthe
schematathat the
Genetic Algorithm has already found. If
schemata are notpreserved,
thenthis
methodis
reducedto ablind
search.5.3
Hill
Climbing
Assuming
thatonly
one solutionis
thebest,
thenonehill
willhave
ahigher
peakthan
allotherhills. When
the
initial
populationis
created,
it
willbe randomly
scatteredin
the topography.
After many
crossoveroperations,
thepopulation will startto
moveup
thedifferent hills in
thetopography,
asbetter
solutions arefound.
The
goalis
that
some ofthe
solutionswill worktheir
way up
tothe
top
ofthehighest hill.
When
two
solutions are onthe
samehill,
then
they
areapproaching
the
solutionin
the
same way.That
is,
they
willshareschemata,
because
they
areworking
toward the
samegood solution.
When
these two
solutions were usedin
crossover,
it may
create abetter
solution
in
the
same neighborhood.When
twosolutions are not onthe
samehill,
the
result of acrossover
may be
useless.Take
theexampleoftheTravelling
Salesman Problem. In
thisproblemtherecanbe
two
best
solutions.The
shortestpath,andthe
shortest pathin
reverse.If
one nearperfectsolution
in
onedirection
is
combined with anearperfect solutionin
theotherdirection,
most
likely
both
children willhave
avery
poorfitness. When
twonearperfect solutionsonthe
samehill
arecombined,
it
could resultin
finding
thebest
solution.A
smallinitial
populationwillquickly
convergeto
asolution,
but
willprobably
notfind
thebest
solution.The
reasonfor
thisis hill
climbing.If
none oftheinitial
solutionsstart at
the
base
ofthe
hill
withthe
best
solution,then the
Genetic Algorithm
willmay
find
this
hill
at all.All
oftheeffortoftheGenetic Algorithm
willbe
concentratedon asmallpercentageof
the
hills. This best
solution ofthisgroup
ofhills
willbe found
quickly,
but
notthe
best
solution overall.The
numberof perfectsolutionscan also effecttheability
oftheGenetic Algorithm
to
find
aperfectsolution.In
somecoding
methodsfor
theTravelling
Salesman
Problem,
there
may be 2N
perfectsolutions,
whereN
is
thenumberof cities.For
both
directions,
there
areN tours,
depending
on whichofthedifferent N
citiesis
the
first in
the tour.In any
coding
methodthatpreserveslocation in
thelist,
instead
ofadjacencies, theschematafor
each ofthe2N
perfect solutionswillbe completely different.
Hill
Climbing
in Genetic
Programming
is slightly different.
Here,
there
canbe
many
perfectsolutionsthataredifferent,
but
they
can all sharethesame schemata.One
per-fect.solution
mightbe
thesame as another perfectsolution,
but
with an extra no-operation6
Emergent
Behavior
Emergent
Behavior
referstothe
application ofseemingly
simple rules thatlead
to
complex overall
behavior.
Many
examples ofEmergent
Behavior
canbe found in
nature,
such as
the
actions of ants.If
nature can evolve complex actionsfrom
a simple set ofrules,
then
it
makes sensethat
aGenetic
Program
can also evolve a solutionto
a complextaskusing
a couple of simple computerinstructions.
This
Emergent Behavior
may
ormay
not consistof severalindividuals performing
the
same action.Some behaviors
thatare not possiblewithoneindividual may be
possiblewith
many
individuals.
Other behaviors
are possible with oneindividual,
but
canbe
performed
moreefficiently
with many.This
thesis
will exploredifferent food collecting behaviors in food
collection problems. The
basic
problemwillbe
a straightforward
"bring
the
food back
tothe
nest"prob
lem. As
more obstacles are addedto theproblem,
hopefully
theGenetic Program
withthelimited
instruction
set willbe
abletofind
anEmergent Behavior
tosolvetheproblem.Michael LaLena Page
23
Teamwork in Genetic
The
Food Collection Problem
7.1
The Santa
Fe Trail Problem
The
mostbasic form
ofthefood
collection problemis
theSanta Fe Trail
Problem
[Koza93]. This is
a one antproblem.For
this problem,
thegoalis
tocollectall ofthefood
that
is
along
atrail.There may be
gapsin
thetrail, but if
theantloses
the trailandcontinuesforward,
the
trailwillbe
pickedup
again.This is
ashortform
ofthe
Santa Fe Trail
(S=start,
E=End,
x=food, -=gap):SXXXXX-XX--XXX X
X
-XX--XXX
XX X
- X X
x-x--xx E
Assuming
food is
pickedup
automatically, thisproblemcanbe
solved withjust
threestatements:MOVE_FORWARD
TURN_LEFT
IF_NOT_FOOD_AHEAD(withoutan else clause).
The
solutionto theproblemis:
IF_NOT_FOOD_AHEADTHEN TURN_LEFT
IF_NOT_FOOD_AHEADTHEN TURNJLEFT
IF_NOT_FOOD_AHEADTHEN TURNLEFT
IF_NOT_FOOD_AHEADTHEN TURN_LEFT
MOVE_FORWARD
The
solutionis
tosimply
spin around untilfood is
directly
in
front
oftheant,
ortheant
is
facing
the originaldirection,
andthenmoveahead onespace.The best way
to trainantstofind
this solutionis
tohave
the trailbecome increas
ingly
moredifficult
asmorefood is found. Have
thefitness be
theamount offood found.
The
ants withthebetter fitness
arethose thatcanovercome more obstacles.The
obstaclesin
thisproblem are:gap
of1
space,
gap
of2
spaces,
gap
of3
spaces,
turn,
food missing
atturn,
andfood missing before
andatturn.The
selectionofaninstruction
setis
alsoimportant
tofinding
asolution.Most
would assumethat
if
aTURN_LEFT
statement wereincluded in
theinstruction
set,
then therewouldalsobe
aTURN_RIGHT statement,
but it is
unnecessary.It
would notsimplify
become
TURN_RIGHT
statements.Adding
aTURN_RIGHT
statement wouldonly
increase
the
size ofthe
set of possible ant programs thatthe
genetic program mustsearchto
find
asolution.For
the
samereason,
aIF_NOT_FOOD_AHEAD
statementis
desired,
instead
of aIF_FOOD_AHEAD
statement,
since a special actionis only
requiredif food is
notin front
of
the
ant.7.2
The Single Ant
Problem
The Single Ant Food Collection Problem deals
withan antcollecting
food
that
is
set
up in
pilesinstead
ofbeing
laid
outalong
atrail.
Normally,
the
Single Ant Problem
is
solved with severalants,
but it is
notrequired.In
this problem, the
ants mustfind
the
food,
andbring
it back
to
onelocation. This
location
is usually
the
nest wherethe
antsstart.It is
assumedthat the
antsknow how
to
find
the nest,
but do
notknow
wherethefood
is,
evenafterthey
have
seen a pileoffood.
Since
the
searchfor food is
random, the
food
mustbe
placedin
piles,
sothat
theentire problem
is
notrandom.Once
thefood is
found,
theantscanusepheromonestomarkthepile of
food,
andthetrail
back
to thenest.The
ants canthenfollow
the trail
from
the
nest
to the
food. Other
ants can stumble acrossthe trail andfollow