我不認爲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
如果你不需要它們是唯一的。
我很高興你找到適合你的東西! –