[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    [R] vectorized code
From:       zeynab jibril <zeyn2307 () gmail ! com>
Date:       2015-05-29 14:49:28
Message-ID: CAH8tL_h7AZ5EjE6q4m2W=3w0=hnEBemzCTuDmjgqNcEJ4R+Tww () mail ! gmail ! com
[Download RAW message or body]

HI

I was working on online example, where virus is spread through a graph. The
example is sufficient for small graph i.e. small number of edges and nodes.
But I tried it on very large graph i.e. 10000 nodes and 20000 edges, but
the below function is not sufficient for large graph because its slow.

My question is how can the below function be converted to Vectorized code
can be optimized for large graphs?

spreadVirus <- function(G,Vinitial,Activation_probability){



# Precompute all outgoing graph adjacencies



G$AdjList = get.adjlist(G,mode="out")



# Initialize various graph attributes

V(G)$color    = "blue"

E(G)$color    = "black"

V(G)[Vinitial]$color    <- "yellow"



# List to store the incremental graphs (for plotting later)

Glist <- list(G)

count <- 1



# Spread the infection

active <- Vinitial



while(length(active)>0){

new_infected <- NULL

E(G)$color = "black"



for(v in active){

# spread through the daily contacts of vertex v



daily_contacts <- G$AdjList[[v]]



E(G)[v %->% daily_contacts]$color <- "red"



for(v1 in daily_contacts){



if(V(G)[v1]$color == "blue" & new_color=="red") {



V(G)[v1]$color <- "red"



new_infected <- c(new_infected,v1)



 }

}

}

# the next active set

#this needed for updating



active <- new_infected



# Add graph to list

# optional dependening on if i want to graph

count <- count + 1

Glist[[count]] <- G

}

return(Glist)

}

	[[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic