Fundamentals of NetLogo · 2018-04-02 · Fundamentals of NetLogo. What is a Model? ... It is the...

Post on 11-Jul-2020

2 views 0 download

Transcript of Fundamentals of NetLogo · 2018-04-02 · Fundamentals of NetLogo. What is a Model? ... It is the...

BillRand AssistantProfessorofBusinessManagement

PooleCollegeofManagementNorthCarolinaStateUniversity

Fundamentals of

NetLogo

WhatisaModel?

Anabstracteddescriptionofaprocess,object,oreventExaggeratescertainaspectsattheexpenseofothers

“Essentially,allmodelsarewrong,butsomeareuseful” (GeorgeBox,1987)

WhatisanAgent-BasedModel?Anagentisanautonomousindividualelementwithpropertiesandactionsinacomputersimulation

Agent-BasedModeling(ABM)istheideathattheworldcanbemodeledusingagents,anenvironment,andadescriptionofagent-agentandagent-environmentinteractions

ToolkitsforABM

WhyareweusingNetLogo?

NetLogoisapremieragent-basedmodelinglanguageanddevelopmentenvironment,designedbyUriWilenskyatNorthwesternUniversity.

ItisthemostwidelyusedABMenvironment.

It’stheeasiesttolearn.

TheNetLogoDesignPrinciple• Lowthreshold

– Novicescanbuildsimplemodelsatfirstuse– Pre-collegiatecurriculumincludescomplexsystemsandmodeling– Universitycoursestoincludemodel-basedinquiry– NewsandMediatoincludemodelsasevidenceforarguments

• Highceiling– Languageshouldbeexpressiveenoughtoenablehighendcomplex

models– Researchersto“read/write”andpublishmodels– Narrow/eliminategapbetweenmodelerandprogrammer– Enableinteractivedevelopmentandresearch– Easytosharemodels– Easytoverifyand/orchallengemodels

TheBirthoftheTurtle

Logowasfirstdevelopedin~1969bySeymourPapertandcolleagues

ClimateandEarthModeling

PoliticalScience

RecommendedBook

• AnIntroductiontoAgent-BasedModeling• UriWilenskyandWilliamRand

• AvailableatMITPressandAmazon

https://mitpress.mit.edu/books/introduction-agent-based-modeling

http://www.intro-to-abm.com/

TheTabs

• ThreeTabs• Interface• Info• Code

InfoTab

• WhatisIt?• HowItWorks• HowtoUseIt• ThingtoNotice• ThingstoTry• ExtendingtheModel• NetLogoFeatures• RelatedModels• CreditsandReferences

InterfaceElements

• Button• Slider• Chooser• Switch• Input• Monitor• Plot• Output• Note

RunningAModel

• Setup• Go• SpeedSlider

ModelSettings

• WorldSize• Wrapping

TurtleRelevantCommands

• create-turtles(crt)• ask• forward(fd),backward(bk)• left(lt),right(rt)• repeat• color,size,xcor,ycor• pen-down(pd),pen-up(pu)• clear-all(ca)• monitor• die

Patches

• Inspector• PatchColorispcolor• Turtlescandirectlyaccesspatches• RelevantCommands

• setxy,facexy• random-xcor(pxcor)andrandom-ycor(pycor)

Links

• Creating-create-link(s)-with/to/from• Linkshavetheirownproperties

CodeTab

• creatingaprocedure• toandend

• findingprocedures• indentation• checkingcode

SavingandDocumentingYourCode

• SaveOften• Savemajorchangeswithanewname• EdittheInfoTabatthesametime

CollectionsofAgents

• Built-InCollections• patches,turtles,links• turtles-here,in-link-neighbors

• AgentBreeds• influentials,imitators• canhavetheirownproperties

• Agentsets• with• turtles-on

SimpleEconomy• In1996,JoshEpsteinandRobAxtellpublishedoneofthefirst

definitivebooksonagent-basedmodelingandsocialsciencecalled“GrowingArtificialSocieties”,whichwaspopulatedbyartificialeconomicagents

• Wearegoingtocreateasimplemodelofeconomicsagents,inspiredinpartbyEpsteinandAxtellandapaperbyDragulescuandYakovenko(2000)

• TheRules:• 500peoplestartoffwith$100each• Ateverytickeachpersongives$1toanotherpersonrandomly• Ifyourunoutofmoneyyoucan’tgiveanymoremoneyaway

untilsomeonegivesyoumoney• Whatwillthefinaldistributionofwealthbe?

ControllingNetLogoCode

• setupandgoarenotrequired,butareNetLogostyle

• Othercommands:• tick• if,ifelse• repeat• while

SettinguptheWorld

Thesetupprocedureturtles-own[wealth]

tosetup

clear-all

create-turtles500[

setwealth100

setshape"circle"

setcolorgreen

setsize2

;;visualizetheturtlesfromlefttorightinascendingorderofwealth

setxywealthrandom-ycor

]

reset-ticks

end

Thegoprocedure

togo;;transactandthenupdateyourlocationaskturtleswith[wealth>0][transact];;preventwealthyturtlesfrommovingtoofartotherightaskturtles[ifwealth<=max-pxcor[setxcorwealth]]tickend

transact

totransact;;giveadollartoanotherturtlesetwealthwealth-1askone-ofotherturtles[setwealthwealth+1]end

CreatingtheHistogram

Isthisananomaly?

• BehaviorSpacecanhelpwiththe

• Canalsohelpwithparametersweeps

• Theoutputisa.csvfilethatcanbepulledintoanyanalysissoftware

ThankYou@billrand

wrand@ncsu.edubillrand.org