Management Information Systems MIS 643 Agent-Based Modeling and Simulation 2016/2017 Fall Bertan Badur Department of Management Information Systems Boğaziçi University
Outline 1. Introduction 2. Searching Mushrooms in a Forest
Introduction NetLogo User Manual Model Library simple to install and experiment its model library User Manual Tutorials, Interface Guide and Programming Guide Dictionary Model Library code examples
Agents Four kind of agents Moving agents – Turtles Patches – square cells – space in world Links – connect two turtles networks Observer - controler of the model create other agents global variables Each type of agents commands variables – build-in such as color and location user defined – additional observer – gloabal variables
Global Variables Global variables: all agent can read and change environment characteristics model parameters
Primitives build-in procedure or command commands reporters E.g.: tell agents something to do – return void reporters calculte and report something – return a value or list E.g.: mean - reports mean of a list of numbers neighbors - reports list of surrounding patches
Context each pice of code is “in the contxt of ” one kind or occationally more than one kind of agent can be changed during execution E.g.: ask turtles [move]
Accesing variables agents – directly access variables for their own type Exceptions: observer varibles by all agents turtles can access patchs variables they are currenlty on
Searching Mushrooms in a Forest Is there a best strategy for searching mushrooms? observation: mushrooms in clusters An intuitive strategy: scanning an area in wide sweeps upon finding a mushroom turning to smaller scale sweeps as mushrroms in clusters
Searching Mushrooms in a Forest What is large, small sweeps? and How long to search in smaller sweeps? Humans searching pizzas, jobs, low prise goods, peace with neighbors
try different search strategies Purpose: model of the problem try different search strategies Purpose: what search strategy maximizes musrooms found in a given time Ignore trees and vegitables, soil type Musrooms are distributed as clusters mushroom hunter moving point having a sensing radius track of how many mushrooms found how much time passed since last mushroom fouınd
clusters of items (mushrooms) If the agent (hunter) finds an item smaller-scale movement If a critical time passes since last item found switchs back to more streight movement so as to find new clusters of items
Demonstrating Program: Mushroom Hunt File/New File/Save with extension “nlogo” Settings World geometry: 0,0 orgin, max-pxcor=16, max-pycor=16 33x33 squre latice 2 hunters – turtels cluster of mushrooms – red patches all other patches are black setup – initialization go – continuous operations
Create a button executing procedure setup procedures – commands to proc name commands end Create a button executing procedure setup Create a button executing procedure go forever is cheked – forever button write setup procedure code tab
to setup end to go
to setup ask patches [ set pcolor red ] end ask primitive asks selected agents to do actions by commands in brackets set color of all pathces to red set - primitive is assignment pcolor – variable for patches
to setup ask n-of 4 patches [ ask patches in-radius 5 set pcolor red ] end n-of: n-of number ageent set in-radius : agents in-radius number
to setup ask n-of 4 patches [ ask n-of 20 patches in-radius 5 set pcolor red ] end 4 patches are randomly selected for each randomly selected pathc for all patches in radius 5 select 20 randomly set their color to red
clear-all to setup clear-all ;abriviares as – ca - ask n-of 4 patches [ ask n-of 20 patches in-radius 5 set pcolor red ] end clear-all: clear all default values
using parameters globals [ num-clusters ] to setup clear-all set num-clusters 4 ask n-of num-clusters patches ask n-of 20 patches in-radius 5 set pcolor red end
creating 2 hunters - turtles create-tutrles 2 ;crt 2 [ set sıze 2 set color yellow ] create 2 turtles crt or create-tutles build-in turtle variables: size and color
go procedure to go ask turtles [search] end to search ifelse tıme-sınce-last-found <= 20 [right (random 181) - 90] [right (random 21) - 10] forward 1 cifelse boolean condition [ block whan true ] [ block when false ] right: turn right by angle in degrees
algorithm of move if timelast-found <= critical value make a small turn else make a biger turn if found – come on a red patch set timelasf-fournd to 0 set color to yellow increment timelast-found by one
variable for turtles tutrles-own [ tıme-sınce-last-found ] variable for all turtles time passed since last mushroom has found by the hunter
tıme-sınce-last-found initial value crt 2 [ set sıze 2 set color yellow set tıme-sınce-last-found 999 ] initialze tıme-sınce-last-found to a very high value greater then 20
add to the search procedure ifelse pcolor = red [ set tıme-sınce-last-found 0 set pcolor yellow ] set tıme-sınce-last-found tıme-sınce-last-found + 1 end if found pcolor is red set tıme-sınce-last-found to 0 else increment tıme-sınce-last-found by one
command center select turtles write commands hatch 1 [right 160] show count turtles
further modifications adding ticks add reset-ticks to the end of setup add tick to the begining of go following motion of hunters add pen-down to the setup procedute when initilizing turtles