Skip to content

Commit

Permalink
version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Blanca A. Ceballos Martin authored and cran-robot committed Sep 22, 2016
1 parent 663692f commit 74fbf4b
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 184 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: MCDM
Type: Package
Title: Multi-Criteria Decision Making Methods for Crisp Data
Version: 1.1
Date: 2016-09-05
Version: 1.2
Date: 2016-09-21
Author: Blanca A. Ceballos Martin <[email protected]>
Maintainer: Blanca A. Ceballos Martin <[email protected]>
Description: Implementation of several MCDM methos for crisp data for decision
Expand All @@ -16,6 +16,6 @@ URL: http://decsai.ugr.es/index.php?p=miembros&id=19909
LazyData: true
RoxygenNote: 5.0.1
NeedsCompilation: no
Packaged: 2016-09-05 11:31:04 UTC; Modo
Packaged: 2016-09-22 08:31:35 UTC; Modo
Repository: CRAN
Date/Publication: 2016-09-05 13:53:38
Date/Publication: 2016-09-22 16:50:45
12 changes: 6 additions & 6 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
69910b71bb5bd011e994234c8b59b0c1 *DESCRIPTION
85c40131e9bb8ed23b4d12207b54a85c *DESCRIPTION
9b7c4e38c891101fd4549788a687c7de *NAMESPACE
8287ca47154ab5e73e30274a16880212 *R/MMOORA.R
5b035e73afcd7f7bae9d167620a5a93b *R/MetaRanking.R
76fbfe56c0a7f78ed63313786b5cff85 *R/RIM.R
00ac3bdfc38bc0f08b8c3c52233e6555 *R/TOPSISLinear.R
266d922c53def0d332ea7c58905294d6 *R/MetaRanking.R
c4ef60a9760928352d2d83df4ebf2d73 *R/RIM.R
14db364d3779af1b8b7e9b3267106ad3 *R/TOPSISLinear.R
4688cfc2894c6138351b9d12525d697d *R/TOPSISVector.R
8d25956de81910c4f10a7d01606915a3 *R/TheoryOfDominance.R
36138b0987e910975df5fd5e956556a2 *R/VIKOR.R
6a66f6cdc3e5fd524cd010c82307e5ab *R/TheoryOfDominance.R
01529281754fede909161af523879a8a *R/VIKOR.R
b5f8ffd3b9c728bd73b802be03486e88 *R/WASPAS.R
6803bdbf53ad9f3fd94ebe327a580fb6 *man/MMOORA.Rd
7e39cee422906ca0e238c31f6aaa3d15 *man/MetaRanking.Rd
Expand Down
21 changes: 15 additions & 6 deletions R/MetaRanking.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,25 @@ MetaRanking <- function(decision, #matrix with all the alternatives
Waspas = WASPAS(decision,weights,cb,lambda)

#Meta-Ranking
MetaR = MMoora[,8]+Rim[,3]+TopsisV[,3]+TopsisL[,3]+Vikor[,5]+Waspas[,5]
if(Vikor[1,5] == "-"){
MetaR = MMoora[,8]+Rim[,3]+TopsisV[,3]+TopsisL[,3]+Waspas[,5]
}else{
MetaR = MMoora[,8]+Rim[,3]+TopsisV[,3]+TopsisL[,3]+Vikor[,5]+Waspas[,5]
}


#Ranking Aggregated
#library(RankAggreg)
ra = rbind(MMoora[,8],Rim[,3],TopsisV[,3],TopsisL[,3],Vikor[,5],Waspas[,5])
if(nrow(decision)<=10)
if(Vikor[1,5] == "-"){
ra = rbind(MMoora[,8],Rim[,3],TopsisV[,3],TopsisL[,3],Waspas[,5])
}else{
ra = rbind(MMoora[,8],Rim[,3],TopsisV[,3],TopsisL[,3],Vikor[,5],Waspas[,5])
}

if(nrow(decision)<=10){
RA = RankAggreg::BruteAggreg(ra, nrow(decision), distance="Spearman")
else
}else{
RA = RankAggreg::RankAggreg(ra, nrow(decision), method = "GA", distance = "Spearman", verbose=FALSE)

}
return(data.frame(Alternatives = 1:nrow(decision), MMOORA = MMoora[,8], RIM = Rim[,3], TOPSISVector = TopsisV[,3],
TOPSISLinear = TopsisL[,3], VIKOR = Vikor[,5], WASPAS = Waspas[,5],
MetaRanking_Sum = rank(MetaR, ties.method= "first"), MetaRanking_Aggreg = RA$top.list))
Expand Down
3 changes: 2 additions & 1 deletion R/RIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ RIM <- function(decision, #matrix with all the alternatives
else if( ((decision[i,j]>= CD[2,j]) && (decision[i,j]<= AB[2,j])) && (CD[2,j]!=AB[2,j])){
N[i,j]=1-(min(abs(decision[i,j]-CD[1,j]),abs(decision[i,j]-CD[2,j]))/abs(CD[2,j]-AB[2,j]))
}
else stop("error in normalization procedure: A != B and D != C")
else stop("Error in normalization procedure: if x is in [A,C], then A != C,
or if x is in [D,B], then D != B")
}
}

Expand Down
146 changes: 72 additions & 74 deletions R/TOPSISLinear.R
Original file line number Diff line number Diff line change
@@ -1,74 +1,72 @@
#' Implementation of TOPSIS Method for Multi-Criteria Decision Making Problems.
#'
#' @description The \code{TOPSISLinear} function implements the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) Method with the linear transformation of maximum as normalization prodecure.
#' @param decision The decision matrix (\emph{m} x \emph{n}) with the values of the \emph{m} alternatives, for the \emph{n} criteria.
#' @param weights A vector of length \emph{n}, containing the weights for the criteria. The sum of the weights has to be 1.
#' @param cb A vector of length \emph{n}. Each component is either \code{cb(i)='max'} if the \emph{i-th} criterion is benefit or \code{cb(i)='min'} if the \emph{i-th} criterion is a cost.
#' @return \code{TOPSISLinear} returns a data frame which contains the score of the R index and the ranking of the alternatives.
#' @references Garcia Cascales, M.S.; Lamata, M.T. On rank reversal and TOPSIS method. Mathematical and Computer Modelling, 56(5-6), 123-132, 2012.
#' @examples
#'
#' d <- matrix(c(1,4,3,5,2,3),nrow = 3,ncol = 2)
#' w <- c(0.5,0.5)
#' cb <- c('max','max')
#' TOPSISLinear(d,w,cb)

TOPSISLinear <- function(decision, #matrix with all the alternatives
weights, #vector with the numeric values of the weights
cb #vector with the "type" of the criteria (benefit = "max", cost = "min")
)
{
#Checking the arguments
if(! is.matrix(decision))
stop("'decision' must be a matrix with the values of the alternatives")
if(missing(weights))
stop("a vector containing n weigths, adding up to 1, should be provided")
if(sum(weights) != 1)
stop("The sum of 'weights' is not equal to 1")
if(! is.character(cb))
stop("'cb' must be a character vector with the type of the criteria")
if(! all(cb == "max" | cb == "min"))
stop("'cb' should contain only 'max' or 'min'")
if(length(weights) != ncol(decision))
stop("length of 'weights' does not match the number of the criteria")
if(length(cb) != ncol(decision))
stop("length of 'cb' does not match the number of the criteria")

#1. Normalization and weighting
N <- matrix(nrow = nrow(decision), ncol = ncol(decision))

Norm <- as.integer(cb == "max") * apply(decision, 2, max) +
as.integer(cb == "min") * apply(decision, 2, min)

N <- matrix(nrow = nrow(decision), ncol = ncol(decision))
for(j in 1:ncol(decision)){
if (cb[j] == 'max'){
N[,j] <- decision[,j] / Norm[j]
}
else{
N[,j] <- Norm[j] / decision[,j]
}
}
W <- diag(weights)
NW <- N%*%W

#2. Ideal solutions
posI <- as.integer(cb == "max") * apply(NW, 2, max) +
as.integer(cb == "min") * apply(NW, 2, min)
negI <- as.integer(cb == "min") * apply(NW, 2, max) +
as.integer(cb == "max") * apply(NW, 2, min)

#3. Distances to the ideal solutions
distance =function(x,y){
sqrt(sum((x - y) ^ 2))
}
posDis <- apply(NW, 1, distance, posI)
negDis <- apply(NW, 1, distance, negI)

#4. R index
R <- negDis/(negDis+posDis)

#5. Rank the alternatives
return(data.frame(Alternatives = 1:nrow(decision), R = R, Ranking = rank(-R, ties.method= "first")))

}
#' Implementation of TOPSIS Method for Multi-Criteria Decision Making Problems.
#'
#' @description The \code{TOPSISLinear} function implements the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) Method with the linear transformation of maximum as normalization prodecure.
#' @param decision The decision matrix (\emph{m} x \emph{n}) with the values of the \emph{m} alternatives, for the \emph{n} criteria.
#' @param weights A vector of length \emph{n}, containing the weights for the criteria. The sum of the weights has to be 1.
#' @param cb A vector of length \emph{n}. Each component is either \code{cb(i)='max'} if the \emph{i-th} criterion is benefit or \code{cb(i)='min'} if the \emph{i-th} criterion is a cost.
#' @return \code{TOPSISLinear} returns a data frame which contains the score of the R index and the ranking of the alternatives.
#' @references Garcia Cascales, M.S.; Lamata, M.T. On rank reversal and TOPSIS method. Mathematical and Computer Modelling, 56(5-6), 123-132, 2012.
#' @examples
#'
#' d <- matrix(c(1,4,3,5,2,3),nrow = 3,ncol = 2)
#' w <- c(0.5,0.5)
#' cb <- c('max','max')
#' TOPSISLinear(d,w,cb)

TOPSISLinear <- function(decision, #matrix with all the alternatives
weights, #vector with the numeric values of the weights
cb #vector with the "type" of the criteria (benefit = "max", cost = "min")
)
{
#Checking the arguments
if(! is.matrix(decision))
stop("'decision' must be a matrix with the values of the alternatives")
if(missing(weights))
stop("a vector containing n weigths, adding up to 1, should be provided")
if(sum(weights) != 1)
stop("The sum of 'weights' is not equal to 1")
if(! is.character(cb))
stop("'cb' must be a character vector with the type of the criteria")
if(! all(cb == "max" | cb == "min"))
stop("'cb' should contain only 'max' or 'min'")
if(length(weights) != ncol(decision))
stop("length of 'weights' does not match the number of the criteria")
if(length(cb) != ncol(decision))
stop("length of 'cb' does not match the number of the criteria")

#1. Normalization and weighting
N <- matrix(nrow = nrow(decision), ncol = ncol(decision))

Norm <- as.integer(cb == "max") * apply(decision, 2, max) +
as.integer(cb == "min") * apply(decision, 2, min)

N <- matrix(nrow = nrow(decision), ncol = ncol(decision))
for(j in 1:ncol(decision)){
if (cb[j] == 'max'){
N[,j] <- decision[,j] / Norm[j]
}
else{
N[,j] <- Norm[j] / decision[,j]
}
}
W <- diag(weights)
NW <- N%*%W

#2. Ideal solutions
posI <- apply(NW, 2, max)
negI <- apply(NW, 2, min)

#3. Distances to the ideal solutions
distance =function(x,y){
sqrt(sum((x - y) ^ 2))
}
posDis <- apply(NW, 1, distance, posI)
negDis <- apply(NW, 1, distance, negI)

#4. R index
R <- negDis/(negDis+posDis)

#5. Rank the alternatives
return(data.frame(Alternatives = 1:nrow(decision), R = R, Ranking = rank(-R, ties.method= "first")))

}
Loading

0 comments on commit 74fbf4b

Please sign in to comment.