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(); } }
public boolean resolve(LinkedList<Clause> clauses) { // Storing onto the stack to verify clauses in reverse order // LinkedList<Clause> expansionStack = new LinkedList<Clause>(); PriorityQueue<Clause> expansionQueue = new PriorityQueue<Clause>(10000, new ClauseSizeComparator()); for (int count = 0; count < clauses.size(); count++) { expansionQueue.add(clauses.get(count)); } while (!expansionQueue.isEmpty()) // Until the stack is empty { Clause lastClause = expansionQueue.poll(); for (int clauseCount = 0; clauseCount < lastClause.getClauseID() - 1; clauseCount++) { // If any new clauses are added since last execution // if(!clauses.getLast().equals(lastClause)) { // break; } Clause tempClause = clauses.get(clauseCount); int numClausesBeforeExpansion = clauses.size(); boolean result = lastClause.resolution(tempClause, clauses); if (!result) { return false; } int numClausesAfterExpansion = clauses.size(); // System.out.println(numClausesAfterExpansion - numClausesBeforeExpansion); //Size does not // change // If new clauses are added, expand the newly added clause before expanding any other clause if (numClausesAfterExpansion - numClausesBeforeExpansion > 0) { expansionQueue.add(clauses.getLast()); } } } return true; }