MIS 643 AgentBased Modeling Chapter 5 The Components
MIS 643 Agent-Based Modeling Chapter 5 The Components of Agent-Based Modeling
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
The Components of Agent. Based Modeling • • Individual components of ABMs Overview of components of ABM Discuss each components How components come together for the construction of ABMs
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Overview • Complex systems – described – agents, environment – behavior - agent rules • Basic components of ABMs • agents – basic ontological units • environment – world in which agents live • interactions – between agents and environments
Overview • agent actions – internanlly – directly affacting agents internal state – E. g. : in Segregation – agents move • The environment may not be passive – E. g. : grass regrows • Two more:
Overview • Observer/User Interface: an agent but can access all agents and environment – ask agents to carry out specific tasks – users interact with ageents with UI • Schedule: the observer tells agents when to do
Trafic Basic Model • Trafic basic model –a simple model of trafic flow – in Social Science section • to explore how trafic jams form • they thought to include – trafic accidents, radar traps • but without such hindrances • trafic jams form as – – – cars approach to cars in front of them they slow down, cars behind slow down and so on. . . a ripple effect backwords – trafic jam moves backward emergence
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Agents • • • Properties Behavior (Actions) Collections of Agents The Granularity of an Agents Cognition Other Kind of Agents
Agents • basic building blocks of ABM • properties – they have – internal and external states • actions – behavior – what they do • Several issues: • agents grin-size – most effective – e. g. : political model: actors, institutions • agent cognition- capability to observe and decision about world • proto agnets and meta-agents
Properties • describe agent’s current state • individual agents - inspected by monitors: – patch, turtle, link • Figure 5. 2 • Two sets of properties – Standard turtle properties • WHO, COLOR, HEADING, XCOR, YCOR, SHAPE, LABEL-COLOR, BREED, HIDEN? , SIZE, PEN-MODE
Properties (cont. ) – Standard patch properties: • PXCOR, PYCOR, PLABEL-COLOR – Standard link properties: • END 1, END 2, COLOR, LABEL-COLOR, HIDEN? , BREED, THICKNESS, SHAPE, THEMODE • turtles can directly access patch properties they are currently on – sit on exactly one patch at a time
• accessing turtles from patches: – turtles-here: set of turtles on the patch – turtles-on: set of turtles on a specified patch
user defined prrperties • author defined properties: • E. g. : for Simple Trafic model: – SPEED, SPEED-LIMIT, SPEED-MIN • should be described in info tab • SPEED: curent speed of the car • SPEED-LIMIT: maximum speed of the car • SPEED-MIN: its minimum speed
• set in the SETUP-CARS procedure at the srart of the model set speed. 1 + random-float. 9 set speed-limit 1 set speed-min 0
• uniformly distributed random variable random-float value – 0 <= random number < value • normally distributed random variables random-normal mean standard-dev • E. g. : random-normal. 5. 1 – mean and starndard deviation of a normal distribution
• Initialize agent properties from – lists or files – emprical data • Example: from file: – Higths of patches in the Butterfly model are red from a file • Example: from lists: – colors of people are assigned from red or blue set color one-of [red blue]
• agent properties can be changed during the running of the model • E. g. : in Trafic Basic model • speed propertiy can be increased or decreased in the SPEED-UP-CAR procedure set speed + acceleration
Behaviors (Actions) • how the agents can behave – actions it can take • the agent can change the state of the – environment, other agents’ or it self • List of all predefined behavior • Net. Logo dictionary: – turtles, patches, links FORWARD/BACKWARD RIGHT/LEFT HATCH/DIE
Behaviors (Actions) • author defined behavior • E. g. : in TBM, SPEED-UP-CAR, SLOW-DOWN-CAR to slow-down-car ; ; turtle procedure set speed - deceleration end to speed-up-car ; ; turtle procedure set speed + acceleration end
initialization globals [ sample-car ] turtles-own [ speed-limit speed-min ] to setup clear-all ask patches [ setup-road ] setup-cars watch sample-car reset-ticks end to setup-road ; ; patch procedure if (pycor < 2) and (pycor > -2) [ set pcolor white ] end
setup-cars to setup-cars if number-of-cars > world-width [ user-message (word "There are too many cars for the amount of road. Please decrease the NUMBER-OF-CARS slider to below " (world-width + 1) " and press the SETUP button again. The setup has stopped. ") stop ] set-default-shape turtles "car" crt number-of-cars [ set color blue set xcor random-xcor set heading 90 ; ; ; set initial speed to be in range 0. 1 to 1. 0 set speed 0. 1 + random-float. 9 set speed-limit 1 set speed-min 0 separate-cars ] set sample-car one-of turtles ask sample-car [ set color red ] end
; this procedure is needed so when we click "Setup" we ; don't end up with any two cars on the same patch to separate-cars ; ; turtle procedure if any? other turtles-here [ fd 1 separate-cars ] end
go • adjust their speed according to speed limits to go ; ; if there is a car right ahead of you, match its speed then slow down ask turtles [ let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody [ set speed [speed] of car-ahead slow-down-car ] ; ; otherwise, speed up [ speed-up-car ] ; ; ; don't slow down below speed minimum or speed up beyond speed limit if speed < speed-min [ set speed-min ] if speed > speed-limit [ set speed-limit ] fd speed ] tick end
slow-down-car/speed-up-car to slow-down-car ; ; turtle procedure set speed - deceleration end to speed-up-car ; ; turtle procedure set speed + acceleration end
• agents - cars can change their speed and indirectly affect the speed of other cars • can chnge environment properties • E. g. : speed of a car makes the road – the patches worm-up by a precedure WEAR • E. g. : sheep eat grass , change the amount of grass in a place
Collections of Agents • • Three types mobile agents – turtles in Net. Logo stationary agents – ptches in Net. Logo connecting agents: links in Net. Logo
Collections of Agents • mobile agents – turtles in Net. Logo – shapeless; arealess points – even shape and size, – when created: • x, y coordinats - at center • headings - random – coordinates : xcor, ycor
Collections of Agents • stationary agents – ptches in Net. Logo – acted upon by turtles; pasive environments – take actions and perform operations – defined space/area
Collections of Agents • connecting agents: links in Net. Logo – link two or more agents – relation between turtles – friendship, communiciation, – envirnonments: roads
Breeds of Agents • particular set of agents with their own preperties and actions • breed of an agent: class or category to which the agent belongs • if different agents have different properties or actions • E. g. : sheep and wolves has the same properties but actions are different tutles-own [energy] sheep-own [wooliness] volves-own [fang-strength] sheep – energy and wooliness volves - energy and fang-strength
Sets of Agents • Net. Logo – agentset: unordered collection of agents • collecting agents something in common • or randomly selecting subset of another agentset let fast-cars turtles with [speed > 0. 5] ask fast-cars [set size 2. 0] • or without let ask turtles with [speed > 0. 5] [set size 2. 0]
• all turn to size 2 • slow turtels sizes 1 ask turtles with [speed > 0. 5] [set size 2. 0] ask turtles with [speed <= 0. 5] [set size 1. 0] • another way of doing ask turtles [ ifelse [speed > 0. 5] [set size 2. 0] [set size 1. 0] ] : : end ask
collection of agents based on location let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody [ set speed [speed] of carahead slow-down-car ] • TURTLES-ON PATCH-AHEAD 1 – turtles on the patch 1 unit ahead of a turtles • accessing collections agents based on their locations • TURTLES-HERE, TURTLES-AT, NEIGHBORS, IN-RADIUS
choosing agents randomly • N-OF, ONE-OF ; ; create turtles on random patches ask n-of number patches [ sprout 1 [set color one-of [red green]] ] ; ; end ask
Agentsets and Lists • creating an empty list set a-list [] • add items to list set a-list fput 1 a-list set a-list fput “and” a-list set a-list fput turtle 0 a-list show a-list [(turtle 0) “and” 1]
• an agentsets hold same type of agents • empty agentsets – no-turtles, no-patches, no-links • creates an empty agentset of turtles set an-agentset no-trutles set an-agentset (turtle-set turtle 0) set an-agentset (turtle-set anagentset turtle 1 turtle 2) : : an-agentset has three turtles
• agentsets can be asked to do something • lists cannot be asked • agentsets are unordered • when printing they are printed randomly turtles-own [information] let a-list [] set a-list sort-on [information] turtles • a-list: list of turtles in ascending order by information
foreach a-list [ ask ? [] ; ; do something ] • ? as a special variable takes on each value of the list elements
let n 0 foreach sort patches [ ask ? [ set plabel n set n n + 1 ] ] ; ; patches are labeled with numbers in left-to-right, ; ; top-to-bottom order
Agentsets and Computation • when an agentset is asked to perform an action, agents collected at that moment are asked to do – agent A, agent B, are in the collection – agent C not in the collection – if agent A action causes agent B not satisfy collection criteria but agent B is also asked – if agent A action causes agent C satisfy collection criteria but agent C is not asked • E. g. : Agentset Ordering Model (AOM) in IABM Ch 05
setup ; ; create 100 blue turtles of size between 0. 0 and 2. 0 to setup clear-all create-turtles 100 [ set size random-float 2. 0 forward 10 set color blue ] reset-ticks end
go to go ; ; ask all turtles with size < 1 to ask a larger turtle to decrease its size, and then turn themselves red ask turtles with [ size < 1. 0 ] [ ask one-of turtles with [size > 1. 0] [ set size - 0. 5 ] set color red ] print count turtles with [color = red] print count turtles with [size < 1. 0] end
Computational Efficiency • Sometimes it is better to form an agentset before performing operations on it • E. g. : Agent Efficiency Model (AEM) in IABM Ch 05 • trade off between efficiency and code readability
setup ; ; SETUP colors the patches so that roughly half are red and half are green to setup clear-all ask patches [ set pcolor one-of [red green] ] reset-ticks end
go-1 ; ; GO-1 sets the labels of red patches to a small random number (0 -4) ; ; and the labels of green patches to a larger random number (5 -9) to go-1 if any? patches with [pcolor = red] [ ask patches with [ pcolor = red ] [ set plabel random 5 ] ] if any? patches with [pcolor = green] [ ask patches with [ pcolor = green ] [ set plabel 5 + random 5 ] ] tick end
go-2 ; ; GO-2 has the same behavior as GO-1 above, but it is more ; ; efficient as it computes each of the agentsets only once. to go-2 let red-patches with [ pcolor = red ] let green-patches with [ pcolor = green ] if any? red-patches [ ask red-patches [ set plabel random 5 ] ] if any? green-pathces [ ask green-patches [ set plabel 5 + random 5 ] ] tick end
go-3 ; ; GO-3 explores what happens if patch colors are changed on the fly. ; ; GO-3 results in the entire world becoming red to go-3 if any? patches with [pcolor = red] [ ask patches with [ pcolor = red ] [ set pcolor green ] ] if any? patches [with pcolor = green] [ ask patches with [ pcolor = green ] [ set pcolor red ] ] tick end
go-4 ; ; GO-4 explores what happens if you first keep track ; ; of which patches are red and which are green. ; ; GO-4 results in the patches swapping their colors. to go-4 let red-patches with [ pcolor = red ] let green-patches with [ pcolor = green ] if any? red-patches [ ask red-patches [ set pcolor green ] ] if any? green-patches [ ask green-patches [ set pcolor red ] ] tick end
The Granularity of an Agent • granularity – at what complexity levcel agents are – atoms < molecules < cells < hummans < organizations < governments • agents – people • government interactions – – agents: governments not every people • Guideline – agents fundamental level of interaction research questio about the phenomena
The Granularity of an Agent • • • Tumor model – agents: cells RQ: how tumor cells spread? AIDS model – agents: humans RQ: deseas spreading between humans The relation between RQ – interaction – agent granularity
The Granularity of an Agent • • • In tumor - agents could be organs RQ: tumor affect throughout the body group of cells operating homogenuously dosens of cells – agents RQ and computational complexity
The Granularity of an Agent • choosing right granularity • ignore unneccessary aspects of the phenomena • focus on interactions of interest • appropriate grain-size – early step in designing ABMs • Granularity – competible relative to each other – scale of model • operate on roughly the same time scale and physical presence • else make udjustments to the model
Agent Cognition • How agents examine their properties and the world around them to make decisions • types of agent cognition: – reflexive – unitiy-based agents – goal-based agents – adaptive agents • Russell and Norving 1995 • usually in order of increasing complexity
Reflexive Agents • build around very simple rules • if-then rules to react to inputs and take action • most basic form of agent cognition • often a good starting point
Reflexive Agents • E. g. : cars in the TBM are reflexive agents • the code controling their actions: let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody [ set speed [speed] of car-ahead slow-down-car ] ; ; otherwise, speed up [ speed-up-car ] ; ; ; don't slow down below speed minimum or speed up beyond speed limit if speed < speed-min [ set speed-min ] if speed > speed-limit [ set speed-limit ] fd speed ]
Utility-Based Agents • Elaborate the TBM agents • give cars gas tank – fuel efficiency • cars change their speed in order to imporve thier fuel efficiency • cars speed up or slow down at different times to minimize their gas usage while not causing accidents • They attempt to maximize a utility function – their fuel efficiency
Utility-Based Agents • replace SPEED-UP-CAR with ADJUST-SPEEDFOR-EFFICENCY let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody [ set speed [speed] of carahead slow-down-car ] ; ; otherwise, speed up [ speed-up-car ]
ADJUST-SPEED-FOREFFİCENCY • maintain the same speed if the car is at the car’s at maximally fuel efficient speed • the logic: – speed up if the car is moving too slow – slow down if the car is moving too fast – slow down not to crash a cor in front of it • utility function to be maximized • f(v) = |v-v’| • vhere v: current velocity, v’: most fuel efficient velocity
adjust-speed-for-efficiency ; ; adjust speed to be closer to most efficient speed to adjust-speed-for-efficiency if not (speed = efficient-speed) [ if (speed + acceleration < efficientspeed) [ set speed + acceleration ] if (speed - deceleration > efficientspeed) [ set speed - deceleration ] ] end
Experiments • with different values of EFFICIENTSPEED • different trafic patterns from the original model – low values - free flow no jams • original model – utility maximization s. t. to speed limit – a trivial utility function
Goal-Based Cognition • Trafic Grid Model (TGM) in the Social Science section of the Net. Logo library • each car has a home and place to work • goal of moving home to work in a reasonable amount of time • not only – speed up or slow down • but also – turn left and rigth • cars – goal-based agents
TGM • each car – house and work locations – off road but adjucent to the road let goal-candidates patches with [ pcolor = 38 and any? neighbors with [ pcolor = white ] ]
Adaptive Agents • agents can change decisions as well as strategies based on prior experience • adaptive agents – • in the TBM cars do not take the same action • same observation of their environment – act differently based on past experiences • learn from past experience – change future behavior
• E. g. : in TBM best acceleration to maintain highest velocity • modify the GO procedure
adaptive-go to adaptive-go ; ; check to see if we should test a new value for acceleration this tick let testing? false if ticks mod ticks-between-exploration = 0 [ set testing? true set acceleration + random-float 0. 001 0. 0005 ] ; ; invoke the non-adaptive go code go
adaptive-go (cont. ) ; ; check to see if our new speed of turtles is better than the previous speeds if so ; ; then adopt the new acceleration ; ; you don't want to take one data point as a measure of the speed. Instead you ; ; calculate a weighted average of the past observed speed and the current speed. ifelse mean [ speed ] of turtles > best-speed-so-far and testing? [ set best-acceleration-so-far acceleration set best-speed-so-far mean [ speed ] of turtles ] [ set acceleration best-acceleration-so-far ] if not testing? [ set best-speed-so-far (0. 1 * mean [speed] of turtles) + (0. 9 * best-speed-so-far) ] end
• run the TBAM for al long enough time • cars stop forming trafic jams • The model learns that high rate of accelation – best speed • one acceleration value for all cars • Allow for individual agents to learn different best accelerations
Other Kinds of Agents • meta-agents: agents made up of other agents • proto-agents: placeholder agents allowing to define interactions with fully defined agents with other entities that are not developed yet
Meta-Agents • agents composed of other agents • always a lower level of detail • E. g. : hummns agents – subagents depends • systems of the body: immune, . . . • psychological aspects: intellect, emotion • mate agents – composed of other agents • subagents – composing agents • neta agent – meta agent interaction
Meta-Agents • • • Design agents granularity or meta-agents in Net. Logo no language support some commannds TIE
Proto-Agents • somethimes rather than having their own properties and behavior • placeholders for future agents • specify how other agents would interact with them, if they were flashed out into full agents
Example • residential location decision making • residents as agents • where to live decision – employment and services: restorants • focal agents – residents • “service centers” as agents – placeholders for jobs or other transactions • Later version of the model – service centers: decide to locate based on their properties • Keep them as proto-agents – initial model to later models, do not revise resident agents too much
Meto/Proto-Agents • Enable a way to create simple models initially • then eloborate upon to refine them
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Environments • Spatial Environments • Network-Based Environments • Special Environments
Environments • Conditions and habitats surrounding the agents as they act and interact within the model • affect agent decisions and be affected by agent decisions • E. g. : Ants model in chapter 1 – anst leave phormone in the environment – that changes the environment and in tern – changes the behavior of the ants
Implementations • veraity of ways • 1 – composed of agents, each has its own properties and actions – Net. Logo – patches – different parts different properties and act differently - local interactions • 2 – one large agent with global set of properties and actions • 3 - implement outside of the ABM toolkit – GIS or social network anaysis
Spatial Environments • in ABM two varients: – discrete spaces – continuous spaces • both can be finite or infinite • in Net. Logo standard is finite • but infinite is possible
Discrete Spaces • common in ABM: latice graphs or mesh graphs, or grid graphs • most common types: • square and hexagonal latices • triange is not so common
Square Latices • neighborhoods • with radius one • von Neuman – four neighbors located in the cardinal directions • Moore – 8 adjecent cells • with radius 2 – 12 neighbors
Hex Latices • the distane between a cell and all of tis adjacent cells are the same
Continuous Spaces • • no notion of a cell or discrete region agents located at points in space can move smootly in space advantage of Net. Logo: agents move in a continuous space with a discrete latice lied on top of it. – they determine what cell they are currently on • center of each patch – integer • patch at -1 -5 – contains buttom and left eges but not top and right edges
Boundary Conditions • • E. g. : an agent reaching far left What happens? topologies of the environment 1 – toroidal: all of the edges are connected to others in a regular manner - wrapping • 2 – bounded: agents are not allowed to move beyond the edges of the world – mixture of bounded and toroidal • 3 – infinite-plane: no bouns; agents can keep moving in any direction
Network-Based Environments • In many real world situations especially in social contexts • agents communicate by a networkbased environment • networks - links • defined by two ends it connects – nodes (vertices) connected by links (edges)
in Net. Logo • • • link – agent type can be like patches passive conduits of information or description of environment or full blown agets with properties and actions latices special networks – latice networks Applications: spread of disease, runnors, formation of social groups, structure of organizations
Common Network Topologies • latice – regular networks – not supported in ABM Tools • random networks • scale-free networks • small world networks
Random Networks • the probability of forming a connection between two agents is p • Erdos Renyi (1959) • Random Network Model (RNM) IABM in Chapter 5
setup to setup ca create-turtles num-nodes [ set shape "circle" setxy random-xcor randomycor ] reset-ticks end
wire 1 ; ; Ask each node to create a link with a random other node. ; ; Results in "just under" NUM-NODES links because no new link is created ; ; if a node tries to connect to a node with which it is already linked. to wire 1 ask links [ die ] ask turtles [ create-link-with one-of other turtles ] end
create-link(s) commands • create-link-with: creates an undirected link between the caller and agent. • create-link-to: creates a directed link from the caller to agent. • create-link-from: creates a directed link from agent to the caller. • When the plural form of the breed name is used, an agentset is expected instead of an agent and links are created between the caller and all agents in the agentset.
create-link(s) commands (cont. ) • The optional command block is the set of commands each newly formed link runs. (The links are created all at once then run one at a time, in random order. ) • A node cannot be linked to itself. Also, you cannot have more than one undirected link of the same breed between the same two nodes, nor can you have more than one directed link of the same breed going in the same direction between two nodes. • If you try to create a link where one (of the same breed) already exists, nothing happens. If you try to create a link from a turtle to itself you get a runtime error.
wire 2 ; ; Pick a random node and ask it to create a link with a random other node. ; ; Results in "just under" NUM-NODES links because no new link is created ; ; if a node tries to connect to a node with which it is already linked. to wire 2 ask links [ die ] repeat num-nodes [ ask one-of turtles [ create-link-with one-of other turtles ] ] end
wire 3 ; ; This is the classic Erdős-Rényi random network. ; ; It uses WHILE to ensure we get NUMLINKS links. to wire 3 ask links [ die ] while [ count links < num-links ] [ ask one-of turtles [ create-link-with one-of other turtles ] ] end
wire 4 ; ; A variant of the classic Erdős-Rényi where each possible pair of nodes ; ; gets a chance to create a link between them with a specified probability. to wire 4 ask links [ die ] ask turtles [ ask turtles with [ who > [ who ] of myself ] [ if random-float 1. 0 < wiring-prob [ create-link-with myself ] ] ] end
Scale Free Networks • any subnetwork of the global network has the same properties as the global one • Creation: – adding new nodes to the system in a way that extends nodes with large number of links is likely to get more new connections • Barabasi 2002 • Preferential attachments – nodes with more connections are attrcted preferentially
Scale Free Networks • many real networks – Internet, electricity grids, • To create a scale-free netowrk • Preferential attacmetn model in Chapter 5 of IABM
setup to setup ca set-default-shape turtles "circle" ; ; create two turtles (nodes) and space them out create-turtles 2 [ set color red fd 5 ] ask turtle 0 [ create-link-with turtle 1 ] ; ; create a link between them reset-ticks end
go to go if count turtles > num-nodes [stop] ; ; choose a partner attached to a random link ; ; this gives a node a chance to be a partner based on how many links it has let partner one-of [both-ends] of one-of links ; ; this is the heart of the preferential attachment mechanism ; ; create new node, link to partner create-turtles 1 [ set color red ; ; move close to my partner, but not too close move-to partner fd 1 create-link-with partner ] ; ; lay out the nodes with a spring layout tick end
Explanation • random selection form links • if a node has many links each of these links has an equal chance of being selected • then select one of the end nodes of that link • connect to the node selected
Small world Networks • Dence clusters of highly interconected networks with joined by a few long distance links • due to these long distance links it does not take long distance for information to travel beteen any randomly seleced nodes
Created • Starting with a regular network • randomly rewiring some of the conections to form large jumps • Watts and Strogatz 1998 • friends in a local geography but occational long jumps • fiends from other continents
Charecterising Networks • average path lenght • clustering coefficient
Average Path Length • average of all the pairwise distances between nodes in a network – measure distance between every pair of nodes and take the average – how far the node are form each other in a network
Clustering Coefficient • average fraction of a node’s immediate neighbors who are also neighbors of the node’s other neighbors • fraction of my friends who are also friends with each other • a network with high average CC – any neighboring nodes share many neighbors in common • a network with low avewrage CC – there is litle overlap neigbors of surrounding nodes
• Random networks – low average path lengths and low CC • Regular networks: – high path lenghts, usually high clustering coefficienfts • Small world networks – low path lengths and high CC • Scale-free – low average PL; hubs serve for communication
Special Environments • 3 D words • Geographical Information Systems (GIS) – importation of layers of geographical data into ABMs
3 D Worlds • • Net. Logo 3 D 3 dimensional word z coordinate orientation: pitch and roll – airplane example • pitch: angle to the horizontal – 90 o goes straigth up • roll – how far wings from horizontal
setup globals [ radius ; ; distance of the farthest green patch from the center ] to setup clear-all set radius 0 ask patch 0 0 0 [ set pcolor green ] reset-ticks end
wonder procedure to wander ; ; turtle procedure ; ; the WIGGLE-ANGLE slider makes our path straight or wiggly roll-right random-float wiggle-angle - random -float wiggle-angle rt random-float wiggle-angle - random-float wiggle-angle tilt-up random-float wiggle-angle - randomfloat wiggle-angle fd 1 end
roll-right/left, tilt-down/pu roll-right number Turtle Command The wingtip of the turtle rotates to the right number degrees with respect to the current heading and pitch. tilt-down number tilt-up number Turtle Command The nose of the turtle rotates by number degrees, relative to its current orientation. Depending on the orientation of the turtle more than one of the relative angles (heading, pitch, and roll) may change when a turtle turns.
neighbors/neighbors 6 Turtle Command Patch Command 3 D versions of neighbors and neighbors 4. Reports an agentset containing the 26 surrounding patches (neighbors) or 6 surrounding patches (neighbors 6). show sum values-from neighbors [count turtles-here] ; ; prints the total number of turtles on the twenty-six ; ; patches around this turtle or patch ask neighbors 6 [ set pcolor red ] ; ; turns the six neighboring patches red
GIS-Based • GIS records large amounts of data related to physical locations in the world. • used by – environmental scintists, urban planners, transportation engineers and many others – organize data and make decisions • spatial socioeconomic or marketing data • GIS provides an environment for ABM
GIS-Based file-open “patch elevation. data” let patch-elevations file-read file-close • list of values to patch-elevations
file-read This reporter will read in the next constant from the opened file and interpret it as if it had been typed in the Command Center. It reports the resulting value. The result may be a number, list, string, boolean, or the special value nobody. Whitespace separates the constants. Each call to file-read will skip past both leading and trailing whitespace. Note that strings need to have quotes around them. Use the command file-write to have quotes included. Also note that the file-open command must be called before this reporter can be used, and there must be data remaining in the file. Use the reporter file-at-end? to determine if you are at the end of the file.
file-read (cont. ) file-open "my-file. data" print file-read + 5 ; ; Next value is the number 1 => 6 print length file-read ; ; Next value is the list [1 2 3 4] => 4
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Interactions • • • fife basic classes of interactions agent-self environment-self agent-agent environment-environmemt agent-environment
Agent-Self Interactions • agent action involve interacting with itself • cognition models • current state – what to do • special case birth – one agent creates antoher agent • birth: not necessarily blological – organizations firms can create new ones • from two atoms - a molecule ?
reproduction in Sheep-Wolf Models ; ; check to see if this agent has enough energy to reproduce if energy > 200 [ set energy - 100 ; ; reproduction causes reduction of energy transfered to the offspring hatch 1 [set energy 100] ] ; ; end if ] ; ; end procedure
• • • considers its own state decide to reproduce update its state HATCH: turtle create turtles SPROUT: patch create turtle
killing agents • an agent can kill itself or an agent may ask an agent to kill itslef • DIE • CLEAR-TURTLES: clears all turtles to check-if-dead if energy < 0 [die] ]
in TBM let car-ahead one-of turtles-on patchahead 1 ifelse car-ahead != nobody [ set speed [speed] of car-ahead slow-down-car ] ; ; otherwise, speed up [ speed-up-car ] ; ; ; don't slow down below speed minimum or speed up beyond speed limit if speed < speed-min [ set speed-min ] if speed > speed-limit [ set speed-limit ] fd speed ]
in general • look at its speed and change it • in general look at its state – reources and decide change its own state – use resources
Environment-Self Interactions • areas of environment alters or changes themselves. • change internal state variables • E. g. : in ch 4 grass regrows to regrow-grass ask patches [ set grass-amount + grass -regrowth-rate if grass-amout > 10 [set grass-amout 10] re-color-grass ] ; ; end ask end
Agent-Agent Interactions • interactions between two or more agents most common in ABMs • E. g. : in SWPM in chapter 4 ; ; wolf eat sheep to eat-sheep if any? sheep-here [ let target one-of sheep-here ask target [die] set energy + energy-from -sheep ] ; ; end if end
in TBM • current car sensing whethere are cars ahead of it. if so, chage its speed let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody [ set speed [speed] of car-ahead slow-down-car ] ; ; otherwise, speed up [ speed-up-car ]
communication • agents can share information about their own state or obout their environment • in TBM current car aaks a car ahead of it to communicate its speed • E. g. : Communicate T-T model in Net. Logo’s Code Examples Library – one turtle starts with a message and communicate it to other turtles
; ; the core procedure! to communicate ; ; turtle procedure if any? other turtles-here with [message? ] [ set message? true ] end • a turtle chose a local turlte to communicate. if has a messages copied it
; ; the core procedure! to communicate ; ; turtle procedur if any? link-neighbors with [message? ] [ set message? true ] end • turtles are linked over a network
Environment-Environment Interactons • less common • E. g. : diffusion ants model in chapter 1 – the ants places phormone in the environment – then diffused through out the world
diffuse command • • diffuse patch-variable number Observer Command • Tells each patch to give equal shares of (number * 100) percent of the value of patch-variable to its eight neighboring patches. number should be between 0 and 1. Regardless of topology the sum of patch-variable will be conserved across the world. (If a patch has fewer than eight neighbors, each neighbor still gets an eighth share; the patch keeps any leftover shares. ) • Note that this is an observer command only, even though you might expect it to be a patch command. (The reason is that it acts on all the patches at once -- patch commands act on individual patches. ) • • • diffuse chemical 0. 5 ; ; each patch diffuses 50% of its variable ; ; chemical to its neighboring 8 patches. Thus, ; ; each patch gets 1/8 of 50% of the chemical ; ; from each neighboring patch. )
Agent-Environment Interactions • agents manipulate or examines part of the world it exists or • when the environmet alters or observe the agent • Agents observing the environment • E. g. : ants model – ants examine environmet to sense phormode to look for food
look-for-food to look-for-food ; ; turtle procedure if food > 0 [ set carrying-food? true ; ; pick up food set food - 1 ; ; and reduce the food source rt 180 ; ; and turn around stop ] if chemical > 0. 05 [ ; ; go in the direction where the pheromone smell is strongest uphill-pheromone] end
• if there is any food on the current patch • if so picks up the food and turn to the nest • the procedure stops • or • checks whethere is chemical • then uphill towords the direction with maximum phormone
movement • can be an agent-environment interaction if agent content of an area is important • E. g. : in the ASM • at the edge of the environment turn back to wander ; ; turtle procedure rt random 40 lt random 40 if not can-move? 1 [ rt 180 ] fd 1 end
other examples • in the SWM – sheep eat grass and gain energy – change the state of the environment • in the Butterfly model – a butterfly senses hight of the environment and move change its state
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Observer/User Interface • The oblserver: high level agent responsible for ensuring that the model runs and proceeds according to the steps developed by the model author. • is a special agent: access global properties like agents or patches • Properties unique to observer: – the perspective from which the modeled world is viewed. – in Net. Logo: the view • centered on a specific agent • focusing a highligth on a certainagent • Fo. LLOW, WATCH, RIDE commands
3 D View • 3 D perspective – • clicking the 3 D buttom in the top rigfht corner of the view control stip • FACE, FACEXYZ, SETXYZ commands or 3 d controls • world can be seen from the particular turtles eve-visw
• observer and agent buttons • observer buttons: tell the observer to do something • E. g. : create a SETUP button create-turtles 100 [ setxy random-xcor random-ycor] – only observer – create-tutrle command – tutles – hatch – patches - sprout
• create a turtle button – selecting turtle in the drop-down box • observer can run the code like that ask turtles [fd random 5 rt random 90]
User Input and Model Output • control mechanisms: • button: executes one or more commands • forever buttons: executes repeatedly until the user presses the button again • command center: a useful feature to test commands and manipulate agents interactively
Data-Driven Interface Controls • input/output controls • input controls: – sliders, switches, choosers, input boxes • output controls: – monitors, plots, an output area and notes
Input Controls • sliders: select a particular value from a range of numerical values – global variable • Switches: verious elements of a model turn on or off – global boolean variable • Choosers: select a choice from a predefined drop-down menu – global String variables • Input boxes: inputing text
Output Controls • Monitors: display the value of a global variable or calculation updated several times a second – no history – current value • Plots: treditional 2 D graphs to see change of a variable over time • Output box: create text-based feee form output • Notes: to place text information on the interface tab
File-Based Methods • write code to read data in from a file – modify the file to give input to the model • output data to a file – using tools such as Excel or R – aggregate data to form summary statistics
Visualization • part of model design • how to present data contained in a model in a visual way • Guidelines for visulization of ABMs – simplify, explain, emphasize • Simplify:
• shapes and colors • every net. Logo agent has • highlite some agents – backround others • E. g. : in the model agents with the same strategies has the same shape
Batch or Interactive • interactive running – the user can interact while the model is running – command center or even change parameter value with siders while model is runnig • batch running – scrpts to run models, different seeds or parameter values – Behavior. Space – command API – from Java or JVM
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Schedule • • • description of the order the model operates in Net. Logo order of events that occur sequence of buttons pushed code/procedures Initialization SETUP in Net. Logo – initilize agents, sets environment – clearing all agents and data about previous models – gets parameter values from user interface – create agents
setup of TBM to setup clear-all ask patches [ setup-road ] setup-cars watch sample-car reset-ticks end
GO Procedure • in Net. Logo main loop • describes what happens in one time unit (tick) – the agents being told what to do – the environment chaning – the user interface updating
go of TBM to go ; ; if there is a car right ahead of you, match its speed then slow down ask turtles [ let car-ahead one-of turtles-on patch-ahead 1 ifelse car-ahead != nobody [ set speed [speed] of car-ahead slow-down-car ] ; ; otherwise, speed up [ speed-up-car ] ; ; ; don't slow down below speed minimum or speed up beyond speed limit if speed < speed-min [ set speed-min ] if speed > speed-limit [ set speed-limit ] fd speed ] tick end
Two Issues • synchronous update: – all agents update at the same time • asynchronous updata: – some agents update before others • The model operates • sequentally – agents take turns acting • or parallel – agents operates at the same time • simulated cuncurrency – in between
Synchronous vs. Asynchronous Updates • Asynchronous update schedule – when agents change states this change is immediately seen by other agents – order of action matters • Synchronous update schedue – state changes are not seen until next clock tick – order of action does not matter • Both commonly used • asynchronous more realistic
go of CA with synchronous update to go ask patches [ set live-neighbors count neighbors with [pcolor = green] ] ask patches [ if live-neighbors = 3 [set pcolor green] if live-neighbors = 1 or liveneighbors = 0 [set pcolor blue] if live-neighbors >= 4 [set pcolor blue] ] end
go of CA with asynchronous update to go ask patches [ set live-neighbors count neighbors with [pcolor = green] if live-neighbors = 3 [set pcolor green] if live-neighbors = 1 or liveneighbors = 0 [set pcolor blue] if live-neighbors >= 4 [set pcolor blue] ]
Sequential vs. Parallel Actions • in asynchronous updates agents can act • sequentially or in parallel • sequential action: – only one act at a time • parallel action: – all act independently – more reallstic but require parallel harware • ASK sequential action – one agnent complete the set of actions then the other starts
simulated concurrency • one processor for parallel action • not fully supperted in Net. Logo • turtle procedures forever to go ; ; turtle procedure search-for-chip find-new-plie put-down-chip end
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Wrapping It All Up • • Three parts of ABMs the code the documentation the interface
Documentation • in Net. Logo - info tab Figure 5. 25 • overall purpose and structure of the model • eigth sections • can be added by model authors • other documantations • ODD by Grimm at all
Sections of the Info Tab • • WHAT IT IS? HOW TO USE IT? THINGS TO NOTICE THINGS TO TRY EXTENDING THE MODEL NETLOGO FEATURES RELATED MODELS CREDITS AND REFERENCES
User Interface • in Net. Logo Interface tab • enables the user – set parameters for a particular run of the model – watch model unfold – visulalizations
Outline Overview Agents Environments Interactions Observer/User Interface Schedule Wrapping It All Up Summary
Summary • agents: – properties, behavior, kinds • environment: – agents reside • interactions: – how the dynamics of the model evolve • observer/userinterface: – how the model is controled and data is extracted from • schedule: – tells the model when to do what
Summary • These fife components form the ABM • in all three parts • in designing new models or extending existing onces – compontnets – parts
- Slides: 170