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.2. BUILDING AN AGENT-BASED MODEL 435Code 19.5:class agent:passag = agent()ag.type = r<strong>and</strong>int(2)ag.x = r<strong>and</strong>om()ag.y = r<strong>and</strong>om()To generate a population <strong>of</strong> agents, we can write something like:Code 19.6:n = 1000 # number <strong>of</strong> agentsclass agent:passdef initialize():global agentsagents = []for i in xrange(n):ag = agent()ag.type = r<strong>and</strong>int(2)ag.x = r<strong>and</strong>om()ag.y = r<strong>and</strong>om()agents.append(ag)2. Design <strong>the</strong> data structure <strong>to</strong> s<strong>to</strong>re <strong>the</strong> states <strong>of</strong> <strong>the</strong> environment, 3. Describe <strong>the</strong>rules for how <strong>the</strong> environment behaves on its own, & 4. Describe <strong>the</strong> rules for how agentsinteract with <strong>the</strong> environment. Schelling’s model doesn’t have a separate environmentthat interacts with agents, so we can skip <strong>the</strong>se design tasks.5. Describe <strong>the</strong> rules for how agents behave on <strong>the</strong>ir own. We assume that agentsdon’t do anything by <strong>the</strong>mselves, because <strong>the</strong>ir actions (movements) are triggered onlyby interactions with o<strong>the</strong>r agents. So we can ignore this design task <strong>to</strong>o.6. Describe <strong>the</strong> rules for how agents interact with each o<strong>the</strong>r. Finally, <strong>the</strong>re is somethingwe need <strong>to</strong> implement. The model assumption says each agent checks who are inits neighborhood, <strong>and</strong> if <strong>the</strong> fraction <strong>of</strong> <strong>the</strong> o<strong>the</strong>r agents <strong>of</strong> <strong>the</strong> same type is less than athreshold, it jumps <strong>to</strong> ano<strong>the</strong>r r<strong>and</strong>omly selected location. This requires neighbor detec-

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

Saved successfully!

Ooh no, something went wrong!