Search in sources :

Example 1 with NormalProgramImpl

use of at.ac.tuwien.kr.alpha.core.programs.NormalProgramImpl in project Alpha by alpha-asp.

the class IntervalTermToIntervalAtom method apply.

@Override
public NormalProgram apply(NormalProgram inputProgram) {
    boolean didChange = false;
    List<NormalRule> rewrittenRules = new ArrayList<>();
    for (NormalRule rule : inputProgram.getRules()) {
        NormalRule rewrittenRule = rewriteIntervalSpecifications(rule);
        rewrittenRules.add(rewrittenRule);
        // If no rewriting occurred, the output rule is the same as the input to the rewriting.
        if (rewrittenRule != rule) {
            didChange = true;
        }
    }
    // Return original program if no rule was actually rewritten.
    if (!didChange) {
        return inputProgram;
    }
    return new NormalProgramImpl(rewrittenRules, inputProgram.getFacts(), inputProgram.getInlineDirectives());
}
Also used : NormalProgramImpl(at.ac.tuwien.kr.alpha.core.programs.NormalProgramImpl) ArrayList(java.util.ArrayList) NormalRule(at.ac.tuwien.kr.alpha.api.rules.NormalRule)

Example 2 with NormalProgramImpl

use of at.ac.tuwien.kr.alpha.core.programs.NormalProgramImpl in project Alpha by alpha-asp.

the class ArithmeticTermsRewriting method apply.

@Override
public NormalProgram apply(NormalProgram inputProgram) {
    List<NormalRule> rewrittenRules = new ArrayList<>();
    boolean didRewrite = false;
    for (NormalRule inputProgramRule : inputProgram.getRules()) {
        if (containsArithmeticTermsToRewrite(inputProgramRule)) {
            rewrittenRules.add(rewriteRule(inputProgramRule));
            didRewrite = true;
        } else {
            // Keep rule as-is if no ArithmeticTerm occurs.
            rewrittenRules.add(inputProgramRule);
        }
    }
    if (!didRewrite) {
        return inputProgram;
    }
    // Create new program with rewritten rules.
    return new NormalProgramImpl(rewrittenRules, inputProgram.getFacts(), inputProgram.getInlineDirectives());
}
Also used : NormalProgramImpl(at.ac.tuwien.kr.alpha.core.programs.NormalProgramImpl) ArrayList(java.util.ArrayList) NormalRule(at.ac.tuwien.kr.alpha.api.rules.NormalRule)

Aggregations

NormalRule (at.ac.tuwien.kr.alpha.api.rules.NormalRule)2 NormalProgramImpl (at.ac.tuwien.kr.alpha.core.programs.NormalProgramImpl)2 ArrayList (java.util.ArrayList)2