Two lists combination

时间:2017-03-02 23:39:16

标签: 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]

1 个答案:

答案 0 :(得分:2)

编辑以便更好地回答以下评论中澄清的问题。

好吧,现在,乌龟将有一个他们曾被吸引过的所有海龟的运行清单。每一个蜱虫,海龟都被其他三只乌龟所吸引。他们将这些海龟添加到他们的“吸引到”列表中(如果他们还没有列在该列表中)。接下来,海龟检查他们的“被吸引的”海龟是否曾被他们吸引过 - 如果是这样的话,他们会将那只乌龟添加到“互惠吸引力”清单中(如果它已经不存在)。这更像是你追求的吗?

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