SimpleConflictDetection extends AbstractConflictDetection { @Override public Set<Constraint> getMinConflictSet(Set<Constraint> constraintsSetC) throws DiagnosisException { Set<Constraint> cs = new LinkedHashSet<Constraint>(); if (consistencyChecker.isConsistent(constraintsSetC, fixedModel)) { return null; } Set<Constraint> intermediaryCS = new LinkedHashSet<Constraint>(); boolean isInconsistent; do { intermediaryCS.clear(); intermediaryCS.addAll(cs); Constraint c = null; do { c = getElement(constraintsSetC, intermediaryCS); if (c == null) { return Collections.emptySet(); } intermediaryCS.add(c); isInconsistent = !consistencyChecker.isConsistent(intermediaryCS, fixedModel); } while (!isInconsistent); appendSet(cs, c); isInconsistent = !consistencyChecker.isConsistent(cs, fixedModel); } while (!isInconsistent); Collections.reverse(new ArrayList<>(cs)); return cs; } SimpleConflictDetection(String mznFullFileName);  SimpleConflictDetection(String mznFullFileName, Collection<? extends Element> fixedModel); @Override Set<Constraint> getMinConflictSet(Set<Constraint> constraintsSetC);  }
@Test public void testSimpleConflictDetection_1() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; File f = new File("testFiles" + File.separator + "testConflictDetection1.mzn"); java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Integer> setOneTwoThree = new RangeExpression(1, 3).toNamedConstant("OneTwoThree"); IntegerVariable x1 = new IntegerVariable("x1", setOneTwoThree); IntegerVariable x2 = new IntegerVariable("x2", setOneTwoThree); IntegerVariable x3 = new IntegerVariable("x3", setOneTwoThree); BooleanExpression expression1 = new RelationalOperation<>(x1, RelationalOperator.EQ, new IntegerConstant(3)); BooleanExpression expression2 = new RelationalOperation<>(x2, RelationalOperator.EQ, new IntegerConstant(3)); Constraint constraint = new Constraint("group", "x1 = 3", expression1); constraintsSetC.add(constraint); constraint = new Constraint("group", "x2 = 3", expression2); constraintsSetC.add(constraint); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(f.getAbsolutePath()); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNull(minCS); }
@Test public void testSimpleConflictDetection_2() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); java.util.Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset2(constraintsSetC, decisionsVar); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(fileName); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNotNull(minCS); assertTrue(minCS.size() == 2); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(0))); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(1))); }
@Test public void testSimpleConflictDetection_2WithMoreConstraints() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); java.util.Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset2WithMoreConstraints(constraintsSetC, decisionsVar); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(fileName); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNotNull(minCS); assertTrue(minCS.size() == 3); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(0))); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(1))); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(3))); }
@Test public void testSimpleConflictDetection_NoConflict() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); java.util.Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset2NoConflict(constraintsSetC, decisionsVar); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(fileName); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNull(minCS); }
@Test public void testSimpleConflictDetection_5() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); java.util.Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset1(constraintsSetC, decisionsVar); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(fileName); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNotNull(minCS); }
@Test public void testSimpleConflictDetection_6() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); java.util.Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset6(constraintsSetC, decisionsVar); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(fileName); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNotNull(minCS); assertTrue(minCS.size() == 2); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(0))); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(1))); }
@Test public void testSimpleConflictDetection_8() throws FileNotFoundException, DiagnosisException { java.util.Set<Constraint> minCS = null; java.util.Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); java.util.Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset8(constraintsSetC, decisionsVar); AbstractConflictDetection conflictDetection = new SimpleConflictDetection(fileName); minCS = conflictDetection.getMinConflictSet(constraintsSetC); assertNotNull(minCS); assertTrue(minCS.size() == 1); assertTrue(minCS.contains(new ArrayList<>(constraintsSetC).get(0))); }