Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 package ATPInterface;
00025
00026 import java.util.*;
00027
00028 import theoremprover.*;
00029 import hittingsetalg.*;
00030
00031
00042 public class LogicalSubDB {
00043
00044
00045 protected String name;
00046
00047
00048 protected LSentence rules;
00049
00050
00051 protected int numRules;
00052
00053
00054 protected LogicParser parser;
00055
00056
00057 protected ABTheoremProver theoremProver;
00058
00062 public LogicalSubDB(String name) {
00063 this.name = name;
00064 rules = new LSentence();
00065 numRules = 0;
00066 parser = new LogicParser();
00067 }
00068
00069
00073 public String getName() {
00074 return name;
00075 }
00076
00077
00081 public void addRules(ArrayList newRules) throws LogicParseException {
00082 for (int i = 0; i < newRules.size(); ++i) {
00083
00084 String ruleStr = (String)newRules.get(i);
00085
00086 if (parser.parse(ruleStr)) {
00087 rules.addRules((LSentence)parser.result());
00088 ++numRules;
00089 } else {
00090 throw new LogicParseException(i + 1);
00091 }
00092 }
00093 }
00094
00098 public int getNumRules() {
00099 return numRules;
00100 }
00101
00105 public ArrayList getRulesAsStrings() {
00106 ArrayList result = new ArrayList();
00107
00108 Iterator it = rules.rules.iterator();
00109 while(it.hasNext()) {
00110 result.add(it.next().toString());
00111 }
00112
00113 return result;
00114 }
00115
00116 public LSentence getRulesAsLSentence() {
00117 return rules;
00118 }
00119
00123 public void clear() {
00124 rules = new LSentence();
00125 numRules = 0;
00126 }
00127
00128
00132 public void append(LogicalSubDB source) {
00133 rules.addRules(source.rules);
00134 numRules += source.numRules;
00135 }
00136
00141 public boolean checkConsistency(boolean useFaultModes, String assumptionAB,
00142 String assumptionNAB) throws LogicParseException {
00143
00144 theoremProver = new ABTheoremProver();
00145 theoremProver = rules.asABPropositionalSentence(theoremProver);
00146 if (theoremProver == null) {
00147 throw new LogicParseException();
00148 }
00149
00150 if (useFaultModes) {
00151 ArrayList posAssPrefixes = new ArrayList();
00152 posAssPrefixes.add(assumptionNAB);
00153 return (theoremProver.checkConsistency(posAssPrefixes));
00154 } else {
00155 return (theoremProver.checkConsistency());
00156 }
00157 }
00158
00169 public ArrayList computeMinDiag(int maxExplSize, int maxNumExpl,
00170 boolean useFaultModes, String assumptionAB,
00171 String assumptionNAB, boolean verboseOutput)
00172
00173 throws IllegalAssumption {
00174
00175 assert(theoremProver != null);
00176
00177 ArrayList minHS;
00178 ArrayList result = new ArrayList();
00179
00180 if (useFaultModes) {
00181 System.out.println("maxExplSize: " + maxExplSize);
00182 System.out.println("maxNumExpl: " + maxNumExpl);
00183 System.out.println("ass AB: " + assumptionAB);
00184 System.out.println("# assumptions: " + theoremProver.getAssumptions().size());
00185 System.out.println("# rules (altogher): " + rules.rules.size());
00186 if (verboseOutput) {
00187 System.out.println("--- rules: --- \n" + rules.toString());
00188 }
00189 MinHittingSetsFM hs = new MinHittingSetsFM(false, theoremProver, assumptionAB, assumptionNAB);
00190
00191 hs.compute(maxExplSize, maxNumExpl);
00192 minHS = hs.getMinHS();
00193 System.out.println("#minimal diagnoses: " + minHS.size());
00194
00195 } else {
00196 MinHittingSets hs = new MinHittingSets(false, theoremProver);
00197 hs.compute(maxExplSize, maxNumExpl);
00198 minHS = hs.getMinHS();
00199 }
00200
00201 Iterator itMinHS = minHS.iterator();
00202 while(itMinHS.hasNext()) {
00203 ArrayList explanation = new ArrayList();
00204
00205 ArrayList candidate = (ArrayList)itMinHS.next();
00206 Iterator itCand = candidate.iterator();
00207 while(itCand.hasNext()) {
00208 Assumption a = (Assumption)itCand.next();
00209 explanation.add(a.toString());
00210 }
00211
00212 result.add(explanation);
00213 }
00214
00215 return result;
00216 }
00217 }