* Subsumption tests are performed and the rule may not be added. <p>
* Previous results may also be removed because of sumption.
*/
private void addResult(Rule rule) {
Rule current;
boolean added = false;
/* Iterate the list until we find the right place. */
SimpleLinkedList.LinkedListIterator iter = m_results.iterator();
while (iter.hasNext()) {
current = (Rule) iter.next();
if (Rule.confirmationThenObservedComparator.compare(current, rule) > 0) {
iter.addBefore(rule);
added = true;
break;
}
/* Subsumption tests to see if the rule can be added. */
if ((m_subsumption || m_sameClause || m_equivalent)
&& current.subsumes(rule)) {
if (current.numLiterals() == rule.numLiterals()) {
if (current.equivalentTo(rule)) {
/* Equivalent rules. */
if (m_equivalent) {
return;
}
} else {
/* Same clauses. */
if (m_sameClause
&& Rule.confirmationComparator.compare(current, rule) < 0) {
return;
}
}
} else {
/* Subsumption. */
if (m_subsumption
&& Rule.observedComparator.compare(current, rule) <= 0) {
return;
}
}
}
}
if (added == false) {
/* The rule must be added in the end of the results. */
m_results.add(rule);
}
/* Iterate the results with a lower confirmation
* to see if some of them must be removed. */
SimpleLinkedList.LinkedListInverseIterator inverse
= m_results.inverseIterator();
while (inverse.hasPrevious()) {
current = (Rule) inverse.previous();
if (Rule.confirmationThenObservedComparator.compare(current, rule) < 0) {
break;
}
if (current != rule && rule.subsumes(current)) {
if (current.numLiterals() == rule.numLiterals()) {
if (!current.equivalentTo(rule)) {
/* Same clauses. */
if (m_sameClause
&& Rule.confirmationComparator.compare(current, rule) > 0) {
inverse.remove();
}
}
} else {
/* Subsumption. */
if (m_subsumption
&& Rule.observedComparator.compare(rule, current) <= 0) {
inverse.remove();
}
}
}
}
/* Remove the rules with the worst confirmation value
* if there are too many results. */
if (m_best != 0 && numValuesInResult() > m_best) {
Rule worstRule = (Rule) m_results.getLast();
inverse = m_results.inverseIterator();
while (inverse.hasPrevious()) {
current = (Rule) inverse.previous();
if (Rule.confirmationComparator.compare(current, worstRule) < 0) {
break;