2015-08-21 60 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

我很高興你找到適合你的東西! –