23
Network structures and assembling code in Netlogo version 01-09-2018 1 Network structures and assembling code in Netlogo, Tutorial By Tom Brughmans First version: Summer 2018 This version created 01/09/2018 Netlogo version used: 6.0.1 Extension used: nw (pre-packaged with Netlogo 6.0.1) https://ccl.northwestern.edu/netlogo/6.0-BETA1/docs/nw.html Cite this tutorial as: Brughmans, T. (2018). Network structures and assembling code in Netlogo, Tutorial, https://archaeologicalnetworks.wordpress.com/resources/#structures .

Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

1

NetworkstructuresandassemblingcodeinNetlogo,TutorialByTomBrughmansFirstversion:Summer2018Thisversioncreated01/09/2018Netlogoversionused:6.0.1Extensionused:nw(pre-packagedwithNetlogo6.0.1)https://ccl.northwestern.edu/netlogo/6.0-BETA1/docs/nw.htmlCitethistutorialas:Brughmans,T.(2018).NetworkstructuresandassemblingcodeinNetlogo,Tutorial,https://archaeologicalnetworks.wordpress.com/resources/#structures.

Page 2: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

2

1. IntroductionThistutorialprovidesanintroductiontofindingandassemblingpre-existingcodetoquicklycreatecomplexmodels.Itusescodeanddatalinkedtointhehttps://projectmercury.eupages.WewillcreateaRomantransportnetworkbyreusingexistingcodethatdrawsontheopenaccessORBISdataset(http://orbis.stanford.edu/),wewillcreatealternativenetworkstructuresbyreusingexistingcode,andwewillexploretheimpactthesedifferentnetworkstructureshaveinlightofsimpleeconomicprocesses.Thistutorialwillrevealtheimportanceofnotreinventingthewheel,ofsearchingforappropriateexistingcodeandlettingyourmodelbuildingbeinspiredbyothers’previouswork.

2. Conventions,tipsandassumedknowledgeThistutorialassumesbasicknowledgeofNetlogoandofsimulation.ItisrecommendedtowalkthroughtheintroductorytutorialsontheNetlogowebsiteorthetutorialonNetlogoforarchaeologistsontheSimulatingComplexityblog:https://simulatingcomplexity.files.wordpress.com/2014/07/dispersal_tutorial.pdfhttps://ccl.northwestern.edu/netlogo/docs/Thistutorialwillalsorefertosomenetworksciencejargon,conceptsandtechniques.Youcangetabasicdefinitionofallofthesefromtheglossaryonmyblog:https://archaeologicalnetworks.wordpress.com/resources/#glossaryGoodintroductionstonetworkscienceincludethefollowing:

Brandes,U.,Robins,G.,McCranie,A.,&Wasserman,S.2013.Whatisnetworkscience?NetworkScience1(01):p.1–15.Newman,M.E.J.,2010.Networks:anintroduction,Oxford:OxfordUniversityPress.

Codewritteninthistutorialwillbeformattedasinthefollowingexample:breed [nodes node]

Saveyourproject!Dothisregularlyandusemultipleversionsthroughoutthetutorialsothatyoucanfallbackonanearlierversionatanytime.Iwillremindyouregularlythroughoutthetutorialtosaveyourproject.

IfyouarefamiliarwithNetlogo:skiptosection6!

Page 3: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

3

3. DownloadandinstallNetlogoNetlogoisopensourcesoftwareandcanbedownloadedfreeofchargeforWindows,MacOSXandLinux.Gotohttps://ccl.northwestern.edu/netlogo/download.shtml.DownloadtheNetlogoinstaller(thistutorialusesversion6.0.1).RuntheinstallerandinstallNetlogo.

4. Netlogoresources,manualandinterfaceNetlogohasgreatdocumentationaboutallitsfeaturesandcodeinitsusermanual:https://ccl.northwestern.edu/netlogo/docs/Thismanualincludestutorials,areferencetothesoftwarefunctions,adictionarytoitsprogramminglanguage,documentationofitsextensionsandmuchmore.Additionalexternalresourcescanbefoundontheresourcespage:https://ccl.northwestern.edu/netlogo/resources.shtmlAdetailedreferencetoNetlogo’sInterfacecanbefoundhere:https://ccl.northwestern.edu/netlogo/docs/ThistutorialwillonlygiveaverybriefintroductiontothekeyelementsoftheNetlogointerfaceyouwillbeusingthroughoutthetutorial.

Page 4: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

4

WhenyouopenNetlogoitshouldlooksomethinglikethis:

Ithasthreetabs:Interface,Info,Code.TheInterfacetabiswhereyouwatchyourmodelrun.Throughoutthetutorialyouwilladdbuttonsandsliderstocontrolthevariablesofyourmodel,andyouwilladdmonitorsandplotstoinspectwhatyourmodelisdoing.Youcanspeeduporslowdownthesimulationusingthespeedslideratthetopoftheinterface.Thecommandcenteratthebottomwilldisplaymessagesyouaskthemodeltoproduce,andyoucanalsouseittogivetocommandstothemodelfromtheinterfacetab.

Page 5: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

5

TheInfotabiswhereyoudescribeyourmodelusingastandardizedsetofquestions.Addingthisinformationwhenyoushareyourmodelwithotheriscrucialtoenablethemtoworkwithyourmodel.WewillnotworkwiththeInfotabinthistutorial.

TheCodetabiswhereyouwriteandstorethecodeforthemodel.InthistutorialwewillbemainlyworkingintheCodetab.AusefulfeatureistheCheckfunctionatthetopofthistab:clickthistoletNetlogocheckyourcodeforerrors.Ifitfindserrorsthenyouwillbeguidedtotheerrorandaskedtoresolveitbeforeyoucancontinue,ifitdoesnotfinderrorsthenyoucanproceedwithcodingorviewingyourmodelinaction.NOTE:thiserrorcheckeronly

Page 6: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

6

checkswhethertheprimitivesusedandtheorderofthecodecomplywiththeNetlogorules(i.e.thecode’svocabularyandgrammar).Itwillnotcheckwhetherthecodedoeswhatyouwantittodo,sogettingnoerrorsisnoguaranteethatthecodeworksthewayitshouldorthewayyouthinkitdoes.Theerrorcheckerwillalwaysneedtobeusedalongsideothererrorcheckingtechniques,likereportingvariablevaluesandcheckingthemagainstexpectations,ortestingsubmodelsindependently.

5. NetlogodictionaryAcrucialresourcewhencodinginNetlogoisitsdictionary:https://ccl.northwestern.edu/netlogo/docs/Forthistutorial,youwillfindthesectionon‘Links’intheNetlogodictionaryparticularlyuseful,aswellasthedocumentationofthe‘nw’extension.Youcangetdirectaccess(evenoffline)totheentryaboutaparticularprimitivebyright-clickingitandselectingQuickHelp.

Page 7: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

7

6. CreateaworkingfolderMakeafolderonyourcomputercalled‘network_structures’.Allcodeanddatawewilluseandthemodelwewillcreatewillbesavedinthisfolder.WhenimportingdataintoNetlogomodels,aswewilldointhistutorial,itiscrucialthatalldatausedinthemodelissavedinthesamelocationasthemodelitself.

7. Whyassemblecode?Whenwritinganacademicpaper,theactofcopyingentireparagraphsfromotherscholars’papersintoyourownpaperiscalledplagiarism.Insoftwaredevelopment,however,itisstandardpracticetosharesnippetsofcomputercodeorentiresoftwareprogrammes,andallowcolleaguestocopypartsofittomakeneworiginalsoftware.Thisprocessallowssoftwaredeveloperstoquicklyovercometechnicalcode-relatedroadblocks,todevelopnewsoftwarereallyfastandtobuildhugeprogrammingresourcesasacommunityeffort.Ofcourse,itisalsoconsideredgoodpracticetoreferenceimportantbitsofcopiedcodeinyourowncode,andtomakeyourowncodeopenlyaccessibletothecommunity.Thistutorialaimstoteachyouhowthiscanbeusefullydoneforthecaseofcreatingagent-basedmodelsoftheRomaneconomy,byusingresourcesfromhttps://projectmercury.eu.FormalmodellinginRomaneconomystudiesisnotcommonpracticeandthecommunityofcodersinthissubdisciplineisrathersmall.Thedevelopmentofcritical,usefulandmoremodelswouldbeseriouslyenhancedifcodesharing,reuseandaccreditationbecomemorecommonpractice.Moreover,oursmallcommunitycandrawonthemanyresourcescreatedbyothercommunitieswithinwhichagent-basedmodellingismorecommonpractice,suchasbehaviouraleconomicsandthesocialsciencesingeneral.ProjectMERCURYhostsamodellibrarylistingformalmodellingcodeinRomanstudies,andaparticularlyusefulresourceistheCOMSESOpenABMrepositoryofsocialsciencemodels(whichincludesafewarchaeologymodelsandahugenumberofeconomicsmodels):

• https://projectmercury.eu/model-library/• https://www.comses.net

ItiscrucialtorealisethatincomputationalmodellingofRomaneconomyhypothesestheaimisnottodevelop100%originalandelegantcomputationallyefficientcode.Wearenotcomputerscientists,butarchaeologistsandhistorians:weaimtomakeappropriateformalcomputationalrepresentationsofkeyhypothesesinRomanstudies.Beingabletodothisfasterandmorecriticallyonatechnicallevelbydrawingontheresourcesofacodingcommunityisinvaluableinachievingthisaim.ItallowsRomaniststofocusontheirexpertise,whichistheappropriaterepresentationandstudyofRomandataandtheories,ratherthanbeingboggeddowninthetechnicalitiesofwritinggoodcode.

8. Ourhypothesis:RomannetworksForthistutorialwewillstudythefollowingabstracthypothesis:

TheRomanimperialtransportsystemstructuredtheflowofgoodsinsuchawaythatwealthinequalitybetweenurbancommunitiesthroughouttheempirewasenforced.

Page 8: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

8

ThishypothesisisformulatedwiththeaimofbetterunderstandingtheeffectsofthephysicalroutesconnectingurbansettlementsduringtheRomanEmpireontheflowofgoods.DidsomeurbansettlementsoccupyapositionontheRomantransportsystemthatallowedtheircommunitiestoaccessandaggregatefarmoregoodsthanothercommunities?IsthisphenomenonofwealthinequalityaparticularfeatureoftheRomantransportsystemstructure,orcanothernetworkstructuresenforcemoreextremewealthinequalitymuchfaster?Becausethisisonlyatutorial,wewillnotspecifyordebatethishypothesisanyfurtherhere.However,itiscrucialtorealisethatinactualresearchofthetopicsuchhypotheseswouldemergethroughliteraturereviewanddataanalysis.Itisalwayscrucialtoprovideargumentswhyahypothesisisfeasibleandhowitdiffersfromotherpreviouslyformulatedhypotheses.Theresultsofformalcomputationalmodellingstudiesofsuchhypotheseswillalwaysneedtobereinsertedintothesesubstantivedebates,otherwisewearejustmakingcomputationalmodelsforthesakeofit.Fornow,considerthisaninterestinghypothesisthatlendsitselfwelltobeingexploredthroughformalcomputationalmodelling.Wewillfocustherestofthistutorialonhowthehypothesiscanbequicklyandappropriatelyrepresentedusingthecodeanddataaccessbileviahttps://projectmercury.eu.

9. ARomantransportnetworkThefirstthingweneedtodoisidentifyadatasetwecanusetorepresenttheRomanimperialtransportsystem.WewilluseORBIS,theStanfordGeospatialNetworkModeloftheRomanWorld(http://orbis.stanford.edu).Itisacoarse-grainedrepresentationofthemajorterrestrialandmaritimeroutesconnectingthemajorsettlementsacrosstheRomanworld.CheckouttheORBISwebsiteifyouwanttolearnmoreaboutit,orreadthefollowingpublications:

• http://orbis.stanford.edu/assets/Scheidel_64.pdf• http://orbis.stanford.edu/assets/Scheidel_59.pdf

WhatismostcrucialforthistutorialisthattheORBISmodelcanbereusedwithaccreditationforresearchpurposes.ItoffersagreatstartingpointforstudiesoftheRomanworldthatconcernflowsofgoods,ideasandpeople.InthistutorialwewilluseanetworkdatarepresentationofORBISinthe.graphmlformat.ItwascreatedfromthedatamadeopenlyaccessiblebytheORBISteam,listedhere:https://projectmercury.eu/datasets/#orbis

10. NetlogocodeimplementingORBISORBISistheonlydigitaldatarepresentationoftheentireRomanworldduringimperialtimesthatcanbeeasilyreusedforcomputationalmodellingwork.Assuch,ithasbeenwidelyusedbyRomanists,inparticularforagent-basedmodelscodedinNetlogo.ThereisthereforenoneedforustofigureoutfromscratchhowtoimportthemodelintoNetlogo,itwouldbemucheasiertofindapre-existingNetlogomodelthatdoesthis,criticallyassessitandcopytherelevantcode.

Page 9: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

9

InthistutorialwewillusecodecreatedbyprojectMERCURY.GototheMERCURYmodellibraryandnavigatetothemode‘ORBIS:importingaRomantransportsystem’:https://projectmercury.eu/model-library/ThiswilltakeyoutotheCOMSESOpenABMmodelrepositorywherethiscodearchived.Beforedownloadingthisresource,itiscrucialtocheckwhetheranyinformationisprovidedaboutthereuselicense.Scrolldownandclickonthe‘Details’tab.YouwillseethelicenseisspecifiedasCC-BY-3.0whichmeansyoucancopy,redistribute,remix,transform,andbuilduponthematerialforanypurpose:aslongasyougiveappropriatecredit.https://creativecommons.org/licenses/by/3.0/Downloadthemodel:

Youwilldownloadafolderwhichholdsafewsubfolders.Copythefollowingfilesintoyourworkingfolder‘network_structures’:

• Fromthefolder‘code’copy‘Roman-transport.nlogo’.Thisisthemodelfromwhichwewillcopycode.

• Fromthefolder‘data’copy‘orbis.graphml’.Thisistheorbisnetworkdatasetwhichisrequiredasinputdataforthemodeltowork.

Nowthatyou’vedownloadedsomecodeanddata,it’stimetoputyouracademichatbackonandcriticallyassesstheinformationyoudownloaded.Openthemodel‘Roman-transport.nlogo’inNetlogoandfamiliarizeyourselfwiththecode.Checkwhatproceduresareincludedandhowtheywork,identifywhichproceduresyouneedtocopyandcheckthattherearenoerrors,explorehowthiscodewillneedtobemodifiedtoworkforyourcurrentpurposes.Applythesamescrutinytothedownloadeddataset‘orbis.graphml’.Whatsourcewasthedataderivedfrom,canitbereused,howwasitmanipulated,doesitrepresentthekindorinformationyouneed?Wewillassumeforthesakeofthistutorialthatthecodeanddataareappropriateandusefulresourcesformakingyourownmodel.Sonowyouhaveyourfirstbuildingblocks,let’sstartbuildingyourmodel!

Page 10: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

10

11. CopyingnetworkimportproceduresCreateanewmodelinNetlogoandsaveitinyourfolderas‘network_structures.nlogo’.Openthemodel‘Roman-transport.nlogo’youjustdownloadedinNetlogo(notethatifyouareworkingonaWindowsmachineyoucansimplyopenmultipleinstancesofNetlogosimultaneouslytocomparecode.However,ifyouareworkingonaMacyouwillneedtohavemultipleinstancesoftheNetlogoapplicationinstalledinordertoopenmultiplemodelsatthesametime.Todothis,gototheapplicationsfolderandcopy/pastethefolder‘Netlogo6.0.1’.YoucannowopenboththeoriginalapplicationofNetlogoandthecopiedapplication).Wewillnowreviewthecodeandlistallelementsthatweneedforourownmodel:

• Thefirstfewlinesfromextensionstoturtles-ownalllistcodethatisrequiredtoimportthenetworkdataset,sowewillneedtocopythis.

• Thesetupprocedureincludestheactualcodethatimportsthedataset,weobviouslyneedthat.Wedefinitelyneedtheprocedure‘data-correction’.Wedon’tnecessarilyneedtheprocedure‘visualise’whichiscalledinthesetupprocedureandthecodeofwhichiswrittenfurtherdowninthemodel,butitmightbeusefultocopythisanywaystomaketheimportedmodellookmorecomprehensible.

• Allotherproceduresfurtherdowninthecodearefortheanalysisandvisualisationofthenetwork,andarethereforenotcrucialforourcurrentaims.

Copyallthecodeyouneedandpasteitintoyournewmodel.Yourmodelshouldnowlooklikethis:

Saveyourmodel!Thereshouldbenoerrorswhenyoupressthe‘check’button.Sowecangoaheadandmodifytheinterfaceofourmodeltocheckwhetherourcodeworks.

Page 11: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

11

GototheInterfacetabandcreateabuttonwiththesetupcommand:

Whenyouclickthesetupbuttonforthefirsttimeyouwillnoticethatalldataiscorrectlyimported,butalsothatthereissomethingwrongwiththeNetlogoworldshowninthescreen:

Thisissueiscausedbyusnothavingcopiedthesettingsofworldsettingsfromtheoriginalmodel.Todothiswewillopentheworldsettingsinboththeoldandnewmodel,andensuretheyarethesame.Rightclickontheworldintheoldmodelandselectedit,dothesameforthenewmodel,andpositionthetwosidebysideonyourscreen:

Page 12: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

12

Modifythesetwoscreenssuchthatthesettingsarenowthesame:

Clickokandclickthesetupbuttonagain.Yournetworkshouldnowbedisplayedcorrectly:

Page 13: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

13

YouhavesuccessfullyimportedtheORBISdataset!Surelythiswasmuchfasterthanhavingtofigureoutallofthisforyourself.Nowwecancontinuetoaddasimpleeconomicprocesstoexploreourhypothesis.Saveyourmodel!

12. TradingpotsoverthenetworkWewillnowwriteaveryabstractandsimpleeconomicprocessthattakesplaceonthisnetwork.Weareinterestedinexploringwhatthestructuringeffectofthenetworkisonsucheconomicprocesses.WewillassumeeachurbansettlementintheORBIStransportsystemisamarketthatbehavesasanindividualeconomicactorandcantradepotterywithotheractors.Althoughthemodelwecreateinthistutorialissogenericthatthegoodscouldbecalledanything,wechoosetocallthempotterytoillustratehowwecansimulateartificialarchaeologicaldatathatcanbecomparedwithactualobservedarchaeologicaldatainfuturework.Wewillgiveallturtles(whichiswhatthesettlementsarecalledinourcode)acertainamountofpotsandeverytick(Netlogojargonfortimestep)allpotsinthemodelwillbeconsideredfortrade.Tokeepitsimple,wewilljustassumethatallturtleswanttosellthepotstheyown,wanttoobtainnewitems,andthatatransactionissuccessfulwithacertainprobability.First,wewillcreateavariablefortheturtlescalledpotsbyaddingitatthetopofthecode:

turtles-own [ pots node-id x y modern province rank town-name ]

Page 14: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

14

Second,wewillgiveallturtlespotsduringthesetupprocedurebyaddingthefollowingcodeattheendofthesetupprocedurebetweenvisualiseandreset-ticks:

visualise ask turtles [set pots round ( num-pots * size )] reset-ticks end

ThiswillgiveeachsettlementanumberofpotsproportionaltoitsrankaccordingtotheORBISdataset(eachsettlementhasadifferentrankofimportanceinORBIS(takenfromtheBarringtonAtlas),andinthevisuaseprocedurethesizeofeachsettlementismadeproportionaltotheirrank).Notethatwejustmentionedanewvariablecallednum-pots,soNetlogowillgiveusanerrorandwewillneedtoaddaslidertocontrolthisvariableintheInterfacetab:

• SelectSliderfromthedropdownbox.• Clickthe‘Add’button.• Clickanywhereinthewhitespace.Anewwindowwillappearwhereyoucan

determinewhatthesliderwilldo.• Writenum-potsinthe‘Globalvariable’box,settheminimumto0,theincrementto

1,themaximumto100andthevalueto50.ClickOK.

Nowwhenyouclickthesetupbuttonallturtleswillbegivenasmanypotsasdefinedbythevariablenum-pots Third,wewillcreateanewprocedurethatdetermineswhatprocesseswilltakeplacewhenthemodelruns.Sofarwehaverestrictedourselvestodetermininghowthemodelissetup,andnowwewilldeterminewhathappensafterthatforeverytick(timestep).Addaprocedurecalledgobywritinginyourcodebelowthesetupprocedurethefollowing:

to go tick end

Thecommandtickwillincreasethenumberoftimestepsofthemodelbyoneeverytimethegoprocedurehappens.TousethegoprocedurewewilladdabuttonforitontheInterfacetab:

• SelectButtonfromthedropdownbox.• Clickthe‘Add’button.• Clickanywhereinthewhitespace.Anewwindowwillappearwhereyoucan

determinewhatthebuttonwilldo.

Page 15: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

15

• Writegointhe‘Commands’boxand‘goonce’inthe‘Displayname’box.ClickOK.

Youhavejustaddedabuttonthatwillrunthegoprocedureonceeverytimeyouclickit.Ifyoudoso,youwillnoticethatthenumberofticksintheInterfacewindowwillincreasebyoneeachtime.Youmightalsowanttocreateasecondbuttonthatrunsthegoprocedurecontinuouslyuntilyouaskittostop:

• SelectButtonfromthedropdownbox.• Clickthe‘Add’button.• Clickanywhereinthewhitespace.Anewwindowwillappearwhereyoucan

determinewhatthebuttonwilldo.• Writegointhe‘Commands’boxand‘go’inthe‘Displayname’box.Makesurethe

‘Forever’boxisticked.ClickOK.

Youhavenowcreatedabuttonthatwillcontinuouslyrunthegoprocedure.Fourth,wewillstartaddingmoreinterestingtrade-relatedcommandstothegoprocedure,beginningwithacountofthetotalnumberofpotsduringanyonetick.Inthismodelthissumwillbethesameforeverytickwithinasinglesetup,butwewilladdthissumincaseyoudecidetomodifythemodelbyallowingpotstobeaddedorremovedfromthemodel.Writethefollowinginthegoprocedurebeforetick:

let total-pots sum [pots] of turtles

Fifth,nowthatweknowhowmanypotsthereareinthistickwecanrepeattradeasmanytimesastherearepotsbyaddingthefollowingcodeinthegoprocedureimmediatelyafterthesumofallpots:

repeat total-pots [ ]

Everycommandthatwenowaddwithinthesebracketswillberepeatedasmanytimesastherearepotsatthestartofthattick.Sixth,wewillrandomlyselectaturtlewhichhasatleastonepot,i.e.aturtlethatcantrade:

repeat total-pots [ ask one-of turtles with [pots > 0] [] ]

Page 16: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

16

Seventh,wewillaskthisnodetoperformatransaction(sellapottoanothernodeitisconnectedto)withacertainprobability.Wewillusethesametechniqueasweusedearlierforimplementingprobability:checkingwhetherarandomlyselectednumberishigherorlowerthanavariablerepresentingthetradeprobability.Addthefollowingtotheaskcommandwejustwrote:

ask one-of turtles with [pots > 0] [if random-float 1 < trade-probability [] ]

Thiscodewillperformanactiononlyifarandomlyselectedfloatingpointnumberbetween0and1issmallerthanthevaluewesetforthevariabletrade-probability.Let’screateasliderforthisnewvariableintheInterfacetab:

• SelectSliderfromthedropdownbox.• Clickthe‘Add’button.• Clickanywhereinthewhitespace.Anewwindowwillappearwhereyoucan

determinewhatthesliderwilldo.• Writetrade-probabilityinthe‘Globalvariable’box,settheminimumto0,the

incrementto0.05,themaximumto1andthedefaultvalueto0.5.ClickOK.

Finally,wewilladdthetransactionthatwilltakeplaceifarandomlyselectednumberislowerthanthethresholddeterminedbythetrade-probabilityvariable.Addthefollowingtotheifcommandwejustwrote:

[if random-float 1 < trade-probability [set pots pots - 1 ask one-of route-neighbors [set pots pots + 1] ] ]

Thiscodewillperformatransactionbyfirstreducingthenumberofpotsoftheseller(therandomlyselectedturtle),thenitwillrandomlyselectoneoftheotherturtlesthisnodeis

Page 17: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

17

connectedto(thissecondturtlebecomesthebuyer),andfinallyitwillincreasethenumberofpotsthebuyerownsby1.Yourcompletegoprocedureshouldnowlooklikethis:

to go let total-pots sum [pots] of turtles repeat total-pots [ ask one-of turtles with [pots > 0] [if random-float 1 < trade-probability [set pots pots - 1 ask one-of route-neighbors [set pots pots + 1] ] ] ] tick end

Saveyourmodel!Atthemomentwecannotexplorethetradeprocedurewejustcreatedveryeasily,becausewedonothaveanythingthatreportsitseffects.Let’saddaplotthattellsussomethingaboutthetradeprocesses.Oneofthemostinterestingthingstoexplorewouldbetoseehowmanypotseachturtlehas:thedistributionofpots.WewillcreateaplotthatshowsusthisintheInterfacetab:

• SelectPlotfromthedropdownbox.• Clickthe‘Add’button.• Clickanywhereinthewhitespace.Anewwindowwillappearwhereyoucan

determinewhatthePlotwilldo.• Write‘Distributionofpots’inthe‘name’box.• Clickontheyellowpenciltomodifythe‘defaultpen’.Anewwindowwillopen

whereyoucandeterminewhatthispenwillplot.• Setthe‘Mode’dropdownboxto‘Bar’,setthe‘Interval’to1.0,andwritethe

followingcodeinthe‘Penupdatecommands’box:let max-pots max [pots] of turtles set-plot-x-range 0 (max-pots + 1) histogram [pots] of turtles

• ClickOKtwice.

Page 18: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

18

Thisplotwillcreateahistogram,displayingthedistributionofpotsamongturtles.OntheXaxisweseethenumberofpots,andontheYaxisweseethenumberofturtlesthatownacertainnumberofpots.Finally,wewilladdanotherwayofvisualisingthedifferencesinthenumberofpotsthatdifferentturtlesownbyupdatingthesizeofturtlesrelativetothenumberofpotstheyown.Attheendofthegoprocedure,justbeforetick,wewillcallanewprocedureupdate-size:

… ] update-size tick end

Attheendofallthecodewewillspecifywhatthisnewproceduredoes.Copyandpastethefollowing:

to update-size let max-pots [pots] of one-of turtles with-max [pots] ask turtles [ set size ( pots / max-pots ) * 3 ] ask one-of turtles with-max [pots] [ show town-name ] end

Thisprocedurewillchangethesizeofeachsettlementattheendofeachtimestep,makingthesettlementswithalotofpotslargerandthesettlementswithfewpotssmaller.Thesettlementwiththehighestnumberofpotswillbedisplayedinthecommandcentreatthebottomofthescreen.Saveyourmodel!

Page 19: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

19

13. TheeffectoftheRomantransportsystemonwealthinequalityNowwecanfinallystartexploringthefirstaspectofourhypothesis:theeffectoftheRomantransportnetworkonthedistributionofwealth(asrepresentedbyoursimpleprocessoftradeinpots).Setupyourmodelandletitrunforafewtimesteps.Explorehowtheplotofpotdistributionandthesizeofsettlementschanges.Trychangingtheslidersandsettingupandrunningthemodelagain.Howdothedistributionsandsettlementsizeschangeovertime?Whatistheeffectofthetrade-probabilityvariable?Whatistheeffectofthenum-potsvariable?Istherestronginequalityinthedistributionofpots?Trytoidentifyhowasettlement’s“wealth”inpotscorrelateswithitsrankanditsnumberofconnectionsintheORBISnetwork.

14. OthernetworkstructuresThereisanaspectofourhypothesisthatwecannotaddresswithourcurrentmodel:IsthephenomenonofwealthinequalityaparticularfeatureoftheRomantransportsystemstructure,orcanothernetworkstructuresenforcemoreextremewealthinequalitymuchfaster?Toexplorethisquestion,andtoseehowwealthinequalitydoesordoesnotarisedependingonnetworkstructure,wewillagainsearchforpre-existingcodethatallowsustocreatedifferentnetworkstructuresinourmodel.Luckily,suchcodeisavailableviatheprojectMERCURYwebsite.NavigatetotheMERCURYmodellibraryandfollowthelinkstothe‘Networkstructures’tutorial:https://projectmercury.eu/model-library/Click‘Download’andfromthe‘code’folderinsidethedownloadedfoldercopythemodel‘network-structures.nlogo’andpasteitintoyourworkingfolder‘network_structures’.Openthemodelyoujustdownloaded.Thismodelsimplyallowsyoutocreateasetofnodesandconnectthemaccordingtoaparticularnetworkstructure(seethenetworkscienceglossaryformoreinformationaboutthedifferenttypesofnetworkshttps://archaeologicalnetworks.wordpress.com/resources/#glossary).Let’shavealookatthedifferentprocedurestoidentifywhatweneedtocopyandwhatnot:

• Thecreate-new-networkprocedurewillcreateacompletelynewsetofnodesandconnectthemwithanewsetoflinksaccordingto8differenttypesofnetworkstructure.Becausewedonotwanttochangethesetofnodes(thesettlementsintheORBISnetwork)wewillnotusethisprocedure.

• Thesame-nodes/new-links procedurewillkeeptheexistingsetofnodesinthemodelandconnectthemwithanewsetoflinksaccordingtofourdifferentnetworkstructures.BecausewewanttokeeptheORBISnodeswecanusethecodeinthisprocedure.

Page 20: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

20

• Theremainingcodeisusedtochangethevisuallayoutofthenetworkandtoreportstatisticalnetworkproperties.Wewillnotcopythiscode.

Copytheentiresame-nodes/new-linksprocedureandpasteitintoyourownmodelattheveryend.Nowweneedtoironoutafewissuestoensurethisnewcodeworkswithourcurrentmodel.Whatwewanttoachieveisthatwhenwesetupthemodel,iteithershowsustheORBISnetworkoranalternativenetworkstructurethatweselect.First,let’schangethenameofthisproceduretosomethingmoredescriptiveandappropriateforourownmodel.Replaceto same-nodes/new-linksforto alternative-network.Second,tousethisnewprocedurewecanincludeitinthesetupprocedurejustbeforereset-ticks:

ask turtles [set pots round ( num-pots * size )] alternative-network reset-ticks end

Third,weshouldchangethevariableexisting-network-structureintosomethingmoreappropriateforourownmodel.Gotothealternative-networkprocedureinyourcodeandchangeeveryexisting-network-structuretothefollowingnewvariable:network-structureFourth,weneedtocreatethisnewvariablenetwork-structureintheinterfaceofourmodel.Itwilltaketheformofadrop-downwindowthatallowsustoselectwhatnetworkstructurewewanttocreateforagivenexperiment.Gototheinterfacetab(ignoreallerrorwarnings)andaddachooserdrop-downwindowtotheinterfacefortheglobalvariablenetwork-structurewiththefollowingfivechoices:

“ORBIS” “nearest neighbour” “random” “star” “circular”

Nowthatwehavemadethenecessarychangestoincorporatethecopiedcodeintoourownmodel,wecanturnourattentiontotheremainingerrormessages.

• Nothingnamednearest-neighboursexists.Thisisavariablethatisneededforcreatingthe“nearestneighbour”networkstructure(itdeterminestohowmanyofanodesnearestneighbourseachnodeisconnected).Gototheinterfaceandadda

Page 21: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

21

sliderforthevariablenearest-neighbourswithaminimumof1andamaximumof10,anincrementof1andadefaultvalueof3.

• Nothingnamedprobabilityexists.Thisisavariableneededforthe“random”networkstructure(itdeterminestheprobabilitywithwhichalinkiscreatedbetweenapairofnodes).Gototheinterfaceandaddasliderforthevariableprobabilitywithaminimumof0andamaximumof0.3,anincrementof0.01andadefaultvalueof0.01.

Onceyoumadethesechangesthemodeldoesnotreportanyerrorsanymore.Putthistothetestbyclickingthesetupbuttonandchangingthesettingofthenetwork-structurevariable.Canyoucreateeachofthefivedifferentnetworkstructurescorrectly?Infact,thereisstilloneissueweneedtoironout.Ifyouclickthegobutton,youwillgetanerrorbecauseourlinksarenolongerknownasroutes(thebreedweneededtoimporttheORBISnetwork)buttheyarenowcalledlinks.Tosolvethisissue,change“route”inthegoprocedureto“link”:

to go let total-pots sum [pots] of turtles repeat total-pots [ ask one-of turtles with [pots > 0] [if random-float 1 < trade-probability [set pots pots - 1 ask one-of link-neighbors [set pots pots + 1] ] ] ] update-size tick end

Saveyourmodel!Yoursetupprocedureshouldnowlooklikethis:

Youralternative-networkprocedureshouldnowlooklikethis:

Page 22: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

22

Yourinterfaceshouldnowlookmoreorlesslikethis:

Page 23: Network structures and assembling code in Netlogo, …...Network structures and assembling code in Netlogo version 01-09-2018 2 1. Introduction This tutorial provides an introduction

NetworkstructuresandassemblingcodeinNetlogo version01-09-2018

23

15. NetworkstructuresandwealthinequalityNowwecanexplorethesecondpartofourhypothesis:towhatextentistheeffectofwealthinequalityaresultofthetransportnetworkstructure?FirstexplorethedistributionofpotsandthetopscoringsettlementswhenonlyusingtheORBISnetwork.Thenstartexploringinturntheotherfournetworkstructures.Tryidentifyingthedifferencesforthedistributionofpotsforeachnetworkstructureusingthefollowingquestions:

• Arepotsdistributedveryunequally?• Withwhatnetworkstructureisthedistributionofpotsmostunequal?• Withwhatnetworkstructureistheinequalityofpotdistributionsatitsmost

extreme?• Withwhatnetworkstructuresdoesittakemoretimestepstoobtainverystrong

inequalitiesinpotdistributions?• Arepotsevernormallydistributed?Canyouidentifyconditionsunderwhichyoucan

generatenon-extremewealthinequalities?Youwillnoticethatmostofthealternativenetworkstructuresdonotmakeanysenseinrealterms:theyblatantlyignoregeographicalrealityandknownsocio-politicalrealitiesoftheRomanworld.However,itiscrucialtokeepinmindthattheydosoinaveryproductiveway.TheyrepresentalternativewaysinwhichtransactionsbetweenurbansettlementsintheRomanworldcouldhavetakenplace.Whatifeveryplacewasonlyconnectedtotwootherplaces(circularstructure)?Whatiftheseplaceswerethegeographicallyclosesttowns(nearestneighbourstructure)?Whatifalltradehadtotakeplacethroughonesingleurbansettlement(starstructure)?Whatifinteractionopportunitiesofapairofsettlementswasentirelyaresultofchance(randomstructure)?Obviouslythesenetworkstructuresrepresentextremealternativescenarios,theyhavenothingtodowiththeRomanreality.ItisveryclearthattheprecisenumberofsimulatedpotsatparticularsiteslikeRhodesorRomeisnotinformativeatall.Butwhatisinformativeisthegeneraltrendsthatrecurbetweendifferentsetupsofasimulationexperiment:isonetownalwaysthemostwealthyordoesitsharethispositionwithahandfulofothers;isthewealthiesttown10timeswealthierthanthemajorityor1000times?Asextremetheoreticalscenarios,thesealternativenetworkstructureshelpusoutlinetherealmofpossiblepastrealities.Mostcrucially,theyhelpustonarrowdownwhereweshouldpositioncredibletheoriesofaRomanphenomenonbycomparingsimulateddatapatternswithobserveddatapatterns.Howclosearethearchaeologicallyandhistoricallyobservableinformationtotheartificialinformationthatresultsfromtheseextremescenarios?