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.

450 CHAPTER 19. AGENT-BASED MODELSFor preda<strong>to</strong>r agents, <strong>the</strong> rules are somewhat opposite. If a preda<strong>to</strong>r agent can’t findany prey agent nearby, it dies with some probability because <strong>of</strong> <strong>the</strong> lack <strong>of</strong> food. But if itcan consume prey, it can also reproduce at a certain reproduction rate.Finally, both types <strong>of</strong> agents diffuse in space by r<strong>and</strong>om walk. The rates <strong>of</strong> diffusioncan be different between <strong>the</strong> two species, so let’s assume that preda<strong>to</strong>rs can diffuse alittle faster than prey.The assumptions designed above can be implemented al<strong>to</strong>ge<strong>the</strong>r in <strong>the</strong> update functionas follows. As you can see, <strong>the</strong> code is getting a bit longer than before, which reflects<strong>the</strong> increased complexity <strong>of</strong> <strong>the</strong> agents’ behavioral rules:Code 19.15:import copy as cpnr = 500. # carrying capacity <strong>of</strong> rabbitsmr = 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> rabbitsmf = 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 ** 2def update():global agentsif agents == []:returnag = agents[r<strong>and</strong>int(len(agents))]# simulating r<strong>and</strong>om movementm = mr if ag.type == ’r’ else mfag.x += uniform(-m, m)ag.y += uniform(-m, m)

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

Saved successfully!

Ooh no, something went wrong!