001 package aima.test.regression.logic.fol; 002 003 import java.util.Set; 004 005 import aima.logic.fol.inference.FOLTFMResolution; 006 import aima.logic.fol.inference.InferenceResult; 007 import aima.logic.fol.inference.trace.FOLTFMResolutionTracer; 008 import aima.logic.fol.kb.data.Clause; 009 import aima.test.logictest.foltest.CommonFOLInferenceProcedureTests; 010 011 /** 012 * @author Ciaran O'Reilly 013 * 014 */ 015 public class FOLTFMResolutionRegression extends 016 CommonFOLInferenceProcedureTests { 017 018 public void testFullFOLKBLovesAnimalQueryKillsJackTunaFalse() { 019 // This query will not return using TFM as keep expanding 020 // clauses through resolution for this KB. 021 FOLTFMResolution ip = new FOLTFMResolution(1000 * 1000); 022 ip.setTracer(new RegressionFOLTFMResolutionTracer()); 023 testFullFOLKBLovesAnimalQueryKillsJackTunaFalse(ip, true); 024 } 025 026 private class RegressionFOLTFMResolutionTracer implements 027 FOLTFMResolutionTracer { 028 private int outerCnt = 1; 029 private int noPairsConsidered = 0; 030 private int noPairsResolved = 0; 031 private int maxClauseSizeSeen = 0; 032 033 public void stepStartWhile(Set<Clause> clauses, int totalNoClauses, 034 int totalNoNewCandidateClauses) { 035 outerCnt = 1; 036 037 System.out.println(""); 038 System.out.println("Total # clauses=" + totalNoClauses 039 + ", total # new candidate clauses=" 040 + totalNoNewCandidateClauses); 041 } 042 043 public void stepOuterFor(Clause i) { 044 System.out.print(" " + outerCnt); 045 if (outerCnt % 50 == 0) { 046 System.out.println(""); 047 } 048 outerCnt++; 049 } 050 051 public void stepInnerFor(Clause i, Clause j) { 052 noPairsConsidered++; 053 } 054 055 public void stepResolved(Clause iFactor, Clause jFactor, 056 Set<Clause> resolvents) { 057 noPairsResolved++; 058 059 Clause egLargestClause = null; 060 for (Clause c : resolvents) { 061 if (c.getNumberLiterals() > maxClauseSizeSeen) { 062 egLargestClause = c; 063 maxClauseSizeSeen = c.getNumberLiterals(); 064 } 065 } 066 if (null != egLargestClause) { 067 System.out.println(""); 068 System.out.println("E.g. largest clause so far=" 069 + maxClauseSizeSeen + ", " + egLargestClause); 070 System.out.println("i=" + iFactor); 071 System.out.println("j=" + jFactor); 072 } 073 } 074 075 public void stepFinished(Set<Clause> clauses, 076 InferenceResult result) { 077 System.out.println("Total # Pairs of Clauses Considered:" 078 + noPairsConsidered); 079 System.out.println("Total # Pairs of Clauses Resolved :" 080 + noPairsResolved); 081 noPairsConsidered = 0; 082 noPairsResolved = 0; 083 maxClauseSizeSeen = 0; 084 } 085 } 086 }