The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher.
powered by NetLogo
view/download model file: MostDifferent.nlogo
This NetLogo simulation is aimed at stimulating some thought about evolutionary processes.
The basic idea is this: there are a bunch of agents, each with a "genome" (a string of bits). At each time step, each agent looks at its (nearby) neighbors and selects one to mate with. The selection algorithm is to choose the neighbor who is most different (hamming distance of genomes) from you. Reproduction is replacement of self by a single offspring, whose genome is the result of a crossover with the mate (a crossover point is selected; the new genome results from one parent up to the crossover point, and the other parent from there on -- which parent selected at random). The crossover point is selected from a normal distribution with mean genome-size / 2, and standard deviation genome-size / 6. There is also the possibility of mutation of a "gene" (a bit in the genome).
Each pass through the GO function represents one time step.
The histogram shows the number of agents having a given range of genomes. The genomes are represented as the binary number corresponding to the genome bit string.
globals [ timestep ; counts how much time has passed ] turtles-own [ genome genomei genomef ] to setup let step 0 clear-output ca set timestep 0 crt num-agents [ set genomei 0 set genome list (random 2) (random 2) repeat genome-size - 2 [ set genome lput (random 2) genome ] ; print genome set step 0 repeat genome-size [ ifelse ( item step genome = 0 ) [ set genomei genomei * 2 ] [ set genomei 1 + genomei * 2] set step step + 1 ] set genomef genomei / (2 ^ genome-size) set color round(139.0 * genomef) setxy (random-float world-width) (random-float world-height) ; randomize turtle locations ] setup-plot plot-genomes end to go if moving [ move ] mate set timestep timestep + 1 plot-genomes end to move ask turtles [ rt random-float 30 - random-float 30 fd 2 ] end to mate let difference 0 let biggest-difference 0 let most-different 0 let me 0 let friends [] let step 0 let cross-over1 0 let cross-over2 0 without-interruption [ ask turtles [ set biggest-difference 0 set me self set friends [] ifelse region [ ask turtles in-radius region-size [ set friends lput self friends ] ] [ ask other turtles [ set friends lput self friends ] ] foreach friends [ set difference 0 set step 0 repeat genome-size [ if ( item step [genome] of ? != item step [genome] of me ) [ set difference difference + 1 ] set step step + 1 ] if ( difference > biggest-difference ) [ set biggest-difference difference set most-different ? ] ] set step 0 ; set cross-over1 random (genome-size / 3.0) + round(genome-size / 3.0) ifelse (fixed) [ set cross-over1 crossover-location ] [ ifelse (uniform) [ set cross-over1 random genome-size ] [ set cross-over1 random-normal (genome-size / 2.0) (genome-size / 6.0) ] ] set cross-over2 random 2 repeat genome-size [ ifelse (cross-over2 = 0) [ if (step >= cross-over1) [set genome replace-item step genome item step [genome] of most-different] ] [ if (step < cross-over1) [set genome replace-item step genome item step [genome] of most-different] ] if (mutate and ((random one-over-mutation-rate) = 0)) [set genome replace-item step genome (1 - (item step genome))] ; [ set genome-of most-different replace-item step genome-of most-different item step genome ; ] set step step + 1 ] set step 0 set genomei 0 repeat genome-size [ ifelse ( item step genome = 0 ) [ set genomei genomei * 2 ] [ set genomei 1 + genomei * 2] set step step + 1 ] set genomef genomei / (2 ^ genome-size) set color round(139.0 * genomef) ] ] end to plot-genomes set-current-plot "Genomes" set-current-plot-pen "genomes" if full-plot [ ask turtles [ plotxy timestep genomef ] ] set-current-plot "Genome-distribution" set-current-plot-pen "agents" histogram [genomei] of turtles end to setup-plot set-current-plot "Genomes" set-plot-x-range 0 400 set-plot-y-range 0 1.0 set-current-plot "Genome-distribution" set-plot-x-range 0 2 ^ genome-size set-plot-y-range 0 round ((count turtles) / 5) set-histogram-num-bars 100 end