我使用R(和igraph軟件包)創建了兩個隨機(Erdos-Renyi)網絡,每個節點都有10個節點。每個節點上,同時在網絡中,已用隨機的0或1鏈接R中兩個不同隨機網絡中的兩個節點
這裏的屬性分配是我的代碼來做到這一點:
# Creates the first Erdos-Renyi graph, graph_a, with 10 nodes and edges with
# p=0.2
num_nodes <- 10
prob <- 0.2
graph_a <- erdos.renyi.game(num_nodes, prob, type=c("gnp", "gnm"),
directed=FALSE, loops=FALSE)
# Randomly sets the attributes of the nodes of graph_a to either 0 or 1
graph_a <- set.vertex.attribute(graph_a, "value",
value = sample(0:1, num_nodes, replace=TRUE))
# Creates the second Erdos-Renyi graph, graph_b, with 10 nodes and edges with
# p=0.2
graph_b <- erdos.renyi.game(num_nodes, prob, type=c("gnp", "gnm"),
directed=FALSE, loops=FALSE)
# Randomly sets the attributes of the nodes of graph_b to either 0 or 1
graph_b <- set.vertex.attribute(graph_b, "value",
value = sample(0:1, num_nodes, replace=TRUE))
我需要以某種方式從鏈接隨機選擇的節點第一個圖,從第二個圖中隨機選擇一個節點。因此,如果第一個圖中選定節點的0或1屬性值發生更改,則第二個圖中選定節點的屬性值也會發生更改(反之亦然)。
任何人都可以提出解決方案,如何實現這一目標?
非常感謝。
還記得簡單多數規則的解決方案嗎?答案與你檢查節點是否將被解除的部分非常相似。 –
這個不清楚。當你說從'a到b'連接一個隨機選擇的節點時,是否選擇了在1:10範圍內的兩個隨機數?第一個圖形的屬性值如何變化?這些東西不會改變自己。還是你想添加圖形,然後創建一組邊形成從a到b的排列?會這樣嗎?你可以做graph_c = graph_a + graph_b然後添加邊。 – Spacedman
@Spacedman - 爲什麼要從每個網絡中挑選一個隨機節點還不夠?屬性根據簡單多數規則而變化,其中根據大多數鄰居的屬性,節點的屬性從1變爲0(或0到1)。例如,如果一個節點的大部分鄰居的值爲0,那麼該節點的值也會變爲0。我不會將圖形添加到一起。 O只是想連接兩個節點。 – LoneWolf