rank_cocoso <- function (df, weights_cocoso, alpha=0.5) { alternatives <- df[3:nrow(df), 1] alternatives <- as.data.frame(alternatives) colnames(alternatives) <- "Alternatives" weights_decisor <- as.numeric(df[2, 2:ncol(df)]) criteria_direction <- df[1, 2:ncol(df)] criterias <- colnames(df)[2:ncol(df)] matrix_decis <- as.data.frame(df[3:nrow(df), 2:ncol(df)]) colnames(matrix_decis) <- criterias matrix_decis <- matrix_decis %>% mutate_all(as.numeric) matrix_decis_norm <- matrix_decis # Inicializar matrix_decis_norm weights_cocoso <- as.numeric(weights_cocoso) seq_pond <- rep(0,nrow(matrix_decis)) seq_exp <- rep(0,nrow(matrix_decis)) ka <- kb <- kc <- CoCoSo <- rep(0,nrow(matrix_decis)) matrix_decis_norm <- matrix_decis # Normalizacao da Matriz de Decisao do CoCoSo for(j in 1:ncol(matrix_decis)) { for(i in 1:nrow(matrix_decis)) { if(criteria_direction[j]=="MAX") { matrix_decis_norm[i,j] <- (matrix_decis[i,j] - min(matrix_decis[,j])) / (max(matrix_decis[,j]) - min(matrix_decis[,j])) } else { matrix_decis_norm[i,j] <- (max(matrix_decis[,j]) - matrix_decis[i,j]) / (max(matrix_decis[,j]) - min(matrix_decis[,j])) } } } # fim da normalizacao da matriz de decisao do CoCoSo # Sequencias de Comparabilidade for(i in 1:nrow(matrix_decis_norm)) { for(j in 1:ncol(matrix_decis_norm)) { seq_pond[i] <- seq_pond[i] + weights_cocoso[j] * matrix_decis_norm[i,j] seq_exp[i] <- seq_exp[i] + (matrix_decis_norm[i,j]) ^ weights_cocoso[j] } } # Estrategias de Agregacao e Agregacao Final for(i in 1:nrow(matrix_decis_norm)) { ka[i] <- (seq_pond[i] + seq_exp[i]) / (sum(seq_pond) + sum(seq_exp)) kb[i] <- seq_pond[i] / min(seq_pond) + seq_exp[i] / min(seq_exp) kc[i] <- (alpha * seq_pond[i] + (1 - alpha) * seq_exp[i]) / (alpha * max(seq_pond) + (1 - alpha) * max(seq_exp)) CoCoSo[i] <- (ka[i] * kb[i] * kc[i])^(1/3) + (1/3) * (ka[i] + kb[i] + kc[i]) } rank_COCOSO <- matrix_decis %>% mutate(Alternatives = alternatives, CoCoSo = CoCoSo) %>% arrange(desc(CoCoSo)) %>% mutate(Position = row_number()) %>% select(Alternatives, Position, everything()) rank_COCOSO <- cbind(rank_COCOSO, ka = ka, kb = kb, kc = kc) colnames(rank_COCOSO[,1]) <- "Alternatives" return(rank_COCOSO) }