Skip to content

Commit

Permalink
Fixing the dValue bug in calculateDistance of TOPSIS
Browse files Browse the repository at this point in the history
  • Loading branch information
dawand committed Oct 27, 2019
1 parent 1f4eb87 commit f061253
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/main/java/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private ArrayList<Fuzzy> 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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/Topsis.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void start(){
availableSites = p.start();

sitesMatrix = transformToFuzzyValues(availableSites);
TreeMap<String, ArrayList<Double>> normalisedSitesMatrix = calculateNormalisedFuzzyMatrix(sitesMatrix);
TreeMap<String, ArrayList<Double>> normalisedWeightedFuzzyMatrix = calculateWeightedFuzzyMatrix(normalisedSitesMatrix);
// TreeMap<String, ArrayList<Double>> normalisedSitesMatrix = calculateNormalisedFuzzyMatrix(sitesMatrix);
TreeMap<String, ArrayList<Double>> normalisedWeightedFuzzyMatrix = calculateWeightedFuzzyMatrix(sitesMatrix);

TreeMap<String, Double> idealDistances = calculateDistance(normalisedWeightedFuzzyMatrix, true);
TreeMap<String, Double> antiIdealDistances = calculateDistance(normalisedWeightedFuzzyMatrix, false);
Expand Down Expand Up @@ -197,32 +197,32 @@ private ArrayList<Fuzzy> profileNode(String node){
private TreeMap<String, Double> calculateDistance(TreeMap<String, ArrayList<Double>> 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<String, Double> results = new TreeMap<>();

for (Map.Entry<String,ArrayList<Double>> 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));
Expand Down

0 comments on commit f061253

Please sign in to comment.