diff --git a/.src/R1_code/sub-challenge1/mlrmcl_r4_v2.R b/.src/R1_code/sub-challenge1/mlrmcl_r4_v2.R index 29fad9e..bfdc7d1 100644 --- a/.src/R1_code/sub-challenge1/mlrmcl_r4_v2.R +++ b/.src/R1_code/sub-challenge1/mlrmcl_r4_v2.R @@ -106,14 +106,25 @@ preProcessing <- function(input,method=c("quantile","pageRank","double"),i,integ generateFile <- function(graph,weighted=T){ test3<-get.adjacency(graph,attr = "weight") - m<-as.matrix(test3) - m.index<-apply(m!=0,1,which,arr.ind=T) - # weight<-m[m.index] + m.index<-get.adjlist(graph) + graph_directed <- as.directed(graph) + m.weight <- get.edge.attribute(graph_directed,name = "weight") + # m<-as.matrix(test3) if (weighted){ - test<-sapply(1:nrow(m), function(i) m[i,m.index[[i]]]) + # test<-sapply(1:nrow(m), function(i) m[i,m.index[[i]]]) temp2<-list() + # temp2_t <- list() + count <- 1 for (i in 1:length(m.index)){ - temp2[[i]]<-c(rbind(as.character(m.index[[i]]),test[[i]])) + num_edge_i = length(m.index[[i]]) + if (num_edge_i == 0){ + temp2[[i]]<-c(rbind(as.character(m.index[[i]]),numeric(0))) + } else{ + edge_weight_i <- m.weight[count:(count+num_edge_i-1)] + # temp2_t[[i]]<-c(rbind(as.character(m.index[[i]]),test[[i]])) + temp2[[i]]<-c(rbind(as.character(m.index[[i]]),edge_weight_i)) + count <- count + num_edge_i + } } fn <- "test.txt" if (file.exists(fn)) file.remove(fn) @@ -129,7 +140,8 @@ generateFile <- function(graph,weighted=T){ } -postProcessing <- function(method=c("random","discard","recluster"),smallest = 3,largest=100,g=graph,b2,c2,i2){ +postProcessing <- function(method=c("random","discard","recluster"),smallest = 3,largest=100, + g=graph,b2,c2,i2){ result<-read.table("output.txt") output<-list() # for (i in 1:nrow(unique(result))){