Пример #1
0
  @Ignore
  @Test
  public void testNormalSimulatedSession()
      throws SolverException, InconsistentTheoryException, NoConflictException,
          OWLOntologyCreationException {
    logger.info("NormalSimulatedSession");

    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search =
        testSetup("ontologies/ecai2010.owl");
    Set<? extends FormulaSet<OWLLogicalAxiom>> diagnoses = getDiagnoses(search);

    Map<QSSType, DurationStat> nTimes = new HashMap<QSSType, DurationStat>();
    Map<QSSType, List<Double>> nQueries = new HashMap<QSSType, List<Double>>();

    for (QSSType type : QSSType.values()) { // run for each scoring function
      logger.info("QSSType: " + type);

      nTimes.put(type, new DurationStat());
      nQueries.put(type, new LinkedList<Double>());
      for (FormulaSet<OWLLogicalAxiom> targetDiagnosis :
          diagnoses) { // run for each possible target diagnosis
        logger.info("targetD: " + CalculateDiagnoses.renderAxioms(targetDiagnosis));
        long completeTime = System.currentTimeMillis();

        computeHS(search, ctTheory, targetDiagnosis, nQueries.get(type), type);
        ctTheory.getKnowledgeBase().removeFormulas(targetDiagnosis);
        completeTime = System.currentTimeMillis() - completeTime;
        nTimes.get(type).add(completeTime);

        foundDiagnoses.addAll(targetDiagnosis);
        ctTheory.getReasoner().addFormulasToCache(ctTheory.getKnowledgeBase().getFaultyFormulas());
        assertTrue(ctTheory.verifyConsistency());
        ctTheory.reset();

        resetTheoryTests(ctTheory);
        search.reset();
      }
      logStatistics(nQueries, nTimes, type, "normal");
      logger.info("found Diagnoses: " + foundDiagnoses.size());
      logger.info("found Diagnosis: " + CalculateDiagnoses.renderAxioms(foundDiagnoses));
      logger.info(
          "found all target diagnoses: "
              + (foundDiagnoses.size() > 0 && foundDiagnoses.containsAll(diagnoses)));
    }
  }
Пример #2
0
  @Ignore
  @Test
  public void testCompareSearchMethods()
      throws SolverException, InconsistentTheoryException, NoConflictException,
          OWLOntologyCreationException {
    logger.info("NormalSimulatedSession compared to ConflictTreeSimulatedSession");

    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search =
        testSetup("ontologies/ecai2010.owl");
    Set<? extends FormulaSet<OWLLogicalAxiom>> diagnoses = getDiagnoses(search);

    // setup second search
    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> ctSearch =
        new HsTreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom>();
    ctSearch.setSearchStrategy(new UniformCostSearchStrategy<OWLLogicalAxiom>());
    ctSearch.setSearcher(new QuickXplain<OWLLogicalAxiom>());
    ctSearch.setSearchable(ctTheory);
    ctSearch.setCostsEstimator(new OWLAxiomKeywordCostsEstimator(ctTheory));

    Map<QSSType, DurationStat> nTimes = new HashMap<QSSType, DurationStat>();
    Map<QSSType, List<Double>> nQueries = new HashMap<QSSType, List<Double>>();
    Map<QSSType, DurationStat> ctTimes = new HashMap<QSSType, DurationStat>();
    Map<QSSType, List<Double>> ctQueries = new HashMap<QSSType, List<Double>>();

    for (QSSType type : QSSType.values()) { // run for each scoring function
      logger.info("QSSType: " + type);

      // run normal simulated session
      logger.info("NormalSimulatedSession");
      nTimes.put(type, new DurationStat());
      nQueries.put(type, new LinkedList<Double>());
      for (FormulaSet<OWLLogicalAxiom> targetDiagnosis :
          diagnoses) { // run for each possible target diagnosis
        long completeTime = System.currentTimeMillis();

        computeHS(search, ctTheory, targetDiagnosis, nQueries.get(type), type);
        ctTheory.getKnowledgeBase().removeFormulas(targetDiagnosis);
        completeTime = System.currentTimeMillis() - completeTime;
        nTimes.get(type).add(completeTime);

        foundDiagnoses.addAll(targetDiagnosis);
        ctTheory.getReasoner().addFormulasToCache(ctTheory.getKnowledgeBase().getFaultyFormulas());
        assertTrue(ctTheory.verifyConsistency());
        ctTheory.reset();

        resetTheoryTests(ctTheory);
        search.reset();
      }
      logger.info("found Diagnoses: " + foundDiagnoses.size());
      logger.info("found Diagnosis: " + CalculateDiagnoses.renderAxioms(foundDiagnoses));
      logger.info(
          "found all target diagnoses: "
              + (foundDiagnoses.size() > 0 && foundDiagnoses.containsAll(diagnoses)));
      // end (run normal simulated session)

      foundDiagnoses.clear();

      // run conflict tree simulated session
      logger.info("ConflictTreeSimulatedSession");
      ctTimes.put(type, new DurationStat());
      ctQueries.put(type, new LinkedList<Double>());
      for (FormulaSet<OWLLogicalAxiom> targetDiagnosis :
          diagnoses) { // run for each possible target diagnosis
        logger.info("targetD: " + CalculateDiagnoses.renderAxioms(targetDiagnosis));

        ConflictTreeSession conflictTreeSearch = new ConflictTreeSession(this, ctTheory, ctSearch);
        long completeTime = conflictTreeSearch.search(targetDiagnosis, ctQueries, type);
        ctTimes.get(type).add(completeTime);

        foundDiagnoses.addAll(conflictTreeSearch.getDiagnosis());
        ctTheory.getReasoner().addFormulasToCache(ctTheory.getKnowledgeBase().getFaultyFormulas());
        assertTrue(ctTheory.verifyConsistency());
        ctTheory.reset();

        resetTheoryTests(ctTheory);
        ctSearch.reset();
      }
      logger.info("found Diagnoses: " + foundDiagnoses.size());
      logger.info("found Diagnosis: " + CalculateDiagnoses.renderAxioms(foundDiagnoses));
      logger.info(
          "found all target diagnoses: "
              + (foundDiagnoses.size() > 0 && foundDiagnoses.containsAll(diagnoses)));
      // end (run conflict tree simulated session)

      // print time statistics
      logStatistics(nQueries, nTimes, type, "normal");
      logStatistics(ctQueries, ctTimes, type, "treeSearch");

      foundDiagnoses.clear();
    }
  }