我做了創建與節點之間的給定數量的節點和無向鏈接的網絡下面的NetLogo過程:如何避免增加兩個節點之間的連接兩次
to setup
;; Here I created the nodes and sort them around a circle
clear-all
create-turtles number-of-nodes
layout-circle turtles max-pxcor
;; Here I add the links
let i 0
while [i < number-of-links] [
;; I randomly extract two nodes and link them
let node1 random number-of-nodes
let node2 random number-of-nodes
if node1 != node2 [
ask turtle node1 [ create-link-with turtle node2 ]
]
set i i + 1
]
reset-ticks
end
的問題是,這可能還要在已連接的節點之間添加鏈接。有沒有辦法知道兩個節點是否連接,如果它們已經連接,我可以隨機提取另一個數字?
我喜歡Arthur的回答。但是試圖創建一個已經存在的鏈接什麼也不做,所以你也可以去掉'i'變量,並且'只要'count鏈接<鏈接數量''。 –