Foreach with multiple lists

86 views
Skip to first unread message

mamadt...@gmail.com

unread,
May 19, 2021, 3:07:32 AM5/19/21
to netlogo-users
I have a list of links "max-links":  set max-links sort-on [(- label)] link-set [max-one-of my-out-links [label]] of turtles
I have divided this list into two and set all turtles at end1 in one list "max-turtles1" and all turtles at end2 in another list "max-turtles2". 
Now, i've defined a foreach with both max-turtles1 and max-turtles2:

    foreach max-turtles1 max-turtles2
    [
      [a b] ->
      ask a 
      [
        ask my-out-links with [not member? self keep] [die]
        set max-links sort-on [(- label)] link-set [max-one-of my-out-links [label]] of turtles
        set max-turtles1 map [k -> [end1] of k] max-links
      ]
      ask b 
      [
        ask my-in-links with [not member? self keep2] [die]
        set max-links sort-on [(- label)] link-set [max-one-of my-out-links [label]] of turtles
        set max-turtles2 map [k -> [end2] of k] max-links
      ]
    ]

As shown here, "ask my-out-links with [not member? self keep] [die]" is executed for max-turtles1 and  "ask my-in-links with [not member? self keep2] [die]" is executed for max-turtles2
However, after each iteration on both lists, the max-links list and max-turtles1 and 2 lists have to be updated before the foreach can move on the next items. 
I tried to manage this list update by once again setting (defining) the lists. But it's not doing what I intended.
Reply all
Reply to author
Forward
0 new messages