From f061253c234d6798a252406d862c74a3406eabea Mon Sep 17 00:00:00 2001 From: Dawand Sulaiman Date: Sun, 27 Oct 2019 01:49:30 +0100 Subject: [PATCH] Fixing the dValue bug in calculateDistance of TOPSIS --- src/main/java/Profiler.java | 6 +++--- src/main/java/Test.java | 8 ++++---- src/main/java/Topsis.java | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/Profiler.java b/src/main/java/Profiler.java index 2580398..5023e7c 100644 --- a/src/main/java/Profiler.java +++ b/src/main/java/Profiler.java @@ -50,7 +50,7 @@ private ArrayList profileNode(String node) { siteCriteria.add(Fuzzy.VERY_LOW); } - //Mobile-2 +// //Mobile-2 else if (node.equalsIgnoreCase(Config.alternatives[1])) { siteCriteria.add(Fuzzy.VERY_HIGH); siteCriteria.add(Fuzzy.LOW); @@ -83,7 +83,7 @@ else if (node.equalsIgnoreCase(Config.alternatives[4])) { siteCriteria.add(Fuzzy.HIGH); siteCriteria.add(Fuzzy.HIGH); siteCriteria.add(Fuzzy.HIGH); - siteCriteria.add(Fuzzy.LOW); + siteCriteria.add(Fuzzy.GOOD); } //Edge-3 @@ -92,7 +92,7 @@ else if (node.equalsIgnoreCase(Config.alternatives[5])) { siteCriteria.add(Fuzzy.VERY_HIGH); siteCriteria.add(Fuzzy.HIGH); siteCriteria.add(Fuzzy.HIGH); - siteCriteria.add(Fuzzy.LOW); + siteCriteria.add(Fuzzy.HIGH); } //Public-1 diff --git a/src/main/java/Test.java b/src/main/java/Test.java index 2f0b28e..a02d4a8 100644 --- a/src/main/java/Test.java +++ b/src/main/java/Test.java @@ -19,10 +19,10 @@ private void calculateAHP(){ // compArray[9] = Config.SECURITY_PRICE; double[] dm = {1.0, 5.0, 7.0, 9.0, 5.0, 6.0, 8.0, 3.0, 3.0, 2.0}; // DM1 -// double[] dm = {7.0, 7.0, 9.0, 9.0, 1.0, 7.0, 7.0, 7.0, 7.0, 1.0}; // DM2 -// double[] dm = {1.0/7.0, 1.0, 3.0, 3.0, 5.0, 9.0, 9.0, 7.0, 7.0, 1.0}; // DM3 -// double[] dm = {1.0, 1.0, 1.0/9.0, 1.0, 1.0, 1.0/9.0, 1.0, 1.0/9.0, 1.0, 9.0}; // DM4 -// double[] dm = {1.0, 2.0, 7.0, 1.0/9.0, 2.0, 7.0, 1.0/9.0, 4.0, 1.0/9.0, 1.0/9.0}; // DM5 +// double[] dm = {5.0, 7.0, 9.0, 9.0, 3.0, 7.0, 9.0, 7.0, 7.0, 1.0}; // DM2 +// double[] dm = {1.0/9.0, 1.0, 3.0, 3.0, 3.0, 9.0, 9.0, 9.0, 9.0, 1.0}; // DM3 +// double[] dm = {1.0, 3.0, 1.0/9.0, 5.0, 3.0, 1.0/9.0, 5.0, 1.0/9.0, 5.0, 9.0}; // DM4 +// double[] dm = {1.0, 3.0, 7.0, 1.0/9.0, 5.0, 7.0, 1.0/9.0, 3.0, 1.0/9.0, 1.0/9.0}; // DM5 System.arraycopy(dm, 0, compArray, 0, 10); diff --git a/src/main/java/Topsis.java b/src/main/java/Topsis.java index b649887..b75fe5b 100644 --- a/src/main/java/Topsis.java +++ b/src/main/java/Topsis.java @@ -18,8 +18,8 @@ void start(){ availableSites = p.start(); sitesMatrix = transformToFuzzyValues(availableSites); - TreeMap> normalisedSitesMatrix = calculateNormalisedFuzzyMatrix(sitesMatrix); - TreeMap> normalisedWeightedFuzzyMatrix = calculateWeightedFuzzyMatrix(normalisedSitesMatrix); +// TreeMap> normalisedSitesMatrix = calculateNormalisedFuzzyMatrix(sitesMatrix); + TreeMap> normalisedWeightedFuzzyMatrix = calculateWeightedFuzzyMatrix(sitesMatrix); TreeMap idealDistances = calculateDistance(normalisedWeightedFuzzyMatrix, true); TreeMap antiIdealDistances = calculateDistance(normalisedWeightedFuzzyMatrix, false); @@ -197,32 +197,32 @@ private ArrayList profileNode(String node){ private TreeMap calculateDistance(TreeMap> sitesMatrix, boolean ideal) { EuclideanDistance distance = new EuclideanDistance(); // The normalized values for the ideal solution and negative ideal solution on criteria are always (1,1,1) and (0,0,0) respectively - double dValue = 0.0; TreeMap results = new TreeMap<>(); for (Map.Entry> entry: sitesMatrix.entrySet()) { + double dValue = 0.0; for (int i = 0; i < entry.getValue().size(); i = i + 3) { double[] fuzzyValues = {entry.getValue().get(i), entry.getValue().get(i+1), entry.getValue().get(i+2)}; if (ideal) { // For D+ if (Config.costCriteria[i/3]) { // cost value for price criterion - dValue += distance.compute(Config.antiIdealSolution, fuzzyValues) * (1.0/3.0); + dValue += distance.compute(fuzzyValues, Config.antiIdealSolution) * (1.0/3.0); // dValue += Math.sqrt((Math.pow(entry.getValue().get(i) - Config.antiIdealSolution[0], 2) + // Math.pow(entry.getValue().get(i+1) - Config.antiIdealSolution[1], 2) + // Math.pow(entry.getValue().get(i+2) - Config.antiIdealSolution[2], 2)) * (1.0/3.0)); } else { - dValue += distance.compute(Config.idealSolution, fuzzyValues) * (1.0/3.0); + dValue += distance.compute(fuzzyValues, Config.idealSolution) * (1.0/3.0); // dValue += Math.sqrt((Math.pow(entry.getValue().get(i) - Config.idealSolution[0], 2) + // Math.pow(entry.getValue().get(i+1) - Config.idealSolution[1], 2) + // Math.pow(entry.getValue().get(i+2) - Config.idealSolution[2], 2)) * (1.0/3.0)); } } else { // For D- if (Config.costCriteria[i/3]) { // cost value for price criterion - dValue += distance.compute(Config.idealSolution, fuzzyValues) * (1.0/3.0); + dValue += distance.compute(fuzzyValues, Config.idealSolution) * (1.0/3.0); // dValue += Math.sqrt((Math.pow(entry.getValue().get(i) - Config.idealSolution[0], 2) + // Math.pow(entry.getValue().get(i+1) - Config.idealSolution[1], 2) + // Math.pow(entry.getValue().get(i+2) - Config.idealSolution[2], 2)) * (1.0/3.0)); } else { - dValue += distance.compute(Config.antiIdealSolution, fuzzyValues) * (1.0/3.0); + dValue += distance.compute(fuzzyValues, Config.antiIdealSolution) * (1.0/3.0); // dValue += Math.sqrt((Math.pow(entry.getValue().get(i) - Config.antiIdealSolution[0], 2) + // Math.pow(entry.getValue().get(i+1) - Config.antiIdealSolution[1], 2) + // Math.pow(entry.getValue().get(i+2) - Config.antiIdealSolution[2], 2)) * (1.0/3.0));