From cfc7b0d2d4c58051565f965d558221cbd5c6eea9 Mon Sep 17 00:00:00 2001 From: Ceriel Jacobs Date: Tue, 22 Nov 2022 09:36:43 +0100 Subject: [PATCH] Addressing issue #64 and issue #98: rewrite existential multi-head rules --- src/vlog/common/concepts.cpp | 8 +++++++- src/vlog/forward/seminaiver.cpp | 16 +++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/vlog/common/concepts.cpp b/src/vlog/common/concepts.cpp index 2458e022..08eb41f1 100644 --- a/src/vlog/common/concepts.cpp +++ b/src/vlog/common/concepts.cpp @@ -1325,7 +1325,13 @@ void Program::addRule(std::vector heads, std::vector body, rewriteRule(heads, body); } else { Rule rule(allrules.size(), heads, body, isEGD); - addRule(rule); + if (heads.size() > 1 && rule.isExistential()) { + // Work-around for bug in existential multihead rules, github issue #98 and issue #64. + // Easiest fix is to just rewrite these rules. + rewriteRule(heads, body); + } else { + addRule(rule); + } } } diff --git a/src/vlog/forward/seminaiver.cpp b/src/vlog/forward/seminaiver.cpp index ad8f5a05..b691a40c 100644 --- a/src/vlog/forward/seminaiver.cpp +++ b/src/vlog/forward/seminaiver.cpp @@ -1831,14 +1831,16 @@ void SemiNaiver::printCountAllIDBs(std::string prefix) { for (PredId_t i = 0; i < program->getNPredicates(); ++i) { if (predicatesTables[i] != NULL) { if (program->isPredicateIDB(i)) { - size_t count = predicatesTables[i]->getNAllRows(); - if (count == 0) { - emptyRel++; - } std::string predname = program->getPredicateName(i); - LOG(DEBUGL) << prefix << "Cardinality of " << - predname << ": " << count; - c += count; + if (predname.rfind("__Generated", 0) != 0) { + // Only count original predicates. + size_t count = predicatesTables[i]->getNAllRows(); + LOG(DEBUGL) << prefix << "Cardinality of " << predname << ": " << count; + if (count == 0) { + emptyRel++; + } + c += count; + } } } }