Search in sources :

Example 1 with StratifiedEvaluation

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

the class NaiveGrounderTest method groundConstraintAlreadyGround.

/**
 * Asserts that a ground constraint whose positive body is not satisfied by the empty assignment
 * is grounded immediately.
 */
@Test
public void groundConstraintAlreadyGround() {
    ASPCore2Program program = PROGRAM_PARSER.parse("a :- not b. " + "b :- not a. " + ":- b.");
    NormalProgram normal = NORMALIZE_TRANSFORM.apply(program);
    InternalProgram prog = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normal));
    AtomStore atomStore = new AtomStoreImpl();
    Grounder grounder = GrounderFactory.getInstance("naive", prog, atomStore, true);
    Map<Integer, NoGood> noGoods = grounder.getNoGoods(new TrailAssignment(atomStore));
    int litB = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("b")));
    assertTrue(noGoods.containsValue(NoGood.fromConstraint(Collections.singletonList(litB), Collections.emptyList())));
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) InternalProgram(at.ac.tuwien.kr.alpha.core.programs.InternalProgram) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment) Test(org.junit.jupiter.api.Test)

Example 2 with StratifiedEvaluation

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

the class NaiveGrounderTest method groundRuleWithLongerBodyAlreadyGround.

/**
 * Asserts that a ground rule whose positive non-unary body is not satisfied by the empty assignment
 * is grounded immediately.
 */
@Test
public void groundRuleWithLongerBodyAlreadyGround() {
    ASPCore2Program program = PROGRAM_PARSER.parse("a :- not b. " + "b :- not a. " + "c :- b. " + "d :- b, c. ");
    NormalProgram normal = NORMALIZE_TRANSFORM.apply(program);
    InternalProgram prog = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normal));
    AtomStore atomStore = new AtomStoreImpl();
    Grounder grounder = GrounderFactory.getInstance("naive", prog, atomStore, true);
    Map<Integer, NoGood> noGoods = grounder.getNoGoods(new TrailAssignment(atomStore));
    int litANeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("a")), false);
    int litBNeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("b")), false);
    int litCNeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("c")), false);
    int litDNeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("d")), false);
    assertExistsNoGoodContaining(noGoods.values(), litANeg);
    assertExistsNoGoodContaining(noGoods.values(), litBNeg);
    assertExistsNoGoodContaining(noGoods.values(), litCNeg);
    assertExistsNoGoodContaining(noGoods.values(), litDNeg);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) InternalProgram(at.ac.tuwien.kr.alpha.core.programs.InternalProgram) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment) Test(org.junit.jupiter.api.Test)

Example 3 with StratifiedEvaluation

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

the class AlphaImpl method performProgramPreprocessing.

@VisibleForTesting
InternalProgram performProgramPreprocessing(NormalProgram program) {
    LOGGER.debug("Preprocessing InternalProgram!");
    InternalProgram retVal = InternalProgram.fromNormalProgram(program);
    if (config.isEvaluateStratifiedPart()) {
        AnalyzedProgram analyzed = new AnalyzedProgram(retVal.getRules(), retVal.getFacts());
        retVal = new StratifiedEvaluation().apply(analyzed);
    }
    return retVal;
}
Also used : AnalyzedProgram(at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram) InternalProgram(at.ac.tuwien.kr.alpha.core.programs.InternalProgram) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with StratifiedEvaluation

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

the class TestUtils method buildSolverFromSystemConfig.

private static Solver buildSolverFromSystemConfig(ASPCore2Program prog, SystemConfig cfg) {
    AtomStore atomStore = new AtomStoreImpl();
    NormalProgram normalProg = new NormalizeProgramTransformation(cfg.getAggregateRewritingConfig()).apply(prog);
    InternalProgram preprocessed = cfg.isEvaluateStratifiedPart() ? new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normalProg)) : InternalProgram.fromNormalProgram(normalProg);
    return SolverFactory.getInstance(cfg, atomStore, GrounderFactory.getInstance(cfg.getGrounderName(), preprocessed, atomStore, cfg.isDebugInternalChecks()));
}
Also used : AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) InternalProgram(at.ac.tuwien.kr.alpha.core.programs.InternalProgram) NormalizeProgramTransformation(at.ac.tuwien.kr.alpha.core.programs.transformation.NormalizeProgramTransformation) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)

Example 5 with StratifiedEvaluation

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

the class NaiveGrounderTest method groundRuleAlreadyGround.

/**
 * Asserts that a ground rule whose positive body is not satisfied by the empty assignment
 * is grounded immediately.
 */
@Test
public void groundRuleAlreadyGround() {
    ASPCore2Program program = PROGRAM_PARSER.parse("a :- not b. " + "b :- not a. " + "c :- b.");
    NormalProgram normal = NORMALIZE_TRANSFORM.apply(program);
    CompiledProgram prog = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normal));
    AtomStore atomStore = new AtomStoreImpl();
    Grounder grounder = GrounderFactory.getInstance("naive", prog, atomStore, true);
    Map<Integer, NoGood> noGoods = grounder.getNoGoods(new TrailAssignment(atomStore));
    int litCNeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("c")), false);
    int litB = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("b")));
    assertExistsNoGoodContaining(noGoods.values(), litCNeg);
    assertExistsNoGoodContaining(noGoods.values(), litB);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AtomStore(at.ac.tuwien.kr.alpha.core.common.AtomStore) NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) AtomStoreImpl(at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl) NormalProgram(at.ac.tuwien.kr.alpha.api.programs.NormalProgram) CompiledProgram(at.ac.tuwien.kr.alpha.core.programs.CompiledProgram) StratifiedEvaluation(at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation) TrailAssignment(at.ac.tuwien.kr.alpha.core.solver.TrailAssignment) Test(org.junit.jupiter.api.Test)

Aggregations

StratifiedEvaluation (at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)6 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)5 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)4 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)4 InternalProgram (at.ac.tuwien.kr.alpha.core.programs.InternalProgram)4 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)3 NoGood (at.ac.tuwien.kr.alpha.core.common.NoGood)3 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)3 Test (org.junit.jupiter.api.Test)3 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)2 DebugSolvingContext (at.ac.tuwien.kr.alpha.api.DebugSolvingContext)1 Solver (at.ac.tuwien.kr.alpha.api.Solver)1 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)1 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)1 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)1 NormalizeProgramTransformation (at.ac.tuwien.kr.alpha.core.programs.transformation.NormalizeProgramTransformation)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1