15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

460 CHAPTER 19. AGENT-BASED MODELSwithm = mr if ag.type == ’r’ else mfCode 19.21:m = ag.min <strong>the</strong> update function. These changes make <strong>the</strong> magnitude <strong>of</strong> movement a heritableattribute <strong>of</strong> individual agents. Finally, <strong>to</strong> introduce variation <strong>of</strong> this attribute, we should addsome small r<strong>and</strong>om number <strong>to</strong> it when an <strong>of</strong>fspring is born. This can be implemented byreplacingCode 19.22:with something like:Code 19.23:agents.append(cp.copy(ag))newborn = cp.copy(ag)newborn.m += uniform(-0.01, 0.01)agents.append(newborn)There are two places in <strong>the</strong> code where this replacement is needed, one for prey <strong>and</strong>ano<strong>the</strong>r for preda<strong>to</strong>rs. Note that, with <strong>the</strong> mutations implemented above, <strong>the</strong> diffusionrates <strong>of</strong> agents (m) could become arbitrarily large or small (<strong>the</strong>y could even become negative).This is fine for our purpose, because m is used in <strong>the</strong> update function in <strong>the</strong> form<strong>of</strong> uniform(-m, m) (which works whe<strong>the</strong>r m is positive or negative). But in general, youshould carefully check your code <strong>to</strong> make sure <strong>the</strong> agents’ evolvable attributes stay withinmeaningful bounds.For completeness, here is <strong>the</strong> revised code for <strong>the</strong> evolutionary preda<strong>to</strong>r-prey ABM(with <strong>the</strong> revised parts indicated by ###):Code 19.24: preda<strong>to</strong>r-prey-abm-evolvable.pyimport matplotlibmatplotlib.use(’TkAgg’)from pylab import *import copy as cpnr = 500. # carrying capacity <strong>of</strong> rabbits

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!