Skip to content

Commit

Permalink
fix the fix for issue #269
Browse files Browse the repository at this point in the history
  • Loading branch information
madmike200590 committed Oct 1, 2020
1 parent c721274 commit e918724
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,27 @@ private void evaluateComponent(SCComponent comp) {
LOGGER.debug("No rules to evaluate for component {}", comp);
return;
}
prepareComponentEvaluation(SetUtils.union(evaluationInfo.nonRecursiveRules, evaluationInfo.recursiveRules));

// Rules outside of dependency cycles only need to be evaluated once.
if (!evaluationInfo.nonRecursiveRules.isEmpty()) {
prepareInitialEvaluation(evaluationInfo.nonRecursiveRules);
evaluateRules(evaluationInfo.nonRecursiveRules, true);
for (IndexedInstanceStorage instanceStorage : workingMemory.modified()) {
// Directly record all newly derived instances as additional facts.
for (Instance recentlyAddedInstance : instanceStorage.getRecentlyAddedInstances()) {
additionalFacts.add(new BasicAtom(instanceStorage.getPredicate(), recentlyAddedInstance.terms));
}
instanceStorage.markRecentlyAddedInstancesDone();
}
}
boolean isInitialRun = true;
if (!evaluationInfo.recursiveRules.isEmpty()) {
do {
// Now do the rules that cyclically depend on each other,
// evaluate these until nothing new can be derived any more.
if (isInitialRun) {
prepareInitialEvaluation(evaluationInfo.recursiveRules);
}
evaluateRules(evaluationInfo.recursiveRules, isInitialRun);
isInitialRun = false;
modifiedInLastEvaluationRun = new HashMap<>();
Expand Down Expand Up @@ -152,7 +162,7 @@ private void evaluateRules(Set<InternalRule> rules, boolean isInitialRun) {
* of rules to the "modifiedInLastEvaluationRun" map in order to "bootstrap" incremental grounding, i.e. making sure
* that those instances are taken into account for ground substitutions by evaluateRule.
*/
private void prepareComponentEvaluation(Set<InternalRule> rulesToEvaluate) {
private void prepareInitialEvaluation(Set<InternalRule> rulesToEvaluate) {
modifiedInLastEvaluationRun = new HashMap<>();
for (InternalRule rule : rulesToEvaluate) {
// Register rule head instances.
Expand Down

0 comments on commit e918724

Please sign in to comment.