Search in sources :

Example 1 with RuleGroundingOrder

use of at.ac.tuwien.kr.alpha.core.grounder.RuleGroundingOrder in project Alpha by alpha-asp.

the class StratifiedEvaluation method calculateSatisfyingSubstitutionsForRule.

private List<Substitution> calculateSatisfyingSubstitutionsForRule(CompiledRule rule, boolean checkAllStartingLiterals) {
    LOGGER.debug("Grounding rule {}", rule);
    RuleGroundingInfo groundingOrders = rule.getGroundingInfo();
    // Treat rules with fixed instantiation first.
    LOGGER.debug("Is fixed rule? {}", rule.getGroundingInfo().hasFixedInstantiation());
    if (groundingOrders.hasFixedInstantiation()) {
        RuleGroundingOrder fixedGroundingOrder = groundingOrders.getFixedGroundingOrder();
        return calcSubstitutionsWithGroundingOrder(fixedGroundingOrder, Collections.singletonList(new BasicSubstitution()));
    }
    List<Literal> startingLiterals = groundingOrders.getStartingLiterals();
    // Check only one starting literal if indicated by the parameter.
    if (!checkAllStartingLiterals) {
        // If this is the first evaluation run, it suffices to start from the first starting literal only.
        Literal lit = startingLiterals.get(0);
        return calcSubstitutionsWithGroundingOrder(groundingOrders.orderStartingFrom(lit), substituteFromRecentlyAddedInstances(lit));
    }
    // Ground from all starting literals.
    // Collection of full ground substitutions for the given rule.
    List<Substitution> groundSubstitutions = new ArrayList<>();
    for (Literal lit : startingLiterals) {
        List<Substitution> substitutionsForStartingLiteral = calcSubstitutionsWithGroundingOrder(groundingOrders.orderStartingFrom(lit), substituteFromRecentlyAddedInstances(lit));
        groundSubstitutions.addAll(substitutionsForStartingLiteral);
    }
    return groundSubstitutions;
}
Also used : Substitution(at.ac.tuwien.kr.alpha.api.grounder.Substitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) BasicSubstitution(at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) ArrayList(java.util.ArrayList) RuleGroundingOrder(at.ac.tuwien.kr.alpha.core.grounder.RuleGroundingOrder) RuleGroundingInfo(at.ac.tuwien.kr.alpha.core.grounder.RuleGroundingInfo)

Aggregations

Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)1 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)1 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)1 RuleGroundingInfo (at.ac.tuwien.kr.alpha.core.grounder.RuleGroundingInfo)1 RuleGroundingOrder (at.ac.tuwien.kr.alpha.core.grounder.RuleGroundingOrder)1 ArrayList (java.util.ArrayList)1