Netlogo- Creating agents with traits from .csv files -
i'm attempting populate world agents traits csv file. file looks this:
i'm pretty fluent in other areas of netlogo first time diving in external data inputs.
i've looked in other places , other topics populating list of data. official , dictionary seem have big differences pre-and post- v 5.1 i'm not sure if guides i'm finding accurate latest version.
i don't particularly care if large list (or list of lists) produced or if while reading data line-by-line, wipes previous lines' data after producing agent.
i've tried using given here: http://netlogoabm.blogspot.com/2015/05/connecting-or-linking-turtles-from-csv.html
but seems throw errors since data not numbers. appreciate assistance.
i believe can modify example match problem, in summary first read file global list, extracted number of agents, assigned properties of agents @ each tick , ran simulation:
extensions [csv] breed [drivers driver] turtles-own[ name list-of-actions ] globals [li] setup ca set li [] file-open "time.csv" load-files-and-set-the-list createdrivers set-agents-list-of-actions reset-ticks end load-files-and-set-the-list if file-at-end? [ stop file-close ] ;; protect against end of file while [not file-at-end? ] [ let _line (csv:from-row file-read-line ",") set li lput _line li ] end set-agents-list-of-actions let t [] foreach li [ if position ? li > 0 [ ask turtles [name = (item 0 ?)] [ set hidden? false set list-of-actions lput ( list (item 1 ?) (item 2 ?) (item 3 ?)) list-of-actions ] ] ] end go ask drivers [ foreach list-of-actions [ if ticks = (item 0 ?) [ move-to patch (item 1 ?) (item 2 ?) set list-of-actions remove ? list-of-actions ] ] ] tick end to-report driver-names let drivernames [] foreach li [ if position ? li > 0 [ set drivernames lput (item 0 ?) drivernames ] ] set drivernames remove-duplicates drivernames report drivernames end createdrivers resize-world 0 500 0 3 set-patch-size 60 let n length driver-names foreach driver-names [ create-drivers 1 [ set name ? set shape "car" set size 1 set hidden? true set list-of-actions [] ] ] end
Comments
Post a Comment