FastDiag { public Set<Constraint> getPreferredDiagnosis(Set<Constraint> constraintsSetC, Boolean displayFastDiagSteps) throws DiagnosisException { this.displayfastDiagSteps = displayFastDiagSteps; if (constraintsSetC.isEmpty()) { if (progressCalback != null) { progressCalback.displayMessage("C set is empty" + LINE_SEPARATOR); } return Collections.emptySet(); } if (consistencyChecker.isConsistent(userRequirements, fixedModel)) { if (progressCalback != null) { String displayConstraintListUserRequirements = progressCalback.displayConstraintList(userRequirements); if (displayConstraintListUserRequirements != null) { progressCalback.displayMessage(String.format("KB with %s is consistent, no solution can be found", displayConstraintListUserRequirements.trim())); } } return Collections.emptySet(); } Set<Constraint> ACWithoutC = AbstractConflictDetection.diffSets(userRequirements, constraintsSetC); Boolean searchForDiagnosis = consistencyChecker.isConsistent(ACWithoutC, fixedModel); if (!searchForDiagnosis) { if (progressCalback != null) { String displayConstraintListConstraintsSetC = progressCalback.displayConstraintList(constraintsSetC); String displayConstraintListACWithoutC = progressCalback.displayConstraintList(ACWithoutC); if (displayConstraintListConstraintsSetC != null && displayConstraintListACWithoutC != null) { String isInconsistentMessage = String.format( "Check : %sKB with %s is inconsistent, therefore no diagnosis. %s", displayConstraintListConstraintsSetC, displayConstraintListACWithoutC.trim(), LINE_SEPARATOR); progressCalback.displayMessage(isInconsistentMessage); } } return Collections.emptySet(); } return fd(Collections.emptySet(), Collections.unmodifiableSet(constraintsSetC), Collections.unmodifiableSet(userRequirements), 0, 0, 0); } FastDiag(String mznFullFileName, Set<Constraint> userConstraints, ConflictDetectionAlgorithm algorithm,
			DiagnoseProgressCallback progressCallback);  FastDiag(Collection<? extends Element> fixedModel, Set<Constraint> userConstraints,
      ConflictDetectionAlgorithm algorithm, DiagnoseProgressCallback progressCallback);  FastDiag(String mznFullFileName, Collection<? extends Element> fixedModel, Set<Constraint> userConstraints,
      ConflictDetectionAlgorithm algorithm, DiagnoseProgressCallback progressCallback); private  FastDiag(Set<Constraint> userConstraints, ConflictDetectionAlgorithm algorithm,
      DiagnoseProgressCallback progressCallback); Set<Constraint> getPreferredDiagnosis(Set<Constraint> constraintsSetC, Boolean displayFastDiagSteps);  }
@Test public void testFastDiagWithDataset8() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset8(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); for (Constraint constraint : diag) { System.out.println(constraint.toString()); } assertTrue(!diag.isEmpty()); assertEquals(diag.size(), 3); Constraint c1 = new ArrayList<>(constraintsSetC).get(0); Constraint c3 = new ArrayList<>(constraintsSetC).get(2); Constraint c4 = new ArrayList<>(constraintsSetC).get(3); assertSame(c1, new ArrayList<>(diag).get(0)); assertSame(c3, new ArrayList<>(diag).get(1)); assertSame(c4, new ArrayList<>(diag).get(2)); }
@Test public void testFastDiagWithDataset8ConsistentKB() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset8ConsistentKB(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); for (Constraint constraint : diag) { System.out.println(constraint.toString()); } assertTrue(diag.isEmpty()); }
@Test public void testFastDiagWithDataset2WithMoreConstraints() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset2WithMoreConstraints(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); assertTrue(!diag.isEmpty()); assertEquals(diag.size(), 2); Constraint c4 = new ArrayList<>(constraintsSetC).get(3); Constraint c5 = new ArrayList<>(constraintsSetC).get(4); assertSame(c4, new ArrayList<>(diag).get(0)); assertSame(c5, new ArrayList<>(diag).get(1)); }
@Test public void testFastDiagWithDataset6() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset6(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); assertTrue(!diag.isEmpty()); assertEquals(diag.size(), 1); Constraint c2 = new ArrayList<>(constraintsSetC).get(1); assertSame(c2,new ArrayList<>(diag).get(0)); }
@Test public void testFastDiagWithDataset1() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset1(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); assertTrue(!diag.isEmpty()); assertEquals(diag.size(), 2); Constraint c1 = new ArrayList<>(constraintsSetC).get(0); Constraint c2 = new ArrayList<>(constraintsSetC).get(1); assertSame(c1, new ArrayList<>(diag).get(0)); assertSame(c2, new ArrayList<>(diag).get(1)); }
@Test public void testFastDiagWithDataset2() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getTestDataset2(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); assertTrue(!diag.isEmpty()); assertEquals(diag.size(), 2); Constraint c2 = new ArrayList<>(constraintsSetC).get(1); Constraint c5 = new ArrayList<>(constraintsSetC).get(4); assertSame(c2, new ArrayList<>(diag).get(0)); assertSame(c5, new ArrayList<>(diag).get(1)); }
@Test public void testFastDiagWithMinimalDiagnoses2() throws FileNotFoundException, DiagnosisException { Set<Constraint> constraintsSetC = new LinkedHashSet<Constraint>(); Set<Element> decisionsVar = new LinkedHashSet<Element>(); String fileName = UtilsForTest.getDataTestMinimalDiagnoses2(constraintsSetC, decisionsVar); FastDiag fastDiag = new FastDiag(fileName, constraintsSetC, ConflictDetectionAlgorithm.FastDiag, null); Set<Constraint> diag = fastDiag.getPreferredDiagnosis(constraintsSetC, false); assertTrue(!diag.isEmpty()); assertEquals(diag.size(), 2); Constraint c4 = new ArrayList<>(constraintsSetC).get(3); Constraint c5 = new ArrayList<>(constraintsSetC).get(4); assertSame(c4, new ArrayList<>(diag).get(0)); assertSame(c5, new ArrayList<>(diag).get(1)); }