Netlogo:评估给定变量的相似性后,让乌龟与其他人互动 [英] Netlogo: Making a turtle interact with anotherone after evaluating similarity in a given variable

查看:149
本文介绍了Netlogo:评估给定变量的相似性后,让乌龟与其他人互动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几只乌龟,每只乌龟都带有三个变量Opinion1,Opinion2和Opinion3.我需要他们:

I have several turtles each with three variables opinion1, opinion2 and opinion3. I need them to:

  1. 确定这三个变量中哪个变量值最高
  2. 在他们的网络中找到另一只乌龟,其价值至少与之相同 就像在1中找到的一样.
  3. 使用1.更新在1.中找到的自己的值. 相对于2中发现的乌龟.
  1. identify which of these three variables has the highest value
  2. find another turtle in their network with a value at least as high as the one found in 1.
  3. update its own value found in 1. with respect to that of the turtle found in 2.

我所做的并没有真正的用处,因为它只会更新o1而不会真正查看哪一棵树(opinion1,view2或Opinion3)最高,然后再寻找邻居.

What I have done doesn't really work because it only updates looking at o1 without really having a look at which of the tree (opinion1, opinion2 or opinion3) is the highest and THEN looking for a neighbour.

to update-opinion
  ask turtles [
    let my-nearby-turtles nw:turtles-in-radius 1
    let my-opinion1 opinion1
    set neighbour one-of my-nearby-turtles with [ opinion1 > my-opinion1 ]
    if neighbour != nobody [
      let opinion_n [opinion1] of neighbour
        set opinion1 ((opinion1 + opinion_n) / (2))
    ]
  ]
end

推荐答案

我不知道使用opinion1等独特变量执行此操作的简单方法,但是也许有一个观点列表,而不是每个观点都有单独的变量意见会奏效.例如,使用以下设置:

I don't know a simple way to do this with unique variables like opinion1 etc, but maybe having a list of opinions instead of individual variables for each opinion will work. For example, with this setup:

extensions [ nw ]

turtles-own [ 
  opinions
]

to setup
  ca
  resize-world -5 5 -5 5
  set-patch-size 30
  crt 30 [
    set shape "dot"
    set opinions n-values 3 [ precision random-float 10 2]
    set color scale-color blue sum opinions -5 35
    while [ any? other turtles-here ] [
      move-to one-of neighbors4
    ]
  ]
  ask turtles [
    create-links-with turtles-on neighbors4
  ]
  reset-ticks
end

您得到的是这样的东西:

You get something like this:

每只乌龟都有一个opinions列表变量,该变量长三项.现在,您可以让每个乌龟使用max确定其最高意见值,使用position获取列表中的最大值索引位置,然后查询该乌龟的邻居以查看它们中是否有更高的值索引位置.如果是这样,请使用replace-item将您要问的海龟opinions列表修改为两个值的平均值:

Where each turtle has an opinions list variable that is three items long. Now, you can have each turtle determine its highest opinion value using max, get that maximum values index position in the list using position, and then query that turtle's neighbors to see if any of them have a higher value in the same index position. If they do, modify your asking turtles opinions list using replace-item to be the average of the two values:

to go
  ask turtles [
    ; Get adjacent turtles
    let my-nearby-turtles nw:turtles-in-radius 1

    ; Identify the highest highest value variable of 
    ; the current turtle, and get its list position
    let my-opinion max opinions
    let my-op-ind position my-opinion opinions

    ; Pick one of the turtles whose value in the same indexed
    ; position is higher than my-opinion
    let influence one-of my-nearby-turtles with [ 
      item my-op-ind opinions > my-opinion
    ]

    ; If that turtle exists, update my own opinions list as appropriate
    if influence != nobody [
      let new-opinion  precision ( 
        ( [ item my-op-ind opinions ] of influence + my-opinion ) / 2
      ) 2
      set opinions replace-item my-op-ind opinions new-opinion
    ]
    set color scale-color blue sum opinions -5 35
  ]
  tick
end

希望这是正确的选择,不确定列表是否适合您的需求.如果必须在每个刻度处将变量作为独立值使用,我想您可以将它们转换为列表,然后按照上述步骤进行操作.如果只需要它们进行输出,则可以根据列表中的值(只要与顺序保持一致)根据需要更新唯一变量.

Hopefully that is sort of on the right track, not sure if a list will work for what you need. If you must have the variables as standalone values at each tick, I suppose you could convert them to a list then follow the procedure above. If you only need them for output, you could just update your unique variables as needed based on the values in the list (as long as you are consistent with the order).

这篇关于Netlogo:评估给定变量的相似性后,让乌龟与其他人互动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆