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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

19.4. ECOLOGICAL AND EVOLUTIONARY MODELS 453nr = 500. # carrying capacity <strong>of</strong> rabbitsr_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.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.’)

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

Saved successfully!

Ooh no, something went wrong!