I created a random (Erdos-Renyi) network with 100 nodes. I set the attribute value for all 100 nodes to 0. I find the node with the maximum degree (most neighbors) and change its attribute value from 0 to 1. Then, using node as the root of the node, I do the first width search (BFS) in network.
Here is my code to do this so far:
library(igraph)
graph <- erdos.renyi.game(100, 0.2, type = c("gnp", "gnm"), directed = FALSE,
loops = FALSE)
graph <- set.vertex.attribute(graph, "value", value = 0)
max_deg <- max(degree(graph))
root_node <- which(degree(graph) %in% c(max_deg))
V(graph)$value[root_node] = 1 - V(graph)$value[root_node]
bfs <- graph.bfs(graph, root = root_node, unreachable = FALSE, order = TRUE,
dist = TRUE)
As it goes through each node of the network, I want it to change the value of the node attribute that it was looking at from 0 to 1. I'm not sure how to do this.
Any help would be greatly appreciated.
Thanks in advance.
source
share