Skip to content

Commit

Permalink
Try to fix diagram-consistency stage
Browse files Browse the repository at this point in the history
  • Loading branch information
dfuchss committed Jan 16, 2024
1 parent 79bf9b9 commit f0619ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.diagramconsistency.evaluation;

import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Objects;

import org.eclipse.collections.api.bimap.MutableBiMap;
import org.eclipse.collections.impl.bimap.mutable.HashBiMap;

/**
* Metrics of the diagram-model matching process.
Expand All @@ -20,7 +21,7 @@
* @param <M>
* The type of the model elements.
*/
public record MapMetrics<R, M>(MutableBiMap<R, M> truePositives, MutableBiMap<R, M> falsePositives, MutableBiMap<R, M> falseNegatives) implements Metrics {
public record MapMetrics<R, M>(Map<R, M> truePositives, Map<R, M> falsePositives, Map<R, M> falseNegatives) implements Metrics {
/**
* Create a new metrics object from the expected and actual links.
*
Expand All @@ -34,10 +35,10 @@ public record MapMetrics<R, M>(MutableBiMap<R, M> truePositives, MutableBiMap<R,
* The type of the model elements.
* @return The metrics.
*/
public static <R, M> MapMetrics<R, M> from(MutableBiMap<R, M> expected, MutableBiMap<R, M> actual) {
MutableBiMap<R, M> truePositives = new HashBiMap<>();
MutableBiMap<R, M> falsePositives = new HashBiMap<>();
MutableBiMap<R, M> falseNegatives = new HashBiMap<>();
public static <R, M> MapMetrics<R, M> from(Map<R, M> expected, MutableBiMap<R, M> actual) {
Map<R, M> truePositives = new IdentityHashMap<>();
Map<R, M> falsePositives = new IdentityHashMap<>();
Map<R, M> falseNegatives = new IdentityHashMap<>();

for (var entry : actual.entrySet()) {
if (Objects.equals(expected.get(entry.getKey()), entry.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* Licensed under MIT 2023. */
/* Licensed under MIT 2023-2024. */
package edu.kit.kastel.mcse.ardoco.core.diagramconsistency.evaluation;

import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.io.IOException;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -129,7 +130,7 @@ private <M> void doIterationsOnRefactoredModel(AnnotatedDiagram<M> diagram, Anno
MutableBiMap<Vertex<Box>, Vertex<M>> expectedLinks = new HashBiMap<>();

for (Map.Entry<M, Vertex<M>> link : refactoredModel.links().inverse().entrySet()) {
Box box = diagram.links().inverse().get(link.getKey());
Box box = inverse(diagram.links()).get(link.getKey());
Vertex<Box> vertex = boxToVertex.get(box);
expectedLinks.put(vertex, link.getValue());
}
Expand All @@ -141,6 +142,16 @@ private <M> void doIterationsOnRefactoredModel(AnnotatedDiagram<M> diagram, Anno
}
}

private static <A, B> Map<B, A> inverse(Map<A, B> map) {
Map<B, A> result = new IdentityHashMap<>();
for (Map.Entry<A, B> entry : map.entrySet()) {
if (result.put(entry.getValue(), entry.getKey()) != null) {
throw new IllegalStateException("Duplicate value: " + entry.getValue());
}
}
return result;
}

private <M> MutableBiMap<Vertex<Box>, Vertex<M>> match(DirectedMultigraph<Vertex<Box>, Edge> a, DirectedMultigraph<Vertex<M>, Edge> b) {
SimilarityFloodingAlgorithm<Vertex<Box>, Vertex<M>, Label> algorithm = new SimilarityFloodingAlgorithm<>(
SyntheticDiagramMatchingEvaluationTest.DEFAULT_EPSILON, 10000, PropagationCoefficientFormula.getInverseProductFormula(), FixpointFormula
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
package edu.kit.kastel.mcse.ardoco.core.diagramconsistency.evaluation.data;

import java.io.File;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Function;

import org.eclipse.collections.api.bimap.MutableBiMap;
Expand Down Expand Up @@ -36,7 +39,7 @@
* @param <M>
* The element type of the model.
*/
public record AnnotatedDiagram<M>(Diagram diagram, MutableBiMap<Box, M> links, Set<Inconsistency<Box, M>> inconsistencies) {
public record AnnotatedDiagram<M>(Diagram diagram, Map<Box, M> links, Set<Inconsistency<Box, M>> inconsistencies) {
/**
* Create an annotated diagram from a diagram.
*
Expand Down Expand Up @@ -82,15 +85,20 @@ public static AnnotatedDiagram<ArchitectureItem> createFrom(String source, Archi
*/
public static AnnotatedDiagram<CodeItem> createFrom(String source, CodeModel model) {
Diagram diagram = new DiagramImpl(source, new File(source));
MutableBiMap<CodeItem, Box> links = new HashBiMap<>();
SortedMap<CodeItem, Box> links = new TreeMap<>();

Transformations.transform(model, (item) -> {
Box box = DiagramUtility.addBox(diagram, item.getName());
links.put(item, box);
return box;
}, (from, to) -> DiagramUtility.addConnector(diagram, from, to), (child, parent) -> parent.addContainedBox(child));

return new AnnotatedDiagram<>(diagram, links.inverse(), new LinkedHashSet<>());
Map<Box, CodeItem> identityInverse = new IdentityHashMap<>();
for (Map.Entry<CodeItem, Box> entry : links.entrySet()) {
identityInverse.put(entry.getValue(), entry.getKey());
}

return new AnnotatedDiagram<>(diagram, identityInverse, new LinkedHashSet<>());
}

/**
Expand Down

0 comments on commit f0619ff

Please sign in to comment.