ABM Basics 3 & 2 (2) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Which loop structure in Netlogo should you use if you want a set of commands to run a specific number of times?

A

Repeat loop structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which loop structure should you use in Netlogo to run commands for each element in a list or agent-set?

A

Foreach

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we use the while command to create a list of 5 random numbers between 0 and 100?

A

let the_list []

while [ length the_list < 5 ]
[
set the_list lput (random 101)
the_list
]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the main purpose of a .nls file in Netlogo?

A

To make the main file easier to read. This organises your code and it’s better for testing/structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you import a .nls file into your main Netlogo code?

A

__includes [“filename.nls”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where should the .nls file be located in relation to the main .nlogo file?

A

Must be in the same directory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the primary delimiter used to separate data in a .csv file?

A

Comma (,)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which extension must be added at the top your code to use .csv functionalities in NetLogo?

A

‘extensions [csv]’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

With the CSV extension in Netlogo, which command is used to convert a row of data from a .csv file into a list?

A

csv: from-row

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you load data from a .csv file named boroughs.csv into a list called borough_data using the Netlogo ‘csv’ extension?

A

let borough_data csv: from-file “boroughs.csv”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of setting the coordinates of the bottom-left corner of the supermarket to (0,0)?

A

To establish the origin of the coordinate system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is the colour of each patch determined in the supermarket layout?

A

Assigned automatically based on keywords in a CSV file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Where should the CRAVED vectors be stored for each patch?

A

In a patch attribute called CRAVED

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain the purpose of the set_colour_patches procedure in terrain .nls

A

It assigns global variables for the colours of each type of patch available.

By using global vars, we can easily adjust the colours in one central location rather than changing the colour in each individual patch’s code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the add_products procedure in relation to CRAVED attributes?

A

Created to assign CRAVED values to each shelves patch, showing how likely items on those shelves are to be stolen.

This procedure reads CRAVED values from the .csv file and assigns them as a list of numbers to the CRAVED attribute of each patch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Write the procedure that checks if a given patch is an intersection patch and, if so, changes its colour to pink.

A

to check_intersection
ask patches
[
if category = “intersection”
[
set pcolor colour_intersection
]
]
end

17
Q

What are the elements in an ABM?

A

Elements in an ABM:
Agents - turtles
Environment - patches/terrain
Actions and interactions

18
Q

What does the environment do?

A

Environment defines the grid which the agents can go to

19
Q

What is a primitive command?

A

Primitive commands describe an action for the programme to do (i.e., ask turtles [set color yellow])

20
Q

What is a primitive reporter?

A

Primitive reporters carry out operations and report the result (i.e., report patches with [pcolor = green])

21
Q

What is a variable?

A

Variables are used to label information that we want the prpgram to store.

22
Q

What is a primitive variable?

A

Primitive variables in NetLogo are variables that are already named and stored in a NetLogo model (i.e., colour of a turtle - color; colour of a patch - pcolor)

23
Q

Write the code when you want the color of the patches to be set in the value of green

A

ask patches [set pcolor green]

24
Q

How could we assign random colours to the sheep?

We could use set to assign or change the value of a variable. Colors in NetLogo range from 0 to 140

A

ask sheep [ set color random 141 ]

Why 141? The random command is 141 because you want to include all colours in the shade provided

25
Q

how can we tell turtles to move forward 1 patch if their colour is red using the if command?

A

Ask turtles [If color = red [ forward 1]]

26
Q

how can we tell turtles to move forward 2 patches if their colour is red and forward 1 patch otherwise?

A

Ask turtles [ ifelse color = red [forward 2] [forward 1]]

Why? Follows this: Ifelse boolean 1 [commands1][elsecommands]

27
Q

Turtles have now an energy attribute, a numeric value ranging from 0 to 100. How can we tell turtles to:

  1. Move forward 1 patch if their energy is less than or equal to 25,
  2. Move forward 2 patches if their energy is less than or equal to 50 but more than 25,
  3. Move forward 3 patches if their energy is less than or equal to 75 but more than 50,
  4. Move forward 4 patches if their energy is less than or equal to 100 but more than 75
A

ask turtles
[(
ifelse energy <= 25 [ forward 1 ]
( energy <= 50 AND energy > 25 ) [forward 2]
( energy <= 75 AND energy > 50) [forward 3]
[forward 4]
)]

28
Q

What are lists

A

Lists are a collection of variables and elements are separated by spaces

29
Q

How can you add items into a list?

A

Add value to the end of the list you do ‘lput’
Add item to the beginning you do ‘fput’

30
Q

We want to add a random number between 0 and 100 to the end of the_list (a list that has been previously created) How do we do it?

A

set the_list lput (random 101) the_list

31
Q

Remember that within a list, each element is an item and is numbered according to its position (starting at 0).

  1. Which is item 3
  2. What is the position of 4
  3. What is the length of the list

list = [ 2 4 6 8 10 ]

A
  1. 8
  2. 1
  3. 5
32
Q

Reports a list containing the given items, the items can be any type, produced by any kind of reporter

If the list is made by reporters (i.e., random 100) use the “list” command

A

Set name_of_list list (random 100) (random 100)

33
Q

What is the greater than less than sign

A

> = <
greater than; equal to; less than