Skip to content

Commit

Permalink
version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Blanca A. Ceballos Martin authored and cran-robot committed Sep 5, 2016
1 parent acf55ed commit 663692f
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 299 deletions.
20 changes: 14 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Package: MCDM
Title: Multi-Criteria Decision Making Methods
Version: 1.0
Date: 2015-09-10
Type: Package
Title: Multi-Criteria Decision Making Methods for Crisp Data
Version: 1.1
Date: 2016-09-05
Author: Blanca A. Ceballos Martin <[email protected]>
Maintainer: Blanca A. Ceballos Martin <[email protected]>
Description: An R implementation of Four Multi-Criteria Decision Making (MCDM) Methods: Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS), "VIseKriterijumska Optimizacija I Kompromisno Resenje" (VIKOR), both Multi-Objective Optimization by Ratio Analysis and Full Multiplicative Form (Multi-MOORA) and Weighted Aggregated Sum Product ASsessment (WASPAS). In addition, this package provides a MetaRanking function which combines the output of the previous methods.
Description: Implementation of several MCDM methos for crisp data for decision
making problems. The methods that are implemented in this package are RIM,
TOPSIS (with two normalization procedures), VIKOR, Multi-MOORA and WASPAS.
In addition, MetaRanking function calculates a new ranking from the sum
of the rankings calculated, as well as an aggregated ranking.
Imports: RankAggreg
License: LGPL (>= 3)
URL: http://decsai.ugr.es/index.php?p=miembros&id=19909
LazyData: true
RoxygenNote: 5.0.1
NeedsCompilation: no
Packaged: 2015-11-18 16:00:54 UTC; Blanky
Packaged: 2016-09-05 11:31:04 UTC; Modo
Repository: CRAN
Date/Publication: 2015-11-19 11:02:12
Date/Publication: 2016-09-05 13:53:38
30 changes: 17 additions & 13 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
b301612e520e87ecf367a63d632b0645 *DESCRIPTION
0f714634d9b6e945d6b30e5d6276b22e *NAMESPACE
a6d7468cec7f23a7d52226beb220a609 *R/MMOORA.R
916b563fb195602c830dd3c55b3f1f7e *R/MetaRanking.R
5b246b44eab588a3641bf7288c90f566 *R/TOPSIS.R
6f0bdad34dcfb7883f3dc08ebdecb72e *R/VIKOR.R
f80bef4b19a66218360122eb29b1f0b0 *R/WASPAS.R
e91d631037e23f00c7fd70739a1278c3 *man/MMOORA.Rd
c3d685827adbeb13256720e443d2687a *man/MetaRanking.Rd
a263ae3ec5866104e5736868d3ebbd8e *man/TOPSIS.Rd
73dae3c80f82ad4dd9119924e75ce00d *man/VIKOR.Rd
244851b5223807a97aaceba704f70a8e *man/WASPAS.Rd
9120b7e76ff718096df3feea7dce908d *vignettes/MCDM.pdf
69910b71bb5bd011e994234c8b59b0c1 *DESCRIPTION
9b7c4e38c891101fd4549788a687c7de *NAMESPACE
8287ca47154ab5e73e30274a16880212 *R/MMOORA.R
5b035e73afcd7f7bae9d167620a5a93b *R/MetaRanking.R
76fbfe56c0a7f78ed63313786b5cff85 *R/RIM.R
00ac3bdfc38bc0f08b8c3c52233e6555 *R/TOPSISLinear.R
4688cfc2894c6138351b9d12525d697d *R/TOPSISVector.R
8d25956de81910c4f10a7d01606915a3 *R/TheoryOfDominance.R
36138b0987e910975df5fd5e956556a2 *R/VIKOR.R
b5f8ffd3b9c728bd73b802be03486e88 *R/WASPAS.R
6803bdbf53ad9f3fd94ebe327a580fb6 *man/MMOORA.Rd
7e39cee422906ca0e238c31f6aaa3d15 *man/MetaRanking.Rd
cbd050e6512a7d2e1db0dfb7c996371d *man/RIM.Rd
2cb23006a72a752f685f0e05cd52e4f7 *man/TOPSISLinear.Rd
f757fbf818251edabcb38bdf2d81879f *man/TOPSISVector.Rd
33a7b42ebabfc5a90616c496db7639c4 *man/VIKOR.Rd
3369c5e7b9317128957225d4a03fd52b *man/WASPAS.Rd
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
exportPattern("^[[:alpha:]]+")

import(RankAggreg)
export(MetaRanking, MMOORA, RIM, TOPSISVector, TOPSISLinear, VIKOR, WASPAS)

55 changes: 26 additions & 29 deletions R/MMOORA.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#' Implementation of MULTIMOORA Method for Multi-Criteria Decision Making Problems.
#'
#' @description The \code{MMOORA} function implements both the Multi-Objetive Optimization by Ration Analysis (MOORA) and the "Full Multiplicative Form" (MULTIMOORA).
#' @param decision The decision matrix (\emph{m} x \emph{n}) with the values of the \emph{m} alternatives, for the \emph{n} criteria.
#' @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{MMOORA} returns a data frame which contains the scores and the four rankings calculated (Ratio System, Reference Point, Multiplicative Form and Multi-MOORA ranking).
#' @return \code{MMOORA} returns a data frame which contains the scores and the four rankings calculated (Ratio System, Reference Point, Multiplicative Form and Multi-MOORA ranking).
#' @references Brauers, W. K. M.; Zavadskas, E. K. Project management by MULTIMOORA as an instrument for transition economies. Technological and Economic Development of Economy, 16(1), 5-24, 2010.
#' @examples
#'
#' d <- matrix(rpois(12, 5), nrow = 4)
#' w <- c(0.2, 0.2, 0.6)
#' cb <- c('max','min','max')
#'
#' d <- matrix(c(60,6.35,6.8,10,2.5,4.5,3,0.4,0.15,0.1,0.2,0.1,0.08,0.1,2540,1016,1727.2,
#' 1000,560,1016,1778,500,3000,1500,2000,500,350,1000,990,1041,1676,965,915,508,920),
#' nrow=7,ncol=5)
#' w <- c(0.036,0.192,0.326,0.326,0.12)
#' cb <- c('max','min','max','max','max')
#' MMOORA(d,w,cb)

MMOORA <- function(decision, #matrix with all the alternatives
Expand All @@ -33,10 +35,10 @@ MMOORA <- function(decision, #matrix with all the alternatives
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")


#MMOORA method

#1. Normalization and weighting
d = sqrt(colSums(decision^2))
NW <- matrix(nrow = nrow(decision), ncol = ncol(decision))
Expand All @@ -48,44 +50,39 @@ MMOORA <- function(decision, #matrix with all the alternatives
NR <- NW
for(j in 1:ncol(decision)){
if (cb[j] == 'min'){
NR[,j] <- NW[,j]*(-1)
NR[,j] <- NW[,j]*(-1)
}
}
RS <- apply(NR, 1, sum)

#3. Reference point
Ref <- as.integer(cb == "max") * apply(NW, 2, max) +
Ref <- as.integer(cb == "max") * apply(NW, 2, max) +
as.integer(cb == "min") * apply(NW, 2, min)
RefP <- matrix(nrow = nrow(decision), ncol = ncol(decision))
for(j in 1:ncol(decision)){
RefP[,j] <- abs(Ref[j]-NW[,j])
}
RP <- apply(RefP, 1, max)

#4. Multiplicative form
NEW <- matrix(nrow = nrow(decision), ncol = ncol(decision))
for(j in 1:ncol(decision)){
NEW[,j] <- (decision[,j] / d[j]) ^ weights[j]
}

max <- NEW
min <- NEW
for (j in 1:ncol(NEW)){
max <- NW
min <- NW
for (j in 1:ncol(NW)){
if (cb[j] == 'max'){
min[,j] <- 1
}else{
max[,j] <- 1
}
}
}
A <- apply(max, 1, prod)
B <- apply(min, 1, prod)
M <- A/B

#5. Ranking the alternatives
Rrs <- rank(-RS)
Rrp <- rank(RP)
Rm <- rank(-M)
R <- Rrs + Rrp + Rm
return(data.frame(Alternatives = 1:nrow(decision), RatioSystem = RS, Ranking = rank(-RS, ties.method= "random"), ReferencePoint = RP, Ranking = rank(RP, ties.method= "random"), MultiplicativeForm = M, Ranking = rank(-M, ties.method= "random"), MultiMooraRanking = rank(R, ties.method= "random")))
}
Rrs <- rank(-RS, ties.method= "first")
Rrp <- rank(RP, ties.method= "first")
Rm <- rank(-M, ties.method= "first")
MMRanking = TheoryOfDominance(Rrs,Rrp,Rm,decision)
return(data.frame(Alternatives = 1:nrow(decision), RatioSystem = RS, Ranking = Rrs, ReferencePoint = RP, Ranking = Rrp, MultiplicativeForm = M, Ranking = Rm, MultiMooraRanking = MMRanking))

}
127 changes: 64 additions & 63 deletions R/MetaRanking.R
Original file line number Diff line number Diff line change
@@ -1,63 +1,64 @@
#' Implementation of MetaRanking function for Multi-Criteria Decision Making Problems.
#'
#' @description The \code{MetaRanking} function internally calls functions \code{MMOORA}, \code{TOPSIS}, \code{VIKOR} and \code{WASPAS} and then calculates a sum of the their rankings.
#' @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.
#' @param lambda A value in [0,1]. It is used in the calculation of the W index for WASPAS method.
#' @param v A value in [0,1]. It is used in the calculation of the Q index for VIKOR method.
#' @return \code{MetaRanking} returns a data frame which contains the rankings of the Multi-MOORA, TOPSIS, VIKOR, WASPAS Methods and the MetaRanking of the alternatives.
#' @examples
#'
#' d <- matrix(rpois(12, 5), nrow = 4)
#' w <- c(0.2, 0.2, 0.6)
#' cb <- c('max','min','max')
#' lambda <- 0.5
#' v <- 0.5
#' MetaRanking(d,w,cb,lambda,v)

MetaRanking <- 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")
lambda, #value with the real number of the 'lambda' parameter to calculate W
v #value with the real number of the 'v' parameter to calculate Q
)
{
#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")
if(missing(lambda))
stop("a value for 'lambda' in [0,1] should be provided")
if(missing(v))
stop("a value for 'v' in [0,1] should be provided")


#Multi-MOORA method
MMoora = MMOORA(decision,weights,cb)

#TOPSIS method
Topsis = TOPSIS(decision,weights,cb)

#VIKOR method
Vikor = VIKOR(decision,weights,cb,v)

#WASPAS method
Waspas = WASPAS(decision,weights,cb,lambda)

#Meta-Ranking
MetaR = MMoora[,8]+Topsis[,3]+Vikor[,5]+Waspas[,3]
return(data.frame(Alternatives = 1:nrow(decision), MMOORA = MMoora[,8], TOPSIS = Topsis[,3], VIKOR = Vikor[,5], WASPAS = Waspas[,3], METARANKING = rank(MetaR, ties.method= "random")))

}
#' Implementation of MetaRanking function for Multi-Criteria Decision Making Problems.
#'
#' @description The \code{MetaRanking} function internally calls functions \code{MMOORA}, \code{RIM}, \code{TOPSISLinear}, \code{TOPSISVector}, \code{VIKOR} and \code{WASPAS} and then calculates a sum of the their rankings and an aggregated ranking by applying the \code{RankAggreg} package.
#' @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.
#' @param lambda A value in [0,1]. It is used in the calculation of the W index for WASPAS method.
#' @param v A value in [0,1]. It is used in the calculation of the Q index for VIKOR method.
#' @param AB A matrix (\emph{2} x \emph{n}). AB[1,] corresponds with the A extrem, and AB[2,] represents the B extrem of the domain of each criterion.
#' @param CD A matrix (\emph{2} x \emph{n}). CD[1,] corresponds with the C extrem, and CD[2,] represents the D extrem of the ideal reference of each criterion.
#' @return \code{MetaRanking} returns a data frame which contains the rankings of the Multi-MOORA, RIM, TOPSISLinear, TOPSISVector, VIKOR, WASPAS Methods and the both MetaRankings of the alternatives.
#' @examples
#'
#' d <- matrix(c(1,2,5,3000,3750,4500),nrow = 3,ncol = 2)
#' w <- c(0.5,0.5)
#' cb <- c('min','max')
#' lambda <- 0.5
#' v <- 0.5
#' AB <- matrix(c(1,5,3000,4500),nrow = 2,ncol=2)
#' CD <- matrix(c(1,1,4500,4500),nrow = 2,ncol=2)
#' MetaRanking(d,w,cb,lambda,v,AB,CD)

MetaRanking <- 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")
lambda, #value with the real number of the 'lambda' parameter to calculate W
v, #value with the real number of the 'v' parameter to calculate Q
AB, #matrix with the range [A,B] of the universe of discourse
CD #matrix with the Reference Ideal [C,D]
)
{

#Multi-MOORA method
MMoora = MMOORA(decision,weights,cb)

#RIM
Rim = RIM(decision, weights, AB, CD)

#TOPSIS method
TopsisV = TOPSISVector(decision,weights,cb)
TopsisL = TOPSISLinear(decision,weights,cb)

#VIKOR method
Vikor = VIKOR(decision,weights,cb,v)

#WASPAS method
Waspas = WASPAS(decision,weights,cb,lambda)

#Meta-Ranking
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)
RA = RankAggreg::BruteAggreg(ra, nrow(decision), distance="Spearman")
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))

}
76 changes: 76 additions & 0 deletions R/RIM.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#' Implementation of RIM Method for Multi-Criteria Decision Making Problems.
#'
#' @description The \code{RIM} function implements the Reference Ideal Method (RIM).
#' @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 AB A matrix (\emph{2} x \emph{n}). AB[1,] corresponds with the A extrem, and AB[2,] represents the B extrem of the domain of each criterion.
#' @param CD A matrix (\emph{2} x \emph{n}). CD[1,] corresponds with the C extrem, and CD[2,] represents the D extrem of the ideal reference of each criterion.
#' @return \code{RIM} returns a data frame which contains the score of the R index and the ranking of the alternatives.
#' @references Cables, E.; Lamata, M.T.; Verdegay, J.L. RIM-reference ideal method in multicriteria decision making. Information Science, 337-338, 1-10, 2016.
#' @examples
#'
#' d <- matrix(c(30,40,25,27,45,0,9,0,0,15,2,1,3,5,2,3,3,1,3,2,3,2,3,3,3,2,2,2,1,4),
#' nrow = 5, ncol = 6)
#' w <- c(0.2262,0.2143,0.1786,0.1429,0.119,0.119)
#' AB = matrix(c(23,60,0,15,0,10,1,3,1,3,1,5),nrow = 2,ncol = 6)
#' CD = matrix(c(30,35,10,15,0,0,3,3,3,3,4,5),nrow = 2,ncol = 6)
#' RIM(d,w,AB,CD)

RIM <- function(decision, #matrix with all the alternatives
weights, #vector with the numeric values of the weights
AB, #matrix with the range [A,B] of the universe of discourse
CD #matrix with the Reference Ideal [C,D]
)
{
#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(length(weights) != ncol(decision))
stop("length of 'weights' does not match the number of the criteria")
if(ncol(AB) != ncol(decision))
stop("length of 'AB' does not match the number of the criteria")
if(ncol(CD) != ncol(decision))
stop("length of 'CD' does not match the number of the criteria")


#1. Normalization and weighting
N <- matrix(nrow = nrow(decision), ncol = ncol(decision))
for(j in 1:ncol(decision)){
for(i in 1:nrow(decision)){
if((decision[i,j] >= CD[1,j]) && (decision[i,j]<= CD[2,j])){
N[i,j]=1
}
else if( ((decision[i,j]>= AB[1,j]) && (decision[i,j]<= CD[1,j])) && (AB[1,j]!=CD[1,j])){
N[i,j]=1-(min(abs(decision[i,j]-CD[1,j]),abs(decision[i,j]-CD[2,j]))/abs(AB[1,j]-CD[1,j]))
}
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")
}
}


W <- diag(weights)
NW <- N%*%W

#2. Distances to the ideal solutions
posDis = c(1:nrow(decision))
negDis = c(1:nrow(decision))
for(i in 1:nrow(decision)){
posDis[i] = sqrt(sum((NW[i,]-weights)^2))
negDis[i] = sqrt(sum(NW[i,]^2))
}


#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 663692f

Please sign in to comment.