OverlapWeightFunction implements ViolationWeightFunction { @Override public double getWeight(Overlap violation, Overlaps overlaps, Model model) { int violationSize = violation.getSize(); int patternSize = violation.getPattern().getSize(); return violationSize / (float) patternSize; }  @Override double getWeight(Overlap violation, Overlaps overlaps, Model model); String getFormula(Overlap violation, Overlaps overlaps, Model model); @Override String getId();  }
@Test public void considersMissingNodes() { TestAUGBuilder targetBuilder = buildAUG().withActionNode("a"); TestAUGBuilder patternBuilder = extend(targetBuilder).withActionNode("b"); Overlap violation = buildOverlap(patternBuilder, targetBuilder).withNode("a", "a").build(); ViolationWeightFunction weightFunction = new OverlapWeightFunction(); double weight = weightFunction.getWeight(violation, null, null); assertThat(weight, is(0.5)); }
@Test public void considersMissingEdges() { TestAUGBuilder targetBuilder = buildAUG().withActionNodes("a", "b"); TestAUGBuilder patternBuilder = extend(targetBuilder).withEdge("a", ORDER, "b"); Overlap violation = buildOverlap(patternBuilder, targetBuilder).withNode("a", "a").build(); ViolationWeightFunction weightFunction = new OverlapWeightFunction(); double weight = weightFunction.getWeight(violation, null, null); assertThat(weight, is(closeTo(1/3.0, 0.00001))); }