-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3232fb3
commit e02df09
Showing
8 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/com/buchmais/sarf/benchmark/ModularizationQualityCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.buchmais.sarf.benchmark; | ||
|
||
import com.buchmais.sarf.SARFRunner; | ||
import com.buchmais.sarf.repository.MetricRepository; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Stephan Pirnbaum | ||
*/ | ||
public class ModularizationQualityCalculator { | ||
|
||
public static Double computeSimilarityBasedMQ(Map<Long, Set<Long>> decomposition) { | ||
Double intraConnectivity = 0d; | ||
Double interConnectivity = 0d; | ||
MetricRepository metricRepository = SARFRunner.xoManager.getRepository(MetricRepository.class); | ||
for (Map.Entry<Long, Set<Long>> component1 : decomposition.entrySet()) { | ||
long[] ids1 = component1.getValue().stream().mapToLong(l -> l).toArray(); | ||
int denominator = ids1.length == 1 ? 1 : ((ids1.length * (ids1.length - 1)) / 2); | ||
intraConnectivity += metricRepository.computeSimilarityCohesionInComponent(ids1) / denominator; | ||
for (Map.Entry<Long, Set<Long>> component2 : decomposition.entrySet()) { | ||
if (!Objects.equals(component1.getKey(), component2.getKey())) { | ||
long[] ids2 = component2.getValue().stream().mapToLong(l -> l).toArray(); | ||
denominator = ((ids1.length + ids2.length) * (ids1.length + ids2.length - 1)) / 2; | ||
interConnectivity += metricRepository.computeSimilarityCouplingBetweenComponents(ids1, ids2) / denominator; | ||
} | ||
} | ||
} | ||
intraConnectivity /= decomposition.size(); | ||
interConnectivity /= (decomposition.size() * (decomposition.size() - 1)) / 2; | ||
return intraConnectivity - interConnectivity; | ||
} | ||
|
||
public static Double computeCouplingBasedMQ(Map<Long, Set<Long>> decomposition) { | ||
Double intraConnectivity = 0d; | ||
Double interConnectivity = 0d; | ||
MetricRepository metricRepository = SARFRunner.xoManager.getRepository(MetricRepository.class); | ||
for (Map.Entry<Long, Set<Long>> component1 : decomposition.entrySet()) { | ||
long[] ids1 = component1.getValue().stream().mapToLong(l -> l).toArray(); | ||
int denominator = ids1.length == 1 ? 1 : ((ids1.length * (ids1.length - 1)) / 2); | ||
intraConnectivity += metricRepository.computeCouplingCohesionInComponent(ids1) / denominator; | ||
for (Map.Entry<Long, Set<Long>> component2 : decomposition.entrySet()) { | ||
if (!Objects.equals(component1.getKey(), component2.getKey())) { | ||
long[] ids2 = component2.getValue().stream().mapToLong(l -> l).toArray(); | ||
denominator = ((ids1.length + ids2.length) * (ids1.length + ids2.length - 1)) / 2; | ||
interConnectivity += metricRepository.computeCouplingBetweenComponents(ids1, ids2) / denominator; | ||
} | ||
} | ||
} | ||
intraConnectivity /= decomposition.size(); | ||
interConnectivity /= (decomposition.size() * (decomposition.size() - 1)); | ||
return intraConnectivity - interConnectivity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters