From f2f8bb60d3df3b2a0ca4afa0572330ef2762f007 Mon Sep 17 00:00:00 2001 From: jbytecode Date: Wed, 2 Feb 2022 20:16:20 +0300 Subject: [PATCH] update copeland and add a test --- CHANGELOG.md | 5 + Project.toml | 2 +- src/codas.jl | 1 + src/copeland.jl | 14 +++ test/testcopeland.jl | 293 +++++++++++++++++++++++++++++++++++++------ 5 files changed, 279 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6432594..25b2691 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.3.4 +- Add new tests for Copeland +- Documentation added for Copeland + + ### 0.3.3 - ROV (Range of Value) Method implemented. diff --git a/Project.toml b/Project.toml index 75b742f..71163a3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JMcDM" uuid = "358108f5-d052-4d0a-8344-d5384e00c0e5" authors = ["Mehmet Hakan Satman (jbytecode) ", "Bahadir Fatih Yildirim "] -version = "0.3.3" +version = "0.3.4" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" diff --git a/src/codas.jl b/src/codas.jl index 2dbdc69..28abb4e 100644 --- a/src/codas.jl +++ b/src/codas.jl @@ -145,6 +145,7 @@ end """ codas(setting; tau = 0.02) + Apply CODAS (COmbinative Distance-based ASsessment) method for a given matrix, weights and, type of criteria. # Arguments: diff --git a/src/copeland.jl b/src/copeland.jl index def1f8c..48543ff 100644 --- a/src/copeland.jl +++ b/src/copeland.jl @@ -33,6 +33,20 @@ function winloss_scores(dommat::Array{Int, 2})::Array{Int, 2} return winlossmat end +""" + copeland(ordering_mat) + +# Arguments + - `ordering_mat`::Array{Int, 2}`: Ordering matrix. + +# Description +The function takes an ordering matrix as input. Different ordering results are in columns. +Orderings are in ascending order. The function returns the ranks. The alternative with rank +1 is the winner. + +# Output +- `::Array{Int, 1}`: Vector of ranks. +""" function copeland(ordering_mat::Array{Int, 2})::Array{Int, 1} winlosses = ordering_mat |> dominance_scores |> winloss_scores n, _ = size(winlosses) diff --git a/test/testcopeland.jl b/test/testcopeland.jl index 1429d6e..af8653c 100644 --- a/test/testcopeland.jl +++ b/test/testcopeland.jl @@ -1,37 +1,260 @@ @testset "Copeland" begin - """ - This example is interpreted from the results of - - Arslan, Rahim, and Hüdaverdi Bircan. "Çok Kriterli Karar Verme Teknikleriyle Elde Edilen - Sonuçların Copeland Yöntemiyle Birleştirilmesi ve Karşılaştırılması." Yönetim ve Ekonomi: - Celal Bayar Üniversitesi İktisadi ve İdari Bilimler Fakültesi Dergisi 27.1 (2020): 109-127. - - for testing the method. - """ - topsis_ord = - [7, 17, 3, 14, 6, 18, 10, 19, 8, 15, 22, 12, 2, 9, 23, 11, 16, 20, 5, 13, 1, 21, 4] - gia_ord = - [9, 17, 3, 14, 6, 18, 7, 19, 8, 16, 22, 13, 1, 10, 23, 11, 15, 20, 5, 12, 2, 21, 4] - vikor_ord = - [7, 17, 3, 14, 5, 18, 10, 19, 8, 16, 22, 13, 1, 9, 23, 11, 15, 20, 6, 12, 2, 21, 4] - mooraref_ord = - [3, 14, 2, 15, 16, 21, 10, 23, 8, 9, 19, 6, 7, 5, 22, 17, 13, 18, 12, 11, 1, 20, 4] - copras_ord = - [7, 17, 3, 14, 6, 18, 11, 19, 8, 15, 22, 12, 1, 9, 23, 10, 16, 20, 5, 13, 2, 21, 4] - moora_ord = - [7, 17, 3, 14, 5, 18, 11, 19, 8, 15, 22, 12, 1, 9, 23, 10, 16, 20, 6, 13, 2, 21, 4] - aras_ord = - [7, 17, 3, 14, 6, 18, 11, 19, 8, 15, 22, 12, 1, 9, 23, 10, 16, 20, 5, 13, 2, 21, 4] - - mat = hcat(topsis_ord, gia_ord, vikor_ord, mooraref_ord) - - c = copeland(mat) - - d = c |> sortperm - - #show(d) - #@info d - - @test d == [15, 11, 22, 18, 8, 6, 2, 10, 17, 4, 12, 20, 16, 7, 14, 9, 1, 5, 19, 23, 3, 13, 21] - + + @testset "Copeland Example 1" begin + """ + This example is interpreted from the results of + + Arslan, Rahim, and Hüdaverdi Bircan. "Çok Kriterli Karar Verme Teknikleriyle Elde Edilen + Sonuçların Copeland Yöntemiyle Birleştirilmesi ve Karşılaştırılması." Yönetim ve Ekonomi: + Celal Bayar Üniversitesi İktisadi ve İdari Bilimler Fakültesi Dergisi 27.1 (2020): 109-127. + + for testing the method. + """ + topsis_ord = [ + 7, + 17, + 3, + 14, + 6, + 18, + 10, + 19, + 8, + 15, + 22, + 12, + 2, + 9, + 23, + 11, + 16, + 20, + 5, + 13, + 1, + 21, + 4, + ] + gia_ord = [ + 9, + 17, + 3, + 14, + 6, + 18, + 7, + 19, + 8, + 16, + 22, + 13, + 1, + 10, + 23, + 11, + 15, + 20, + 5, + 12, + 2, + 21, + 4, + ] + vikor_ord = [ + 7, + 17, + 3, + 14, + 5, + 18, + 10, + 19, + 8, + 16, + 22, + 13, + 1, + 9, + 23, + 11, + 15, + 20, + 6, + 12, + 2, + 21, + 4, + ] + mooraref_ord = [ + 3, + 14, + 2, + 15, + 16, + 21, + 10, + 23, + 8, + 9, + 19, + 6, + 7, + 5, + 22, + 17, + 13, + 18, + 12, + 11, + 1, + 20, + 4, + ] + copras_ord = [ + 7, + 17, + 3, + 14, + 6, + 18, + 11, + 19, + 8, + 15, + 22, + 12, + 1, + 9, + 23, + 10, + 16, + 20, + 5, + 13, + 2, + 21, + 4, + ] + moora_ord = [ + 7, + 17, + 3, + 14, + 5, + 18, + 11, + 19, + 8, + 15, + 22, + 12, + 1, + 9, + 23, + 10, + 16, + 20, + 6, + 13, + 2, + 21, + 4, + ] + aras_ord = [ + 7, + 17, + 3, + 14, + 6, + 18, + 11, + 19, + 8, + 15, + 22, + 12, + 1, + 9, + 23, + 10, + 16, + 20, + 5, + 13, + 2, + 21, + 4, + ] + + mat = hcat(topsis_ord, gia_ord, vikor_ord, mooraref_ord) + + c = copeland(mat) + + d = c |> sortperm + + #show(d) + #@info d + + @test d == [ + 15, + 11, + 22, + 18, + 8, + 6, + 2, + 10, + 17, + 4, + 12, + 20, + 16, + 7, + 14, + 9, + 1, + 5, + 19, + 23, + 3, + 13, + 21, + ] + + end + + + @testset "Copeland Example 2" begin + """ + This example is interpreted from the result of + + Özdağoğlu, Aşkın, et al. "Combining different MCDM methods with the Copeland method: + An investigation on motorcycle selection." Journal of process management and new + technologies 9.3-4 (2021): 13-27. + + in this test. + """ + mopa_rank = [1, 4, 2, 3] + moosra_rank = [1, 2, 3, 4] + copras_rank = [1, 3, 2, 4] + saw_rank = [1, 3, 2, 4] + wpm_rank = [1, 3, 2, 4] + rov_rank = [4, 1, 2, 3] + + mopa_order = reverse(mopa_rank) + moosra_order = reverse(moosra_rank) + copras_order = reverse(copras_rank) + saw_order = reverse(saw_rank) + wpm_order = reverse(wpm_rank) + rov_order = reverse(rov_rank) + + mat = hcat(mopa_order, moosra_order, copras_order, saw_order, wpm_order, rov_order) + + c = copeland(mat) + + d = c |> sortperm + + @test d == [1, 3, 2, 4] + end + end