"
A friend advised me to change from the first version to the version just below:
"
g <- sample_pa(n=100, power=1, m=1, directed= F)
V(g)$compartment <- "IGNORANT"
x <- sample(vcount(g), round(vcount(g)*0.1))
V(g)[x]$compartment <- "IMMUNI"
y <- sample(which(V(g)$compartment=="IGNORANT"), 1)
V(g)[y]$compartment <- "SPREADER"
degree(g,which(V(g)$compartment=="SPREADER"))
p <- 0.15
r <- 0.12
while (sum(V(g)$compartment=="SPREADER") >0) {
w <- unique(unlist(adjacent_vertices(g, which(V(g)$compartment=="SPREADER"))))
dummy_1 <- which(V(g)[w]$compartment=="IGNORANT")
z <- sample(w[dummy_1], ceiling(p*length(dummy_1)))
V(g)[z]$compartment <- "SPREADER"
dummy_2 <- which(V(g)$compartment=="SPREADER")
k <- sample(dummy_2, ceiling(r*length(dummy_2)))
V(g)[k]$compartment <- "STIFLER"
}
"
I have 3 problem I can't solve:
1) The while cycle, and the algorithm, must stops if there are no more nodes in the "IGNORANT" compartment and/or there are no more nodes in the "SPREADER" compartment.
2) I already tried the algorithm, and the number of the nodes that are "IMMUNE", decreases after a certain number of the while cycle. But that vertices must remain in the same compartment during the whole process!
Maybe an issue in the while cycle, i think the problem is the indexing of nodes when it chooses the vertices to change from "IGNORANT" to "SPREADER", and/or the ones to change from "SPREADER" to "STIFLER".
3) I have to revise the algorithm, because I want to obtain, at the and of the process, a print of a matrix that tell me about the number of "IGNORANT", "SPREADER" and "STIFLER" nodes in EACH iteration of the while cycle.
Does anyone know the way to solve these 3 problems?
Thank you in advance!!
Giorgio