use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class StratifiedEvaluation method prepareInitialEvaluation.
/**
* To be called at the start of evaluateComponent. Adds all known instances of the predicates occurring in the given set
* 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 prepareInitialEvaluation(Set<CompiledRule> rulesToEvaluate) {
modifiedInLastEvaluationRun = new HashMap<>();
for (CompiledRule rule : rulesToEvaluate) {
// Register rule head instances.
Predicate headPredicate = rule.getHeadAtom().getPredicate();
IndexedInstanceStorage headInstances = workingMemory.get(headPredicate, true);
modifiedInLastEvaluationRun.putIfAbsent(headPredicate, new LinkedHashSet<>());
if (headInstances != null) {
modifiedInLastEvaluationRun.get(headPredicate).addAll(headInstances.getAllInstances());
}
// Register positive body literal instances.
for (Literal lit : rule.getPositiveBody()) {
Predicate bodyPredicate = lit.getPredicate();
IndexedInstanceStorage bodyInstances = workingMemory.get(bodyPredicate, true);
modifiedInLastEvaluationRun.putIfAbsent(bodyPredicate, new LinkedHashSet<>());
if (bodyInstances != null) {
modifiedInLastEvaluationRun.get(bodyPredicate).addAll(bodyInstances.getAllInstances());
}
}
}
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class AbstractAggregateEncoder method buildElementRuleHead.
/**
* Builds a the head atom for an aggregate element encoding rule of form
* <code>HEAD :- $element_literals$, $aggregate_dependencies$</code>, e.g.
* <code>count_1_element_tuple(count_1_args(Y), X) :- p(X, Y), q(Y)</code> for the rule body
* <code>N = #count{X : p(X, Y)}, q(Y)</code>.
*
* @param aggregateId
* @param element
* @param aggregateArguments
* @return
*/
protected BasicAtom buildElementRuleHead(String aggregateId, AggregateElement element, Term aggregateArguments) {
Predicate headPredicate = Predicates.getPredicate(this.getElementTuplePredicateSymbol(aggregateId), 2);
FunctionTerm elementTuple = Terms.newFunctionTerm(ELEMENT_TUPLE_FUNCTION_SYMBOL, element.getElementTerms());
return Atoms.newBasicAtom(headPredicate, aggregateArguments, elementTuple);
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class MinMaxEncoder method buildElementRuleHead.
@Override
protected BasicAtom buildElementRuleHead(String aggregateId, AggregateElement element, Term aggregateArguments) {
Predicate headPredicate = Predicates.getPredicate(this.getElementTuplePredicateSymbol(aggregateId), 2);
Term elementTerm = element.getElementTerms().get(0);
return Atoms.newBasicAtom(headPredicate, aggregateArguments, elementTerm);
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class SumEncoder method buildElementRuleHead.
/**
* In contrast to encoders for other aggregate functions, the "element tuple" atom for sum encodings is ternary - apart
* from the aggregate arguments and the variable tuple identifying the aggregated element, it also holds the value to
* add to the result sum as its third argument.
*/
@Override
protected BasicAtom buildElementRuleHead(String aggregateId, AggregateElement element, Term aggregateArguments) {
Predicate headPredicate = Predicates.getPredicate(this.getElementTuplePredicateSymbol(aggregateId), 3);
FunctionTerm elementTuple = Terms.newFunctionTerm(AbstractAggregateEncoder.ELEMENT_TUPLE_FUNCTION_SYMBOL, element.getElementTerms());
return Atoms.newBasicAtom(headPredicate, aggregateArguments, elementTuple, element.getElementTerms().get(0));
}
use of at.ac.tuwien.kr.alpha.api.programs.Predicate in project Alpha by alpha-asp.
the class InternalProgram method recordFacts.
private void recordFacts(List<Atom> facts) {
for (Atom fact : facts) {
List<Instance> tmpInstances = FactIntervalEvaluator.constructFactInstances(fact);
Predicate tmpPredicate = fact.getPredicate();
factsByPredicate.putIfAbsent(tmpPredicate, new LinkedHashSet<>());
factsByPredicate.get(tmpPredicate).addAll(tmpInstances);
}
}
Aggregations