3

I'm working on a simulation of social behavior in an emergency situation, using anonymized data from an actual event. Below is the section of code I'm using to create the 'people' turtles.

to read-people-from-file [filename]
  let rows bf csv:from-file filename
  foreach rows
  [[row] ->
create-people 1
[
 set size .46
 setxy (item 0 row) (item 1 row)
 set age (item 2 row)
 set gender (item 3 row)
 set visited? (item 4 row)
 set group-number (item 6 row)
 set group-type (item 7 row)
 if group-number < 300 and ((person group-number) = (other group-number))) [create-links-with other person]
]
 ]
end

Everything works except for the group-number based links. I've tried a few different variations of it, with no luck except where I attempted if group-number <300 [create-links-with other people which worked creating links but was functionally useless. What I'm trying to do is set it so that every person who came together (who has the same group number) has a link with other group members. It's specifically less than 300 because numbers 300 and above are for people who came alone or other designations.

I could theoretically create the links by hand after the turtles are created, but that seems both like a waste of time (I have a dataset of over 400) and like something that makes the code significantly less applicable to other scenarios.

How do I make Netlogo create links between members of the same group, based on what's in the CSV?

Actually, the dream answer: how do I make Netlogo create different breeds of links (based on group-type) between members of the same group-number, based on what's in the CSV?

Edit: In the end, I had to separate creating links from the initial agent setup. This was what worked:

 to soclink ;;groups that came together have links based type of relationship
ask people [if group-number < 300 
 [
if group-type = 1 [ask other people with [group-number = [group-number] of myself] [create-coworker-with myself]]
if group-type = 2 [ask other people with [group-number = [group-number] of myself] [create-friend-with myself]]
if group-type = 3 [ask other people with [group-number = [group-number] of myself] [create-partner-with myself]]
if group-type = 4 [ask other people with [group-number = [group-number] of myself] [create-family-with myself]]
if group-type = 5 [ask other people with [group-number = [group-number] of myself] [create-multiple-with myself]]

  show count links]]
end
Chiomi
  • 53
  • 6

1 Answers1

3

For the first part, maybe this would work- once your people are created, with their numbers assigned to group-number:

to group-link
  ask people [
    let my-group other people with [ group-number = [ group-number] of myself ]
    create-links-with my-group
  ]  
end

For the dream answer- it might depend on how many breeds of links you need. As far as I know, link breeds must be predefined- you could not programatically generate links as needed for different groups (although I am no expert- there may be a way). If you have your link breeds already defined, for example:

undirected-link-breed [ link-as link-a ]
undirected-link-breed [ link-bs link-b ]

Pretend now that your group-type is either "a" or "b", and you can do something like

to specific-link-breeds
  ask people [
    let my-group other people with [ group-number = [ group-number] of myself ]
    if group-type = "a" [
      create-link-as-with my-group
    ]
    if group-type = "b" [
      create-link-bs-with my-group
    ]
  ]
  ask link-as [ 
    set color red
  ]
  ask link-bs [
    set color blue
  ] 
end

Edit: Changed turtles to people as it should be- thanks Mattsap.

Luke C
  • 10,081
  • 1
  • 14
  • 21
  • 2
    I also believe you need to pre-define your link breeds. However, it would be straightforward to simply create an attribute of the links that contained group-type. – JenB Nov 28 '17 at 00:54
  • 1
    One improvement to not have so many if statements would be to create a table where the key is the group-type and the value would be the function create-link-xs-with where xs is replaced by each link-breed. FYI, for beginner netlogoer's, if you have a more specific breed, use that (e.g. people) instead of the general turtle breed which calls all turtles---which would be bad if you have multiple breeds. – mattsap Nov 28 '17 at 01:46
  • 1
    Thanks to you both- I agree. @mattsap- good catch, that was an oversight, I have edited to fix. – Luke C Nov 28 '17 at 03:51