You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在NetLogo中提取网络邻域并统计其中链接数量?

Great question! I’ve tackled this exact scenario when working with NetLogo’s network tools, and it’s totally doable with a combination of NetLogo’s built-in primitives. Here’s a step-by-step breakdown to get the link count for a turtle’s ego network (just like make_ego_graph in igraph):

Step 1: Define the Ego Neighborhood

First, we need to get the set of turtles that make up the ego graph—this includes the target turtle itself plus all its direct link neighbors. For undirected networks (which matches your example), use link-neighbors:

  • turtle-set combines the target turtle and its neighbors into a single agent set.
  • [link-neighbors] of target-turtle grabs all turtles directly connected to the target via undirected links.

Next, we filter all links in the model to only those where both endpoints are in the ego neighborhood. This gives us all the links in the subgraph we care about:

  • links with [...] filters the global link set to only include links where both end1 and end2 are part of our ego neighborhood.
  • count ego-links gives us the total number of links in that subgraph.

Full Reporter Procedure

To make this reusable, wrap the logic into a reporter procedure that you can call for any turtle:

Example Usage

Let’s test this against your examples:

  • Case 1: Target has two unconnected neighbors
    If Turtle A is linked to Turtle B and Turtle C, but B and C have no link between them, calling ego-graph-link-count turtle 0 (assuming A is turtle 0) will return 2 (the links A-B and A-C).
  • Case 2: Target’s neighbors are connected
    If B and C also have a link, the same call will return 3 (A-B, A-C, B-C)—exactly what you described.

You can use this reporter in observer commands or ask turtles to calculate their own ego link counts:

Notes for Directed Networks

If you’re working with directed links instead of undirected, adjust the neighborhood to include in-link-neighbors and out-link-neighbors depending on whether you want incoming, outgoing, or all connections. For example:

内容的提问来源于stack exchange,提问作者ThomasC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:23:20