ABM Basics 2 & 3 (1) Flashcards
What does ABM stand for
Agent Based Modelling
In an ABM what do we use to represent the terrain?
Patches
What can turtles do in Netlogo?
Turtles can move, act and change the properties of the patches. Their behaviours and interactions can be defined using set rules, conditions or random events
What is the purpose of the “random” command?
The purpose is to introduce variability or unpredictability into simulations or models
What is a “floating-point number”?
A decimal number (e.g., 0.23)
What would you write to place turtle 0 at a random x-coordinate and y-coordinate = 2 in the command centre?
> ask turtle 0 [set xcor random-xcor set ycor 2]
ask turtle 0 [setxy random-xcor 2]
What is the primary purpose of using conditionals?
To allow agents or patches to make decisions based on conditions
In which situation would you use the IF conditional without an accompanying ELSE?
An agent needs to perform an action if a condition is met; meaning NO ACTION when NOT MET
How can we tell turtles to move forward 2 patches if their colour is red, move forward 1 patch otherwise?
> ask turtles [ ifelse color = red [forward 2] [forward 1] ]
What is the purpose of a list?
A list is meant to group and manage multiple values together
What line of code would you write to create a list called my_list comprising the elements 2 and 3?
set my_list [2 3]
What would you write to add a value (5) to the beginning of an existing list called my_list?
set my_list fput 5 my_list
What would you write to add a value (6) to the end of an existing list called my_list?
set my_list lput 6 my_list
What’s the difference between Global Variable and Local Variable?
Global variables are known to all procedure, local variables are only known to one procedure you are creating the variable in
how can we create a list of 10 random numbers between 0 and 100 using the repeat command?
let the_list []
repeat 10
[
set the_list lput (random 101) the_list
]
how can we create a list of 10 random numbers between 0 and 100 using the ‘while’ command?
let the_list []
while [length the_list , 10]
[
set the_list lput (random 101) the_list
]
list_a is: [ 1 3 5 7 ], how can we create a new list (b_list) that contains the square value of the items in list_a?
let the_list [1 3 5 7 ]
foreach list_a
[
x -> set list_b lput (x*x) list_b
]
What’s the difference of using the following loop structures? Repeat, while and forreach
Repeat - when you want the code to run the instructions several times
While - when you want the code to run the instructions as long as the condition remains true
Forreach - when you want the code to run a set of instructions for each of the elements within a set of elements
You want to create a procedure called rainbow-sheep in a separated file from the rest of the Wolf sheep predation code. This procedure should ask sheep to change to a random colour. What do you do?
Write the procedure rainbow-sheep in Notepad and save it as a .nls file
File name will be rainbowCode.nls
Code:
To rainbow-sheep
Ask sheep [ set color random 141 ]
End
What’s the purpose of a CSV:from-row?
Csv:from-row: takes data from a row and creates a list that contains the elements in the row
How do you read a .csv file?
file-close-all
if not file-exists? “name of file.csv”
[
user-message “No file ‘name of file.csv’ exists!”
Stop
]
file-open “london_crime.csv”
while [ not file-at-end? ]
[
let data csv: from-row file-read-line
]
file-close