320 likes | 616 Views
Agent-Based Modeling and Simulation (ABMS) Bertan Badur badur@boun.edu.tr Department of Management Information Systems Boğaziçi University. Collectives. Chapter 16 of Agent-Based and Individual-Based Modeling: A Practical Introduction , by S. F. Railsback and V. Grimm NetLogo User Menual.
E N D
Agent-Based Modeling and Simulation (ABMS) Bertan Badur badur@boun.edu.tr Department of Management Information Systems Boğaziçi University
Collectives • Chapter 16 of Agent-Based and Individual-Based Modeling: A Practical Introduction,by S. F. Railsback and V. Grimm • NetLogo User Menual
Outline • .
Entities, States, Scales • Agents: • dogs, dog packs, disperser groups • State variables: • dogs • age, sex, pack or disperser group, social status • social atatus: • “pup”: age less then one • “yearling”: age between 1 and 2 • “subordinate”: age greater then 2 but dog is not an alpha • “alpha”: dominant sex in a pack • “disperser”: belong to a disperser not a pack • dog packs • list or agent set of dogs • disperser groups: • sex, agnet set of members
NetLogo Code globals [n-telemar] turtles-own [bank-bal] to setup ca ] reset-ticks end to go tick if ticks > yers-to-sim [stop] end
NetLogo Code breed [dogs dog] breed [packs pack] breed [disperser-groups disperser-group] dogs-own [ age sex status my-pack my-disperser-group ] packs-own [ pack-members ] disperser-groups-own [ sex group-members ]
Initialization • 10 packs, no disperser groups • number of dogs in each initial pack • Poisson – mean 5 • sex: uniformly • age: uniform intergers 0 – 6 • social status: according to age • alpha: for each sex, randomly among subordinates
NetLogo code (1) create-packs initial-num-packs [ setxy random-xcor random-ycor set shape "box" let num-dogs random-poisson initial-mean-pack-size hatch-dogs num-dogs [ set headıng random 360 fd 1 ifelse random-float 1.0 < 0.5 [set sex "male" ] [set sex "female"] set age random 7 set my-pack myself set-my-status ] ; end hatch-dogs
NetLogo code (2) set pack-members dogs with [my-pack = myself] update-pack-alphas ] ; end of create-packs
set-my-status to set-my-status ; dog procedure if age = 0 [set status "pup"] if age = 1 or age = 2 [set status "yearling"] if age > 2 [set status "subordinate"] end
update-pack-alphas to update-pack-alphas let can-alpha-males pack-members with [sex = "male" and status = "subordinate"] if any? can-alpha-males [ ask one-of can-alpha-males [set status "alpha"] ] let can-alpha-females pack-members with [sex = "female" and status = "subordinate"] if any? can-alpha-females [ ask one-of can-alpha-females [set status "alpha"] ] end
setup set years-to-sim 100 set carry-cap 60 set initial-num-packs 10 set initial-mean-pack-size 5
Process Overview and Scheduling (1) • 1- age and social status updates • age is incremented • social status is updated • each pack updates its alpha • if not having an alpha a subordinate is selected • 2- Reproduction • alpha male and female or no reproduction • N: total number of dogs – not newly born • carrying capacity: 60 • P: probablity of reproduction • P = 0.5 when N is 0.5 of carrying capacity • P = 0.1 whn N is carrying capacity
3-Dispersal • if nosubordinate – no disperser groups • if one subordinate withprob 0.5 for a disperser group of one member • if more then one subordinates of thesame sex – always form a disperser group • dogs no longer belong to pach • 4- Dog mortality probabilities: • 0.44: disperser 0.25: yearlings, 0.2: subordinates and alphas, 0.12: pups • 5- Mortality of collectives: • no member then collective dies • for packs only pups die ansd packs removes
6- Form pack • disperser groups with opposit sex and from different packs • how namy times a group meets another • poisson number of other groups • if meets 64/% forms a pack • set status to disperser • update alpha • remove disperser groups • 7-outputs • plots of number of dogs, disperser groups and packs
NetLogo Code - go to go tick if ticks > years-to-sim [stop] ask dogs [ set age age + 1 set-my-status ] ask packs [update-pack-alphas] ask packs [reproduce]
NetLogo Code - submodels ask packs [ disperse ] ask dogs [ do-mortality ] ask dogs [ do-mortality ] ask packs [ do-pack-mortality ] ask disperser-groups [ if count group-members = 0 [die] ] ask disperser-groups [ do-pack-formation ] update-output end
reproduce to reproduce if ( any? pack-members with [status = "alpha" and sex = "male"] ) and ( any? pack-members with [status = "alpha" and sex = "female"] ) [ let n-dogs count dogs let p logistic-func n-dogs if random-float 1.0 < p [ let num-new-pups random-poisson 7.9
reproduce hatch-dogs num-new-pups [ set headıng random 360 fd 1 ifelse random-float 1.0 < 0.55 [set sex "male"] [set sex "female"] set age 0 set status "pup" set my-pack myself set pack-members (turtle-set pack-members self) ] ; end of hatch ;set pack-members dogs with [my-pack = myself] ] ; reproduce ] ; any alpha end
logistic-func to-report logistic-func [num] let z a + b * num report ( exp z ) / ( 1 + exp z) end
add to setup set d ln (0.1 / 0.9) set x2 carry-cap / 2 set x1 carry-cap set b d / ( x1 - x2 ) set a d - ( b * x1 )
do-mortality to do-mortality if random-float 1.0 < pup-mortality-rate and status = "pup" [die] if random-float 1.0 < yearling-mortality-rate and status = "yearling" [die] if random-float 1.0 < subordinate-mortality-rate and status = "subordinate" [die] if random-float 1.0 < alpha-mortality-rate and status = "alpha" [die] if random-float 1.0 < disperser-mortality-rate and status = "disperser" [die] end
add to setup set pup-mortality-rate 0.12 set yearling-mortality-rate 0.25 set alpha-mortality-rate 0.20 set subordinate-mortality-rate 0.20 set disperser-mortality-rate 0.44
do-pack-mortality to do-pack-mortality if count pack-members = 0 [die] if count pack-members = count pack-members With [status = "pup"] [ ask pack-members [die] die ] end
disperse (1) to disperse let my-subordinates pack-members with [status = "subordinates"] if not any? my-subordinates [stop] if count my-subordinates with [sex = "female"] = 1 [ if random-float 1.0 < 0.5 [ create-disperser-group-from my-subordinates with [sex = "female"] ] ] if count my-subordinates with [sex = "female"] > 1 [ create-disperser-group-from my-subordinates with [sex = "female"] ] if count my-subordinates with [sex = "male"] = 1 [ if random-float 1.0 < 0.5 [ create-disperser-group-from my-subordinates with [sex = "male"] ] ]
disperse (2) if count my-subordinates with [sex = "male"] = 1 [ if random-float 1.0 < 0.5 [ create-disperser-group-from my-subordinates with [sex = "male"] ] ] if count my-subordinates with [sex = "male"] > 1 [ create-disperser-group-from my-subordinates with [sex = "male"] ] end ; to disperse
create-disperse-group-from (1) to create-disperser-group-from [some-dogs] hatch-disperser-groups 1 [ set group-members some-dogs set sex [sex] of one-of some-dogs set shape "car" set headıng random 360 fd 2
create-disperse-group-from (2) ask some-dogs [ set my-disperser-group myself set status "disperser" set color green move-to my-disperser-group set headıng [headıng] of my-disperser-group fd 1 + random-float 2 ] ; end of ask some-dogs
create-disperse-group-from (3) let dogs-former-pack [my-pack] of one-of some-dogs ask dogs-former-pack [ set pack-members pack-members with [status != "disperser"] ] end
to do-pack-formation let num-groups-met random-poisson count ( disperser-groups ) - 1 repeat num-groups-met [ let can-group-merge one-of other disperser-groups if any? can-group-merge [ if [sex] of can-group-merge != [sex] of myself and ( [my-pack] of one-of [group-members] of can-group-merge = [my-pack] of one-of [group-members] of myself ) and random-float 1.0 < 0.64 [merge-disperser-groups myself can-group-merge] ] ] end
merge-disperser-groups to merge-disperser-groups [disperser-group1 disperser-group2] hatch-packs 1 [ set pack-members [group-members] of disperser-group1 set pack-members (turtle-set pack-members [group-members] of disperser-group2 ) ask pack-members [ set status "subordinate" set my-pack myself update-pack-alphas ] ] ask disperser-group1 [die] ask disperser-group2 [die] end