From 121fdca1585bafa4118c62408b32a26c23446c02 Mon Sep 17 00:00:00 2001 From: jbytecode Date: Mon, 13 Dec 2021 19:02:22 +0300 Subject: [PATCH] fixed electre, pump version v0.2.6 --- Project.toml | 2 +- src/electre.jl | 15 ++++++++++----- test/testmcdm.jl | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index bedb635..787d61b 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.2.5" +version = "0.2.6" [deps] Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76" diff --git a/src/electre.jl b/src/electre.jl index 27b1713..e0f9213 100755 --- a/src/electre.jl +++ b/src/electre.jl @@ -128,10 +128,15 @@ function electre(decisionMat::DataFrame, weights::Array{Float64,1}, fns::Array{F r_ik_full = weightednormalizedMat[i, :] r_jk_full = weightednormalizedMat[j, :] - nom = maximum(abs.(r_ik - r_jk)) - dom = maximum(abs.(r_ik_full - r_jk_full)) - nonfitnessmatrix[i, j] = nom / dom - end + if length(r_ik) > 0 && length(r_jk) > 0 + nom = maximum(abs.(r_ik - r_jk)) + dom = maximum(abs.(r_ik_full - r_jk_full)) + nonfitnessmatrix[i, j] = nom / dom + else + nonfitnessmatrix[i, j] = Inf64 + end # end if + + end # end for C = zeros(Float64, nalternatives) D = zeros(Float64, nalternatives) @@ -153,7 +158,7 @@ function electre(decisionMat::DataFrame, weights::Array{Float64,1}, fns::Array{F result = ElectreResult( decisionMat, w, - weightednormalizedMat, + weightednormalizedMat, fitnessTable, nonfitnessTable, fitnessmatrix, diff --git a/test/testmcdm.jl b/test/testmcdm.jl index 54a843b..01c4b7e 100644 --- a/test/testmcdm.jl +++ b/test/testmcdm.jl @@ -154,6 +154,21 @@ @test result3.bestIndex == result.bestIndex end + @testset "Electre (failed in previous release <= v0.2.5" begin + df = DataFrame( + x = [1.0, 2.0, 3.0, 2.0], + y = [1.0, 2.0, 1.0, 1.0], + z = [1.0, 3.0, 2.0, 2.0], + k = [4.0, 2, 1, 4], + ) + fns = makeminmax([maximum, maximum, maximum, maximum]) + ws = [0.25, 0.25, 0.25, 0.25] + e = electre(df, ws, fns) + + @test e isa ElectreResult + @test e.bestIndex == (2, 1) + end + @testset "MOORA" begin tol = 0.00001