Agent-Based Modeling and Simulation (ABMS) Bertan Badur badur@boun.edu.tr Department of Management Information Systems Boğaziçi University Thetelemarketer Model • Chapter 13, 14, of Agent-Based and IndividualBased Modeling: A Practical Introduction, by S. F. Railsback and V. Grimm • NetLogo User Menual Outline • 13. 4. The Telemarketer Model • ODD Description • Purpose • Entitie, States Variables, and Scales – patches – poterntial customers • called in one time step – boolean – color black or red – turtles – telemarketers • location – xcor, ycor • size – staff, telephone,... • bank-balance – money – Time – weeks 200 steps – no wraping in x and y, max-x 200, max-y 200 NetLogo Code globals [n-telemar] turtles-own [bank-bal] to setup ca set n-telemar 200 crt n-telemar [ set bank-bal 0.0 ] reset-ticks end to go tick if ticks > 200 [stop] end Process Overview and Scheduling (1) • For actions in each time step • First: set calling “no” – with a color • Second: sales – make sales – order is important – each time random – call customers in radius proportional with size – if a customer not called previously in the same week – then buy – else not buy Process Overview and Scheduling (1) • Third: accounting – – – – – revenue form sales fixed cost proportionla with size update bank balance updete size if bank balance is high enough die if bank balance is lessw then 0 • Forth: output – marketers in business at each time – size distribution and total sales NetLogo Code - go to go tick if ticks > 200 [stop] ask patches [set pcolor black] ask turtles [ sales account ] output end NetLogo Code - submodels to sales end to account end to output end Design Concepts • • • • • • • • Basic principles Emergence Adaptive behavior Prediction Sensing Interraction Stochasticity Observation Initialization • Telemarketers: – – – – – bank balance 0.0 size 1.0 color random lacation random chape circle • Potential customers: – called no – color black NetLogo code to setup ca set n-telemar 200 crt n-telemar [ set bank-bal 0.0 set sıze 1.0 setxy random-xcor random-ycor set shape "circle" ] ask patches [ set pcolor black ] reset-ticks end Submodels - sales • • • • • • • • • • radius: 10 times square root of size max number of calls: 100 times size if potential cust > nax number of calls select nax number of calls of them else select all of them if poterntial customer is not called sell to the poterntial customers change its call to yes – color to red NetLogo code - sales to sales let radius 10 * sqrt sıze let max-call floor ( 100 * sıze ) let pot-custs patches in-radius radius if count pot-custs > max-call [ set pot-custs n-of max-call pot-custs ] ask pot-custs [ if pcolor = black [ set pcolor red ] ] end . Submodels - account • • • • • cost: 50 times size income: 2 times succesful sales update bank balance if bank balance is greater then growth param bank balance – growth param is used to increase size • size is added: excess money times 0.001 • if size less then zero • the telemarketer goes out of business NetLogo code - updates globals [n-telemar growth-param size-param ] turtles-own [bank-bal n-sales] to setup ca set growth-param 1000 set size-param 0.001 • add tot the sales set n-sales count pot-custs with [pcolor = black] ... NetLogo code - account to account let cost 50 * sıze let income 2 * n-sales set bank-bal bank-bal + income - cost if bank-bal > growth-param [ set sıze sıze + size-param * ( bankbal - growth-param ) set bank-bal 1000 ] if bank-bal < 0 [ die ] end Submodels - output • number of telemarketers • size and bank balance distribution • add a ploter plot count turtles 5. Direct Interraction: Mergers in the Telemarketing Model • update balance depends on have a parent or not • if bank balance less then zero and not have a parent • select a parent with • size greater then ist own size and • bank balance greater then its deficit • or go out of business • if balance < 0 and have a parent • get subsidize or die netLogo code – account modififed to account let cost 50 * sıze let income 2 * n-sales let profit income - cost ifelse parent != nobody [ set bank-bal bank-bal + 0.5 * profit ask parent [set bank-bal 0.5 * profit ] ] [ set bank-bal bank-bal + profit ] if bank-bal > growth-param [ set sıze sıze + size-param * ( bank-bal growth-param ) set bank-bal 1000 ] netLogo code – account modififed if bank-bal < 0 and parent != nobody [ output-show parent let bank-bal-par [bank-bal] of parent ifelse bank-bal-par > ( -1 * bank-bal ) [ ask parent [set bank-bal bank-bal + [bankbal] of myself ] set bank-bal 0.0 ] [die stop] ] netLogo code – account modififed if bank-bal < 0 and parent = nobody [ let pot-parents other turtles with [ sıze > [sıze] of myself and bankbal > -1 * [bank-bal] of myself ] ifelse any? pot-parents [ set parent one-of pot-parents ask parent [set bank-bal bank-bal + [bank-bal] of myself ] set bank-bal 0 ] [die stop] ] end updates turtles-own [bank-bal n-sales parent] crt to setup ... crt n-telemar [ ... set parent nobody Using links to reach parents • if aparent set a directed link NetLogo code -account to account let cost 50 * sıze let income 2 * n-sales let profit income - cost ifelse any? my-out-links [ set bank-bal bank-bal + 0.5 * profit ask one-of out-link-neighbors [set bank-bal 0.5 * profit ] ] [ set bank-bal bank-bal + profit ] if bank-bal > growth-param [ set sıze sıze + size-param * ( bank-bal - growth-param ) set bank-bal 1000 ] NetLogo code -account if bank-bal < 0 and any? my-out-links [ let bank-bal-par [bank-bal] of one-of out-link-neighbors ifelse bank-bal-par > ( -1 * bank-bal ) [ ask one-of out-link-neighbors [set bank-bal bank-bal + [bank-bal] of myself ] set bank-bal 0.0 ] [die stop] ] NetLogo code -account if bank-bal < 0 and not any? my-out-links [ let pot-parents other turtles with [ sıze > [sıze] of myself and bank-bal > -1 * [bank-bal] of myself ] ifelse any? pot-parents [ create-link-to one-of pot-parents ask one-of out-link-neighbors [set bank-bal bank-bal + [bank-bal] of myself ] set bank-bal 0 ] [die stop] ] end 6. The Customers Fight Back: Remembering Who Cslled • custmers talernce limit • if cals from a marketer exceeds taht limit • reject call NetLogo code - sales to sales let radius 10 * sqrt sıze let max-call floor ( 100 * sıze ) let pot-custs patches in-radius radius if count pot-custs > max-call [ set pot-custs n-of max-call pot-custs ] set pot-custs pot-custs with [pcolor = black] set pot-custs pot-custs with [ accept-call myself] set n-sales count pot-custs ask pot-custs [ set pcolor red ] end NetLogo code – accept-call to-report accept-call [marketer] let num-calls length filter [? = marketer] callerlist set caller-list fput marketer caller-list report num-calls <= tol-lim end NetLogo code – initilalizations patches-own [caller-list tol-lim] to setpu ... ask patches [ set pcolor black set tol-lim 5 + random 16 set caller-list [] ] end