2015-08-21 46 views
2

我创建了一个图表来反映道路网络的图形(即G =(V,E))。这包括许多交点,终点和中间节点(V)。 Terminus节点有1个连接(E),中间节点2和连接节点多于2个。NW:扩展龟半径

我想要做的是确定形成连接节点或连接节点之间的连接的单独部分。我正在考虑使用nw:radius在海龟这样做,但是这需要指定一个固定的搜索范围。我想知道有没有人

  • 有一个想法如何识别其他结/末端节点多远 从搜索节点走,这样我可以在海龟,在半径函数指定呢?
  • 或有一个更好的方式来识别网络部分的想法?

一旦我确定了这些部分,我将随后将位于它们旁边的海龟存储在列表中供以后使用。

回答

1

我不认为nw:turtles-in-radius会帮助你很多,在这里。这不是一个简单的问题。我发现了一个相当复杂的做法。也许别人会拿出更简单的东西。

的设置是只存在测试:

extensions [ nw ] 
to setup 
    clear-all 
    ; generate a simple network for testing 
    nw:generate-ring turtles links 5 
    ask n-of 2 turtles [ 
    hatch 1 [ 
     create-link-with myself 
     hatch 1 [ create-link-with myself ] 
    ] 
    ] 
    ask turtles [ set label who ] 
    repeat 1000 [ layout-spring turtles links 0.2 5 1 ] 
end 

其余的是从一堆记者,在一个相当实用的方式谱写制作:

to go 
    let nodes [ self ] of turtles with [ not is-intermediate? ] 
    let sections unique-sections reduce sentence map my-sections nodes 
    foreach sections print 
end 

to-report my-sections [ node ] 
    report map [ section-from node ? ] [ sort link-neighbors ] of node 
end 

to-report section-from [ n1 n2 ] 
    report ifelse-value [ is-intermediate? ] of n2 [ 
    fput n1 section-from n2 
     [ one-of link-neighbors with [ self != n1 ] ] of n2 
    ] [ 
    list n1 n2 
    ] 
end 

to-report is-intermediate? 
    report count my-links = 2 
end 

to-report unique-sections [ all-sections ] 
    let sections [] 
    foreach all-sections [ 
    if not member? reverse ? sections [ 
     set sections lput ? sections 
    ] 
    ] 
    report sections 
end 

可以在呼叫下降到unique-sections如果你不需要它们是唯一的。

0

首先感谢尼古拉斯。

最后,在看了更多的图论后,我决定使用弱组件集群路由。为了识别集群,我将上下文设置为只有两个连接的节点。因此删除联结和终点节点。然后我使用nw:weak-component-clusters。这给了我一个在每个组件中出现的海龟列表。然后我遍历这个列表,并给每个乌龟集合一个唯一的标识符。我现在有一个节点列表,它知道它与谁联系。

+0

我很高兴你找到适合你的东西! –