WHAT IS IT?
-----------
This project is a model of a classic example of natural
selection- the peppered moths of Manchester, England. The
peppered moths use their coloration as camouflage from the
birds that would like to eat them. (Note that in this model,
the birds act invisibly.) Light-colored moths blended in
better against the white bark of the trees they rested on-
hence the lighter moths were more numerous than the darker
ones.

Due to the intense pollution caused by the Industrial
Revolution, though, the trees became discolored with soot.
Eventually, the light-colored moths stuck out in contrast
with the now-dark treebark. Consequently, the darker moths
began to do better, and grew in population; they were now
camouflaged from the sight of the birds.

And now, in the past few decades, pollution controls have
helped clean up the environment, and the trees are returning
to their original color. Hence the lighter moths begin to
thrive at expense of their darker cousins.

This model simulates these environmental changes, and how a
population of moths, initially of all different colors,
changes under the pressures of natural selection.

HOW TO USE IT
-------------
The NUM-MOTHS slider controls how many moths are initially
present in the world. Their coloration is randomly
distributed over the possible colors of the world (generally
white to black). Simply select how many moths you'd like to
begin with (around 300 is good), and press the SETUP button.
Then press the GO button to begin the simulation.

The MUTATION slider also controls an aspect of reproduction.
For the purposes of the simulation, the mutation rate is
much higher than it might be in real life. When set to 0,
moths are exactly the same as the parent that hatched them.
When set to 100, there is little corolation between a
parent's color and the coloration of its children. (Best
results are seen when MUTATION is set to around 10 or 15,
but experiment with the rate and watch what happens.)

The SELECTION slider determines how moths are harvested by
the birds that feed on them. SELECTION wraps up nicely many
factors that determine the survivability of a species-
how many birds there are, how hungry they are, how well they
can see the moths, and just how important camouflage is to
escape being eaten. SELECTION provides a probabilistic
window- the lower the level of the slider, the wider this
'window'. At 0, a moth's color ceases to matter. At 100, a
moth needs to be perfectly camouflaged to reduce its odds of
being seen (and thus devoured). You might first try running
the model with SELECTION set to around 50.

The SPEED slider controls just how fast the simulation 
runs. Unlike some other StarLogo projects where SPEED is
used, this slider has a direct effect on the run-time
performance of the model. SPEED controls just how fast the
world becomes polluted, and then clean again. (Look at the
two monitors MAX-OF-PATCHES [ENV] and MIN-OF-PATCHES [ENV]-
watch how fast they change at different levels of speed.)
As you might guess, 1 is slow, and 10 is fast.

Two once-buttons also effect what happens during a run of
the model. POLLUTE-WORLD and CLEAN-UP-WORLD do just that-
POLLUTE-WORLD makes the world darker, and CLEAN-UP-WORLD
makes the world lighter. 

Finally, 'Peppered Moths' uses six monitors, all of which are
straightforward. TICKS reports how much time has elapsed.
COUNT-MOTHS displays how many moths are present in the
world. LIGHT-MOTHS, MEDIUM-MOTHS, and DARK-MOTHS report the
total number of moths with each color gradation- the moth
population is just divided into thirds over the range of
colors. Finally, AVG-ENV reports the pollution level in each
patch- as the world of the peppered moths is equally
polluted or clean all over, the value is the same for all
patches.

RUNNING THE MODEL
-----------------
  1) THINGS TO NOTICE
  -------------------
The most important thing to watch is how the entire set of
moths seems to change color over time. Let the model run by
itself the first time- watch the world change from white to
black back to white. Then see how manipulating the sliders
effects the population of moths.

Notice that during the first few initial time-steps, the
moth population booms. You might then see the moth
population fluctuate between different levels, some of which
are quite large. The moths give birth to many offspring, but
the world in which they live is finite- it has finite space
and resources. If the population exceeds 1000 or so, the
moths tend to die a lot faster than they would otherwise.
Under normal circumstances, the population will tend to stay
constant, at a level dependent on the speed and selection
rates.

Watch what happens when a drastic change in the environment
occurs. (You can force this with the POLLUTE-WORLD and
CLEAN-UP-WORLD buttons.) Can you kill off all of the moths
in a matter of a few time-steps?

You can watch the ratios between the types of moths change
either in the monitors, or graphically in the plot window.
The yellow line indicates the lighter-colored moths, the
green line indicates moths whose color is intermediate, and
the blue line represents the total number of moths with the
darkest coloration.

  2) THINGS TO TRY
  ----------------
How do different levels of mutation and selection change the
population? How does the speed of the model effect the rate
at which the moths change? Is there a speed at which the
moths can't keep up, i.e. the world changes faster than
small pockets of discolored moths or mutants can help keep
the population up to size?

The color system that 'Peppered Moths' uses was designed to
be malleable. Thus two global variables were used, and their
values set in the setup procedure. They are 'light-color'
and 'dark-color'. Initially, they are set to white and
black, but if you wish, you can set them to any values you'd
like.

The upper-bound for the moth population is also easily
defined as a global variable, 'upper-bound'. It is initially
set to 1000, but you can change this as well and watch what
happens. (Note that if it is set too high, you may need to
change the maximum number of turtles that StarLogo has
available. Pull down 'Settings' from the Edit menu to adjust
StarLogo's memory allocations.) 

EXTENDING THE MODEL
-------------------
'Peppered Moths' is a nice introduction into modeling
genetic and evolutionary phenomena. The code is fairly
simple, and divided up into several small procedures that
handle the different stages of each generation. This makes
it easy for other extensions to be added to the model.

Each moth has one gene that effectively determines its
survivability under current conditions. This is a turtle
variable, 'c-gene'. Add the concept of the recessive gene to
'Peppered Moths'- each moth might have two color genes, that
together determine its color. Moths will then need to seek
out mates, and use sexual reproduction as opposed to the
unnatural asexual reproduction we see here.

Add a 'geography' to the world of the moths. Already, the
pollution level of the world is a 'local' patch variable,
not simply set for the world as a whole. What might happen
if parts of the world were heavily polluted and some parts
stayed pristine? Perhaps each moth could do a local search
to move to a patch that was close to its own color.

STARLOGO FEATURES
-----------------
Note that all of the commands given to the moths are in a
block of code that begins 'ask-moths [...]'. This is because
each moth is given a breed, 'moths'. This makes the code far
easier to modify, especially if you want to add a different
kind of animal, say, the birds that eat the moths. You would
then add a new breed, 'birds', and put all code that birds
are to execute in the body of 'ask-birds [...]'.

Although the moths have a wide range of different colors,
we use one basic shape for them all. This is because a
moth's color, as StarLogo knows it, can be different from
the color you see the shape has. The moth shapes consist of
a black border (with two beady black eyes), inside of which
is a special color, a 'transparent' color that takes on the
color of the patch beneath it. Moths then stamp their real
color (here we use 'c-gene') onto the patch they are on, and
then take on that color due to their transparency. (And to
make sure that these colors don't stick around after a moth
flies off the patch, we reset a patch's color to its 'env'
rate at the start of every time-step.)