Predicate* InternalArgument::get<Predicate*>() { auto preds = _value._predicate; if (preds == NULL) { return NULL; } if (preds->size() == 0) { throw IdpException("Empty set of predicates passed but function was requested."); } else if (preds->size() > 1) { throw IdpException("Internal error: ambiguous predicate."); } else { return *(preds->begin()); } }
Function* InternalArgument::get<Function*>() { auto funcs = _value._function; if (funcs == NULL) { return NULL; } if (funcs->size() == 0) { throw IdpException("Empty set of functions passed but function was requested."); } else if (funcs->size() > 1) { throw IdpException("Internal error: ambiguous function."); } else { return *(funcs->begin()); } }
Sort* InternalArgument::get<Sort*>() { auto sorts = _value._sort; if (sorts == NULL) { return NULL; } if (sorts->size() == 0) { throw IdpException("Empty set of sorts passed but sort was requested."); } else if (sorts->size() > 1) { throw IdpException("Internal error: ambiguous sort."); } else { return *(sorts->begin()); } }
static std::pair<AbstractGroundTheory*, StructureExtender*> createGroundingAndExtender(AbstractTheory* theory, Structure* structure, Vocabulary* outputvocabulary, Term* term, TraceMonitor* tracemonitor, bool nbModelsEquivalent, GroundingReceiver* solver) { if (theory == NULL || structure == NULL) { throw IdpException("Unexpected NULL-pointer."); } auto t = dynamic_cast<Theory*>(theory); // TODO handle other cases if (t == NULL) { throw notyetimplemented("Grounding of already ground theories"); } if (t->vocabulary() != structure->vocabulary()) { throw IdpException("Grounding requires that the theory and structure range over the same vocabulary."); } auto m = new GroundingInference(t, structure, outputvocabulary, term, tracemonitor, nbModelsEquivalent, solver); auto grounding = m->ground(); auto result = std::pair<AbstractGroundTheory*, StructureExtender*>{grounding, m->getManager()}; delete(m); return result; }
std::vector<Definition*> SplitDefinitions::split(Structure* structure, UniqueNames<Rule*>& uniqueRuleNames){ auto temptheo = splittheo->clone(); auto models = ModelExpansion::doModelExpansion(temptheo, structure, NULL, NULL, { })._models; if (models.size() != 1) { throw IdpException("Invalid code path: no solution to definition splitting problem"); } temptheo->recursiveDelete(); auto splitmodel = models[0]; splitmodel->makeTwoValued(); auto sameDefInter = splitmodel->inter(sameDef); std::set<const DomainElement*> rulesDone; auto allrules = structure->inter(structure->vocabulary()->sort("rule")); std::vector<Definition*> result; for(auto ruleIt = allrules->begin(); not ruleIt.isAtEnd(); ++ruleIt){ auto currentRuleName = (*ruleIt)[0]; if(contains(rulesDone, currentRuleName)){ continue; } Assert(currentRuleName->type() == DET_INT); auto currentDef = new Definition(); result.push_back(currentDef); auto iterator = sameDefInter->ct()->begin(); for (; not iterator.isAtEnd(); ++iterator) { auto currentTuple = *iterator; Assert(currentTuple.size() == 2); if (currentTuple[0] == currentRuleName) { Assert(currentTuple[1]->type() == DET_INT); auto otherRule = uniqueRuleNames.getOriginal(currentTuple[1]->value()._int); currentDef->add(otherRule); rulesDone.insert(currentTuple[1]); } } } delete(splitmodel); return result; }
void nextSubset() { if (not hasNextSubset()) { throw IdpException("No next subset available"); } if (atLevelEnd()) { minimalindex++; currIndices.push_back(0); currentsubset.clear(); for (uint i = 0; i < currIndices.size(); ++i) { currIndices[i] = i; currentsubset.insert(totalset[i]); } return; } if (currIndices[minimalindex] < totalset.size() - 1) { currentsubset.erase(totalset[currIndices[minimalindex]]); currIndices[minimalindex]++; currentsubset.insert(totalset[currIndices[minimalindex]]); return; } int target = -1; for (uint i = 0; i < currIndices.size(); ++i) { if (target != -1) { currentsubset.erase(totalset[currIndices[i]]); currIndices[i] = target; currentsubset.insert(totalset[currIndices[i]]); target++; continue; } auto maxfornext = totalset.size() - (minimalindex - i); if (i + 1 < currIndices.size() && currIndices[i + 1] != maxfornext) { continue; } currentsubset.erase(totalset[currIndices[i]]); currIndices[i]++; currentsubset.insert(totalset[currIndices[i]]); target = currIndices[i] + 1; } }
InverseUNAFuncGenerator::InverseUNAFuncGenerator(Function* function, const std::vector<Pattern>& pattern, const std::vector<const DomElemContainer*>& vars, const Universe& univ) : _function(function), _reset(true) { _universe = univ; /* * Note: if pattern.back()!=Pattern::OUTPUT, then a SimpleFuncGenerator should have been constructed instead. * See the method "void GeneratorFactory::visit(const FuncTable* ft)" for more information. */ if(pattern.back()==Pattern::OUTPUT){ throw IdpException("Invalid code path in InverseUNAFuncGenerator"); } for (unsigned int n = 0; n < pattern.size(); ++n) { if (pattern[n] == Pattern::OUTPUT) { _outvars.push_back(vars[n]); _outpos.push_back(n); }else{ _invars.push_back(vars[n]); _inpos.push_back(n); } } _resvar = vars.back(); Assert(_inpos.size()+_outpos.size()==pattern.size()); Assert(_invars.size()+_outvars.size()==pattern.size()); }
bool isTwoValued(const Term* t, const Structure* structure) { if (t == NULL) { return false; } switch (t->type()) { case TermType::FUNC: { // TODO check if the specific instance is twovalued auto ft = dynamic_cast<const FuncTerm*>(t); auto inter = ft->function()->interpretation(structure); if (inter==NULL || not inter->approxTwoValued()) { return false; } auto twoval = true; for (auto st : ft->subterms()) { twoval &= isTwoValued(st, structure); } return twoval; } case TermType::AGG: { bool alltwovalued = true; auto at = dynamic_cast<const AggTerm*>(t); for(auto qset: at->set()->getSets()) { if(not SetUtils::approxTwoValued(qset, structure)) { alltwovalued = false; break; } } return alltwovalued; } case TermType::VAR: return true; case TermType::DOM: return true; } throw IdpException("Invalid code path"); }