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.

19.4. ECOLOGICAL AND EVOLUTIONARY MODELS 461r_init = 100 # initial rabbit populationmr = 0.03 # magnitude <strong>of</strong> movement <strong>of</strong> rabbitsdr = 1.0 # death rate <strong>of</strong> rabbits when it faces foxesrr = 0.1 # reproduction rate <strong>of</strong> rabbitsf_init = 30 # initial fox populationmf = 0.05 # magnitude <strong>of</strong> movement <strong>of</strong> foxesdf = 0.1 # death rate <strong>of</strong> foxes when <strong>the</strong>re is no foodrf = 0.5 # reproduction rate <strong>of</strong> foxescd = 0.02 # radius for collision detectioncdsq = cd ** 2class agent:passdef initialize():global agentsagents = []for i in xrange(r_init + f_init):ag = agent()ag.type = ’r’ if i < r_init else ’f’ag.m = mr if i < r_init else mf ###ag.x = r<strong>and</strong>om()ag.y = r<strong>and</strong>om()agents.append(ag)def observe():global agentscla()rabbits = [ag for ag in agents if ag.type == ’r’]if len(rabbits) > 0:x = [ag.x for ag in rabbits]y = [ag.y for ag in rabbits]plot(x, y, ’b.’)foxes = [ag for ag in agents if ag.type == ’f’]

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

Saved successfully!

Ooh no, something went wrong!