############ ## Bipartite case ############ P_names = as.character(1:5) PartyID = data.frame(PartyID = P_names, fraud = c(1,1,0,0,0), stringsAsFactors = F) P_mat = matrix(0,nrow(PartyID),nrow(PartyID)); rownames(P_mat) = P_names; colnames(P_mat) = P_names A_names = paste0('A',1:13) PA_mat = matrix(c(1,1,rep(0,11),0,0,1,1,1,rep(0,8),rep(0,5),1,rep(0,7),rep(0,6),1,1,rep(0,5),rep(0,8),1,1,0,0,0),byrow=T,nrow=5) rownames(PA_mat) = P_names; colnames(PA_mat) = A_names A_mat = matrix(c(sample(0:4,13,replace = T), sample(0:1,13,replace = T), sample(0:2,13,replace = T), sample(0:3,13,replace = T), sample(0:2,9*13,replace = T)),byrow = T,nrow=13) colnames(A_mat) = rownames(A_mat) = A_names diag(A_mat) = 0 # no loops # Create disconnected component A_mat[c(6,12),] = 0; A_mat[,c(6,12)] = 0 A_mat[6,12] = 4 ## Create sink node A_mat[11,] = 0 ## Add some more 0s A_mat[1:2,3:5] = 0; A_mat[3:5,1:2] = 0 A_mat[c(11,13),c(11,13)] = 0 # A = rbind(cbind(P_mat,PA_mat),cbind(t(PA_mat),A_mat)) g = graph.adjacency(A) ## Set attributes V(g)$pers = c(1,1,rep(0,vcount(g)-2)) ## Edge weights set.seed(1) E(g)$weight = round(runif(ecount(g)),1) ### AS.UNDIRECTED and sum of edge weights g_UN = as.undirected(g,'each') ## This keeps every edge and do not combine edge weights g_UN2 = as.undirected(g) ## This somehow collapse edges, however edge weights are combined in strange way E(g_UN)$weight E(g_UN2)$weight ## Here edge weights doesn't make sense g_simUN = simplify(g_UN, edge.attr.comb = list(weight='sum')) g_simUN2 = simplify(g_UN2, edge.attr.comb = list(weight='sum')) E(g_simUN)$weight ## This gives correct edge weights(sum of all edge weights between two vertices) E(g_simUN2)$weight ## Here edge weights doesn't make sense