我不认为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
如果你不需要它们是唯一的。
我很高兴你找到适合你的东西! –