我怎么问一个不是我的代理人还是我的邻居?

时间:2017-03-21 09:19:36

标签: netlogo

在Netlogo中,如何为包含除它们及其内链接邻居之外的所有其他海龟的海龟创建代理集?

谢谢,

托马斯

这非常接近于创建一个不包括邻居的海龟代理集,但是效果不好:

to setup
  ca
  create-turtles 10 [setxy random-xcor random-ycor]
  ask turtles[create-link-to one-of other turtles]
end

to go
  ask one-of turtles[
    show in-link-neighbors
    let poss turtles with [not member? self in-link-neighbors]
    show poss 
  ]
end

上述代码来自:this previous answer

2 个答案:

答案 0 :(得分:1)

这将完成这项工作,虽然它并不漂亮。

to setup
  ca
  create-turtles 10 [setxy random-xcor random-ycor set color yellow set shape "circle"]
  ask turtles[create-link-to one-of other turtles]
end

to go
  ask one-of turtles[
    set color green
    ask in-link-neighbors [set color green]
    ask one-of turtles with [color != green] [set shape "person"]
  ]
  ask turtles [set color yellow]
end

答案 1 :(得分:0)

最直接的方法是:

turtles with [not link-neighbor? myself]

以下是显示此操作的示例:

observer> crt 10 [ create-links-with other turtles ]
turtles> fd 10
observer> ask turtle 0 [ show link-neighbors ]
(turtle 0): (agentset, 9 turtles)
links> if random 2 = 0 [ die ]
observer> ask turtle 0 [ show link-neighbors ]
(turtle 0): (agentset, 7 turtles)
observer> ask turtle 0 [ show turtles with [not link-neighbor? myself]]
(turtle 0): (agentset, 3 turtles)

对于无向链接的说法。如果您的链接已定向,请视情况替换in-link-neighbor?out-link-neighbor?