Exemplo n.º 1
0
  public void printProofTree(Clause finalClause, LinkedList<Clause> clauseList) {
    PriorityQueue<Integer> proofTree =
        new PriorityQueue<
            Integer>(); // Will be used to order the ancestors of the finalClause for output
    LinkedList<Clause> treeQueue =
        new LinkedList<
            Clause>(); // Will take in the ancestors of the finalClause. Dequeue each element, add
                       // it to the proofTree, then add the parents to the queue
    int[] parentIDs;

    treeQueue.add(finalClause);
    while (!treeQueue.isEmpty()) {
      Clause polledClause = treeQueue.poll();

      if (proofTree.contains(
          polledClause
              .getClauseID())) // Skip this iteration if the clause has already been added to the
                               // proofTree
      {
        continue;
      }
      proofTree.add(polledClause.getClauseID());
      parentIDs = polledClause.getParentIDs();
      if (parentIDs[0]
          != -1) // if one parent exists, the other must exist and we add the parents to the queue
      {
        treeQueue.add(clauseList.get(parentIDs[0] - 1)); // add the first parent to the queue
        treeQueue.add(clauseList.get(parentIDs[1] - 1)); // add the second parent to the queue
      }
    }

    // output all the clauses in the proof tree
    while (proofTree.peek() != null) {
      clauseList.get(proofTree.poll() - 1).outputClause();
    }
  }