// if there is an inconsistency with l and -l, // then we need to decide between them. // l is the new thing. private Policy ResolveInconsistency(LogicalForm l) { LogicalForm notL = l.Negate(); // okay. new plan: // 1. have two helper methods: // BestRemoval() and BestInsertion() // 2. recursively call BestRemoval() and // BestInsertion() and conjoin sentences // along best removal path // 3. (when there's a negation, check to see) // whether, in the current rule, there's A // on top or ~A on bottom // 4. problem for BestInsertion(): have to // make copy of model to make hypothetical // inferences // 5. ResolveInconsistency calls BestRemoval() // on P and ~P, and then removes whichever // wins out. // 6. Question simply becomes what to yield // as output for BestInsertion() and BestRemoval() Policy bestL = BestRemoval(l); Policy bestNotL = BestRemoval(notL); int comparison = CompareLikelihood(BestRemoval(l), BestRemoval(notL)); if (comparison > 0) { // TODO perform the removal strategy encoded by bestL return(bestL); } if (comparison < 0) { // TODO perform the removal strategy encoded by bestNotL return(bestNotL); } // TODO pick arbitrary one??? // rn we're conservative - we pick the older one return(bestNotL); }
// returns null if nothing should be inferred. // otherwise, return what should be inferred // when this rule is applied to the model // this should only be called when there are no free variables. public LogicalForm GetInference(Model m) { LogicalForm uniquelyUnsatisfiedTop = null; foreach (LogicalForm l in top) { if (!m.Satisfies(l)) { if (uniquelyUnsatisfiedTop == null) { uniquelyUnsatisfiedTop = l; } else { // this is the case where more than // one top sentence is false return(null); } } } // is there one and only one top sentence which // m fails to satisfy? If all the bottom sentences // are rejected, then reject that unique sentence. if (uniquelyUnsatisfiedTop != null) { for (int i = 0; i < bot.Length; i++) { foreach (LogicalForm l in bot[i]) { if (!m.Satisfies(new Not(l))) { // this means the rule should // not infer anything at this point return(null); } } } // if we ever reach this point, // it must be that all bottom sentences // were rejected. So we should reject // the only top sentence not satisfied. return(uniquelyUnsatisfiedTop.Negate()); } else { // this is the case where all sentences // on the top were true, // so we should infer something on the bottom. // infer the disjunction of satisfiable sentences // in the first tier HashSet <LogicalForm> satisfiableSentences = new HashSet <LogicalForm>(); if (bot.Length == 0) { return(null); } foreach (LogicalForm l in bot[0]) { if (!m.Satisfies(l.Negate())) { satisfiableSentences.Add(l); } } // this means one and only one sentence in this tier // is satisfiable. So, we infer it! if (satisfiableSentences.Count == 1) { return(satisfiableSentences.First()); } // TODO: infer most likely in the top tier if (satisfiableSentences.Count > 1) { return(new Or(satisfiableSentences)); } // this means that all of the top sentences were true, // but all of the bottom sentences were false. // this should make the system try to resolve an // inconsistency; or perhaps this case should never happen. // for now, I'll just return null. return(null); } }