banner-nll

Now we must fix all the  variables and procedures to fit this program.  Everywhere "wolves" appears, replace it with "birds" and instead of "sheep" we have "moths."  After editing, if you select compile, you get an error message that says you didn't define Move.  So, we must define move by writing a routine that will move the birds around.  This routine must be outside  of the to go routine because it is to be done by the birds.  After the  end of the to go routine add a to move routine.  How will you move the birds?  Random heading and random distance might work out alright. Can you write this piece of the program? Remember to give them directions that vary and  a distance to travel. 

Now, compile.  Our next task is to write code so our birds will catch moths.  Once again, we can use the code in the Wolf Sheep Predation model.  Find the wolf procedureto catch-sheep and cut and paste it into the peppered moth program just after the Move routine you wrote for the birds.  Replace references  to wolves and sheep with birds and moths.  Do the same thing with the routine to reproduce wolves and to death.   After you do this, and compile again, the error message will tell you that "grabbed?" is not defined.  Look at the Wolf Sheep Predation model to see where to put this definition.   This "moths" variable will also have to be set to false during the setup  of the moth population.  Refer to the Predation model if you have a problem with  that.

The model should now run.  Is it doing what we wanted?  Study the code and see how moths die.  Predation is not the only way.  They die due to a lack of fitness.  That is what predation is  supposed to do.  There is no advantage given to certain colored moths by our birds even though the fitness formula does provide an advantage.  Lets remove the fitness formula and see if we can just use the birds to determine fitness. Delete the slider for selection also. 

Now, you need to alter the catch-moths routine so that only moths that are not camouflaged are  captured.  A simple and statement will cause the birds to inspect the moth to  see if it matches the patch it is currently on.  The amount of energy provided  to the bird by eating the moth may need tinkering.   Have the moth count for about 3 energy units. That section of the program should look like this:

catchmoth102

Change the mutation rate slider to a scale of 1 to 10.  Run the simulation with mutation set to a low number and compare the results with a simulation when it is set at a high  number.

To extend this lab, think  about a way to have the moths reproduce sexually rather than by just random  asexual reproduction.  You could have breed variables for the sexes and  genotypes, and local variables for the production of gametes.  Mating would include "If" statements to determine the sex of other moths on a patch.  The  genes contributed to the offspring would be determined by the genotype of the parent.  You would then rewrite the assignment of color to a routine that uses  the genotype to determine the phenotype instead of choosing a color based on random number generation.   How would you handle the mutation rate in this case?


With Support from:

The NetLogo Learning Lab is part of modelingcomplexity.org, the home of the Mesa State College Center for Agent-Based Modeling.

This website is copyright by Mesa State College, 2004. All rights are reserved.

Some materials are adapted from the NetLogo User manual, and are copyright Wilensky, U. (1999). NetLogo.  Center for Connected Learning and Computer-Based Modeling. Northwestern University, Evanston, IL.