Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
Code_Sidang_Ulang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ari Whuandaniel Manurung
Code_Sidang_Ulang
Commits
33c11764
Commit
33c11764
authored
Jul 25, 2020
by
ratna kasmala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
20ca7f69
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
143 additions
and
0 deletions
+143
-0
VIKOR.ipynb
VIKOR.ipynb
+143
-0
No files found.
VIKOR.ipynb
0 → 100644
View file @
33c11764
{
"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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment