Commit 33c11764 by ratna kasmala

Upload New File

parent 20ca7f69
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-1-4f8651ffc702>, line 8)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-1-4f8651ffc702>\"\u001b[1;36m, line \u001b[1;32m8\u001b[0m\n\u001b[1;33m if(! is.matrix(decision))\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"VIKOR <- function(decision, #matrix with all the alternatives\n",
" weights, #vector with the numeric values of the weights\n",
" cb, #vector with the \"type\" of the criteria (benefit = \"max\", cost = \"min\")\n",
" v #value with the real number of the 'v' parameter to calculate Q\n",
")\n",
"{\n",
" #Checking parameters\n",
" if(! is.matrix(decision))\n",
" stop(\"'decision' must be a matrix with the values of the alternatives\")\n",
" if(missing(weights))\n",
" stop(\"a vector containing n weigths, adding up to 1, should be provided\")\n",
" if(sum(weights) != 1)\n",
" stop(\"The sum of 'weights' is not equal to 1\")\n",
" if(! is.character(cb))\n",
" stop(\"'cb' must be a character vector with the type of the criteria\")\n",
" if(! all(cb == \"max\" | cb == \"min\"))\n",
" stop(\"'cb' should contain only 'max' or 'min'\")\n",
" if(length(weights) != ncol(decision))\n",
" stop(\"length of 'weights' does not match the number of the criteria\")\n",
" if(length(cb) != ncol(decision))\n",
" stop(\"length of 'cb' does not match the number of the criteria\")\n",
" if(missing(v))\n",
" stop(\"a value for 'v' in [0,1] should be provided\")\n",
"\n",
" #1. Ideal solutions\n",
" posI <- as.integer(cb == \"max\") * apply(decision, 2, max) +\n",
" as.integer(cb == \"min\") * apply(decision, 2, min)\n",
" negI <- as.integer(cb == \"min\") * apply(decision, 2, max) +\n",
" as.integer(cb == \"max\") * apply(decision, 2, min)\n",
"\n",
" #2. S and R index\n",
" norm =function(x,w,p,n){\n",
" w*((p-x)/(p-n))\n",
" }\n",
" SAux <- apply(decision, 1, norm, weights, posI, negI)\n",
" S <- apply(SAux, 2, sum)\n",
" R <- apply(SAux, 2, max)\n",
"\n",
"\n",
" #3. Q index\n",
" #If v=0\n",
" if (v==0)\n",
" Q <- (R-min(R))/(max(R)-min(R))\n",
" #If v=1\n",
" else if (v==1)\n",
" Q <- (S-min(S))/(max(S)-min(S))\n",
" #Another case\n",
" else\n",
" Q <- v*(S-min(S))/(max(S)-min(S))+(1-v)*(R-min(R))/(max(R)-min(R))\n",
"\n",
" #4. Checking if Q is valid\n",
" if( (Q == \"NaN\") || (Q == \"Inf\")){\n",
" RankingQ <- rep(\"-\",nrow(decision))\n",
" }else{\n",
" RankingQ <- rank(Q, ties.method= \"first\") \n",
" }\n",
" #5. Ranking the alternatives\n",
" return(data.frame(Alternatives = 1:nrow(decision), S = S, R = R, Q = Q, Ranking = RankingQ))\n",
"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d <- matrix(c(492.3065182591944 , 45000 , 30.100069992688567,\n",
"499.4238816104592 , 45000 , 30.100069992688567,\n",
"403.622103782017 , 45000 , 30.100069992688567,\n",
"388.2312906158455 , 45000 , 30.100069992688567,\n",
"358.77720822367576 , 45000 , 30.100069992688567),\n",
" nrow = 5,ncol = 3)\n",
"\n",
"w <- c(0.4,0.3,0.3)\n",
"cb <- c('min','max','min')\n",
"v <- 0.5\n",
"\n",
"VIKOR(d,w,cb,v)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment