OverlapWithoutEdgesToMissingNodesWeightFunction implements ViolationWeightFunction { @Override public double getWeight(Overlap violation, Overlaps overlaps, Model model) { return getMappedElementsWeight(violation) / getPatternWeight(violation); } OverlapWithoutEdgesToMissingNodesWeightFunction(NodeWeightFunction nodeWeight); @Override double getWeight(Overlap violation, Overlaps overlaps, Model model); @Override String getFormula(Overlap violation, Overlaps overlaps, Model model); @Override String getId();  }
@Test public void noMissingElements() { Overlap instance = instance(buildAUG().withActionNode("A")); double weight = getWeight(instance, node -> 1); assertThat(weight, is(1.0)); }
@Test public void noMissingElements_withEdge() { Overlap instance = instance(buildAUG().withActionNodes("A", "B").withEdge("A", ORDER, "B")); double weight = getWeight(instance, node -> 1); assertThat(weight, is(1.0)); }
@Test public void excludesEdgeToMissingNode() { TestAUGBuilder pattern = buildAUG().withActionNodes("A", "B").withEdge("A", ORDER, "B"); TestAUGBuilder target = buildAUG().withActionNode("A"); Overlap violation = buildOverlap(pattern, target).withNode("A").build(); double weight = getWeight(violation, node -> 1); assertThat(weight, is(0.5)); }
@Test public void considersNodeImportance() { TestAUGBuilder pattern = buildAUG().withActionNodes("A", "B").withEdge("A", ORDER, "B"); Node nodeB = pattern.getNode("B"); TestAUGBuilder target = buildAUG().withActionNode("A"); Overlap violation = buildOverlap(pattern, target).withNode("A").build(); double weightWithEqualImportance = getWeight(violation, node -> 1); double weightWithMissingNodeDoubleImportance = getWeight(violation, node -> node == nodeB ? 2 : 1); assertThat(weightWithEqualImportance, is(lessThan(weightWithMissingNodeDoubleImportance))); }
@Test public void considerNodeImportance2() { TestAUGBuilder pattern = buildAUG().withActionNodes("A", "B", "C") .withEdge("A", ORDER, "B").withEdge("A", ORDER, "C").withEdge("B", ORDER, "C"); Node nodeC = pattern.getNode("C"); TestAUGBuilder target = buildAUG().withActionNodes("A", "B").withEdge("A", ORDER, "B"); Overlap violation = buildOverlap(pattern, target).withNodes("A", "B").withEdge("A", ORDER, "B").build(); double weightWithEqualImportance = getWeight(violation, node -> 1); double weightWithMissingNodeDoubleImportance = getWeight(violation, node -> node == nodeC ? 2 : 1); assertThat(weightWithEqualImportance, is(lessThan(weightWithMissingNodeDoubleImportance))); }