条件网络邻居

时间:2018-03-05 14:11:52

标签: netlogo

我想选择按link属性而不是turtle属性过滤的网络邻居。例如,这可能是基于友谊链接上的强度分数仅选择最亲密的朋友。我可以通过为亲密朋友提供不同的link breeds来做到这一点,但这需要不断变化的品种,因为条件已经或不需要。

下面是一个布尔条件的示例。

links-own [flag?]

to testme
  clear-all
  ask patches [set pcolor white]
  create-turtles 20
  [ setxy 0.95 * random-xcor 0.95 * random-ycor
    set color black
  ]
  ask n-of 3 turtles [set color red]
  repeat 40
  [ ask one-of turtles
    [ create-link-with one-of other turtles
      [ set flag? random-float 1 < 0.4
        set color ifelse-value flag? [red] [gray]
      ]
    ]    
  ]
;  colour-neighbours
  colour-neighbours2
end

to colour-neighbours
  ask turtles with [color = red ]
  [ ask my-links with [flag?]
    [ ask other-end [ set color blue ]
    ]
  ]
end

to colour-neighbours2
  ask turtles with [color = red ]
  [ ask turtle-set [ other-end ] of my-links with [flag?]
    [ set color blue ]
  ]
end

我目前正在做相当于颜色的邻居,但它涉及单步执行。 color-neighbours2版本在概念上更接近,因为它直接指向网络邻居。但是,由于of,我得到一个邻居列表,然后我必须转换为代理集。

这是用于教学的,虽然两者都有效,但与具有link-neighbors原语的无条件网络邻域相比,它们似乎非常复杂。也就是说,如果我不关心旗帜,我可以简单地说ask link-neighbors [ set color blue ]

是否有更直接的方法来识别以链接属性为条件的网络邻居?

2 个答案:

答案 0 :(得分:3)

你已经涵盖了大多数可能性。另一种方法是:

to colour-neighbours3
  foreach [ other-end ] of my-links with [ flag? ] [ t ->
    ask t [ set color blue ]
  ]
end

我会避免使用colour-neighbours2,因为正如您所说,它需要从列表转换为代理集。我认为,您应该使用colour-neighbours还是colour-neighbours3是个人偏好的问题。

答案 1 :(得分:1)

只是添加一个使用代理集的更复杂(更糟糕的?)选项:

to colour-neighbours4
  ask turtles with [ color = red ] [
    let flag-links my-links with [flag?]
    ask link-neighbors with [ any? my-links with [ member? self flag-links ] ] [ 
      set color blue 
    ]
  ]  
end