Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two lists combination

Tags:

netlogo

I have two lists for each agent. They show 1) to whom they are attracted and 2) whom they attracted. I would like to make a new set variable that shows only those agents that are equally attracted to each other. Equal attraction is: the number of the agent (self) is in the 'attracting' list of the other agent and the number of the other agent is in the 'attracting' list for the first agent (self). My code so far:

    if attracted != nobody [set attractinglists fput ([self] of attracted) attractinglists]

    if attracted != nobody [set attrlists fput ([self] of attracting) attrlists]

    set attractinglist [self] of other turtles with [member? myself attrlists]
like image 976
Newguy Avatar asked Dec 19 '25 01:12

Newguy


1 Answers

Edited to better answer the question as clarified in the comments below.

Alright so now, turtles will have a running list of all turtles to which they have ever been attracted. Every tick, turtles become attracted to three other turtles. They add those turtles to their "attracted-to" list (if they are not already on that list). Next, the turtles check if any of their "attracted-to" turtles have ever been attracted to them- if so, they will add that turtle to the "reciprocal-attraction" list (if it's not there already). Is that more what you were after?

turtles-own [
  attracted-to
  reciprocal-attraction      ;;; the turtles to which this turtle is attracted
]


to setup 
  ca
  create-turtles 10 [
    set attracted-to []
    set reciprocal-attraction []
  ]
end


to go  

  ask turtles [
    let temp-attraction sort n-of 3 other turtles
    show temp-attraction
    foreach temp-attraction [
      [x]->
      if ( member? x attracted-to = false ) [
        set attracted-to lput x attracted-to
      ]
    ]
  ]

  ask turtles [
    foreach attracted-to [ 
      [x]->
      if member? self [attracted-to] of x [
        if ( member? x reciprocal-attraction = false ) [
          set reciprocal-attraction lput x reciprocal-attraction
        ]
      ]
    ]
  ]

end
like image 168
Luke C Avatar answered Dec 21 '25 10:12

Luke C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!