45
Training Types of agents in NetLogo: • Observer • Patches • Turtles • Links Gives instruc=ons from an external points of view Cannot move, have integer coordinates Can move in the “world” Connect two turtles

ask patch 0 0 [ set pcolor green ] - CERES · p1 is not a built-in variable of patches in NetLogo, so we have to define it. Basic simulaon of pest growth and spread in a landscape

  • Upload
    vumien

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

TrainingTypesofagentsinNetLogo:•  Observer•  Patches•  Turtles•  Links

Givesinstruc=onsfromanexternalpointsofview

Cannotmove,haveintegercoordinates

Canmoveinthe“world”

Connecttwoturtles

Training

ask patch 0 0 [ set pcolor green ]

Training

ask patch 0 0 [ set pcolor green ]

Whoisthesubjectofthiscommand?Theobserver

Training

ask patch 0 0 [ set pcolor green ]

Whoisthesubjectofthiscommand?Patch00Inthe[],thepointofviewchanges

Training

ask patch 0 0 [ set pcolor green ]

ask agentset [ do something ]

Training

ask patch 0 0 [ set pcolor green ]

pcolorisabuilt-invariableofpatches,therearemanyotherbuilt-invariables,forexamplepxcorandpycor“green”Isavaluethatpcolorcanhave

Training

ask agentset [ do something ]

Wecannowdefineanother“agentset”Howcanweturnallthepatchesintoblue?

Training

ask agentset [ do something ]

Wecannowdefineanother“agentset”Howcanweturnallthepatchesintoblue?

ask patches [ set pcolor blue ]

Training

ask agentset [ do something ]

Wecannowdefineanother“agentset”Howcanweturnallthepatchesintoblue?

ask patches [ set pcolor blue ]

Patchesisanagentsetthattheobservercanaccess,itrepresentsallthepatchesinthe“world”

Training

clear-all

NowtypeAndrepeatthesamecommandwithreducedspeed.Whatdoyouno=ce?

Training

clear-all

NowtypeAndrepeatthesamecommandwithreducedspeed.Whatdoyouno=ce?Whenacommandisassignedtoanagentset,itisnotexecutedsimultaneouslybyallthecomponentsoftheagentset.ComponentsoftheagentsetexecutethecommandoneaReranotherinrandomorder.

ask agentset [ do something ]

Training

Howtoaskthepatchesintheupperhalfoftheworldtoturntheircolorintoyellow?

ask agentset [ do something ]

Training

Howtoaskthepatchesintheupperhalfoftheworldtoturntheircolorintoyellow?

ask patches with [ pycor > 0] [ set pcolor yellow ]

ask agentset [ do something ]

Training

Howtoaskthepatchesintheupperhalfoftheworldtoturntheircolorintoyellow?

ask patches with [ pycor > 0] [ set pcolor yellow ]

agentset with [ condition ]

ask agentset [ do something ]

Training

Howtoaskthepatchesintheupperhalfoftheworldtoturntheircolorintoyellow?

ask patches with [ pycor > 0] [ set pcolor yellow ]

agentset with [ condition ]

Herethepointofviewbelongstotheagentwithintheagentset.Eachagentknowsitsownpycor.

Training

ask agentset [ do something ]

Howtoturntheneighborsofpatch00intopink?

Training

ask agentset [ do something ]

Howtoturntheneighborsofpatch00intopink?Eachpatchhasabuilt-invariable(anagentset)called“neighbors”

Training

ask agentset [ do something ]

Howtoturntheneighborsofpatch00intopink?Eachpatchhasabuilt-invariable(anagentset)called“neighbors”

ask patch 0 0 [ ask neighbors [ set pcolor pink ] ]

Training

ask agentset [ do something ]

Howtoturntheneighborsofpatch00intopink?Eachpatchhasabuilt-invariable(anagentset)called“neighbors”

ask patch 0 0 [ ask neighbors [ set pcolor pink ] ]

Theobservercandelegatethecommandasktoanagenset

TrainingAskto10randompatchestosetthecolorequaltoBLUE

ask n-of 10 patches [ set pcolor blue]

ask agentset [ do something ]

TrainingAskto10randompatchestosetthecolorequaltoBLUE

ask n-of 10 patches [ set pcolor blue]

ask agentset [ do something ]

TrainingAskto10randompatchestosetthecolorequaltoBLUE

ask n-of 10 patches [ set pcolor blue]

ask agentset [ do something ]

n-of number agentset

Now,SettheneighborsofthebluepatchesRED

Now,SettheneighborsofthebluepatchesREDThenSettheneighborsoftheREDpatchesequaltoREDIFTHEYARENOTBLUERepeatthisla_ercommandoverandover

Basicsimula=onofpestgrowthandspreadinalandscape

Eachpatchischaracterizedby:•  Cul=vatedfrac=onsp1,p2,p3…•  Anormalizeddensityofpests(from0to1)

Weneedtodefinearulefor-  Pestgrowthwithineachpatch-  Pestspreadfromonepatchtoanother

Basicsimula=onofpestgrowthandspreadinalandscape

Assignacul=vatedfrac=ontoeachpatch:Letsassumethatwehaveonlytwotypesofcul=vatedfrac=ons,p1andp2=1–p1.(weonlyhavetoassignp1)p1isnotabuilt-invariableofpatchesinNetLogo,sowehavetodefineit.

Basicsimula=onofpestgrowthandspreadinalandscape

patches-own [ p1 ]

Basicsimula=onofpestgrowthandspreadinalandscape

patches-own [ p1 ]

to setupclear-allask patches [ set p1 random-float 1 ]end

Assigningcul=vatedfrac=onstopatches

patches-own [ p1 ]

to-setupclear-allask patches [ set p1 random-float 1 ]end

Wearetellingtonetlogotoassigntoeachpatchavariablecalledp1

patches-own [ p1 ]

to setupclear-allask patches [ set p1 random-float 1 ]end

ThisisawaytodefineaprocedureinNetlogoItcanbe“called”inthecommandlineoritcanbeassociatedwithabu_on

Assigningcul=vatedfrac=onstopatches

patches-own [ p1 ]

to setupclear-allask patches [ set p1 random-float 1 ]end

Usuallyitisbe_ertowritethisasafirstcommandinasetupprocedure

Assigningcul=vatedfrac=onstopatches

patches-own [ p1 ]

to setupclear-allask patches [ set p1 random-float 1 ]end

random-float n generatesarealnumberbetween0andn.

Assigningcul=vatedfrac=onstopatches

Bycallingtheproceduresetupnothinghappens,why?

Assigningcul=vatedfrac=onstopatches

Bycallingtheproceduresetupnothinghappens,why?Eachpatchhasavalueforp1,itisjustnotvisible.Forexample,type:

ask patch 0 0 [ show p1 ]

Assigningcul=vatedfrac=onstopatches

Bycallingtheproceduresetupnothinghappens,why?Eachpatchhasavalueforp1,itisjustnotvisible.Howtoassignthecolorgreentoallthepatcheswithp1>0.5?

Assigningcul=vatedfrac=onstopatches

Bycallingtheproceduresetupnothinghappens,why?Eachpatchhasavalueforp1,itisjustnotvisible.Howtoassignthecolorgreentoallthepatcheswithp1>0.5? ask patches with [ p1 > 0.5 ]

[ set pcolor green ]

Assigningcul=vatedfrac=onstopatches

patches-own [ p1 ]

to setupclear-allask patches [ set p1 random-float 1 ]ask patches [ set pcolor scale-color green p1 0 1 ]end

Thisassignsashadeofgreenpropor=onaltop1.

Assigningcul=vatedfrac=onstopatches

Now,let’sintroducepests

patches-own [ p1 PESTS ]

to setup…end

Pestpopula=ongrowthineachpatch

Weneedtoassignanothervariabletothepatches

patches-own [ p1 PESTS ]

to setup…ask patch 0 0 [ set PESTS 0.1 ]end

Pestpopula=ongrowthineachpatch

Asadefault,allvariablesareini=alizedto0.Forini=alizing,weneedtospecifyinthesetupfunc=on

patches-own [ p1 PESTS ]

to setup…ask patch 0 0 [ set PESTS 0.1 ]color-patches-pestsend

to color-patches-pestsask patches with [ PESTS > 0 ] [set pcolor scale-color brown PESTS 0 1 ]end

Pestpopula=ongrowthineachpatch

Wecanalsocolorpatchesinordertoshowthedensityofpests

patches-own [ p1 PESTS ]globals [ S R ]

to setup…set S 0.8set R 0.2end

Pestpopula=ongrowthineachpatch

Therearesomeparameterswhicharethesameforallthepatches,sotheyareglobals(theparametersS–survivalandR–reproduc=on)Theirvalueisassignedinthesetupfunc=ondirectlybytheobserver

patches-own [ p1 PESTS ]globals [ S, R ]

to setup…end

to gogrow-pestscolor-patches-pestsend

to grow-pestsask patches [ set PESTS ( S * PESTS + R * PESTS * ( p1 – PESTS) ) ] end

Pestpopula=ongrowthineachpatch

TheproceduregoexecutesaprocedureforgrowingpestsineachpatchandforcoloringpatchesItcanbesetupasaforeverprocedure

patches-own [ p1 PESTS Contagious ]globals [ S, R ]

…To spread-pestsask patches with [ PESTS > 0.2 ][ set Contagious 1 ]end

Pestpopula=onspreadingfrompatchtoneighbors

First,weassumethatPESTScanspreadtoneighborsiftheirdensityofPESTSisgreaterthan0.2

patches-own [ p1 PESTS Contagious ]globals [ S, R ]

…to spread-pestsask patches with [ PESTS > 0.2 ][ set Contagious 1 ]ask patches with [ Contagious = 1 ][ ask neighbors4 with [ PESTS = 0][ set PESTS 0.1 ] ]end

Pestpopula=onspreadingfrompatchtoneighbors

First,weassumethatPESTScanspreadtoneighborsiftheirdensityofPESTSisgreaterthan0.2