Search in sources :

Example 26 with NoGood

use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.

the class AlphaHeuristicTestAssumptions method testNumbersOfNoGoods.

private void testNumbersOfNoGoods(Predicate<? super Integer> isRuleBody) {
    int n = 0;
    int bodyNotHead = 0;
    int bodyElementsNotBody = 0;
    int noHead = 0;
    int other = 0;
    Collection<NoGood> noGoods = getNoGoods();
    assignment.growForMaxAtomId();
    choiceManager.growForMaxAtomId(atomStore.getMaxAtomId());
    choiceManager.addChoiceInformation(grounder.getChoiceAtoms(), grounder.getHeadsToBodies());
    for (NoGood noGood : noGoods) {
        n++;
        boolean knownType = false;
        if (DependencyDrivenHeuristic.isBodyNotHead(noGood, isRuleBody)) {
            bodyNotHead++;
            knownType = true;
        }
        if (DependencyDrivenHeuristic.isBodyElementsNotBody(noGood, isRuleBody)) {
            bodyElementsNotBody++;
            knownType = true;
        }
        if (!noGood.hasHead()) {
            noHead++;
            knownType = true;
        }
        if (!knownType) {
            other++;
        }
    }
    System.out.println(noGoods.stream().map(atomStore::noGoodToString).collect(Collectors.joining(", ")));
    assertEquals(5, bodyNotHead, "Unexpected number of bodyNotHead nogoods");
    assertEquals(5, bodyElementsNotBody, "Unexpected number of bodyElementsNotBody nogoods");
    assertGreaterThan("Unexpected number of nogoods without head", 4, noHead);
    // there may be other nogoods (e.g. for ChoiceOn, ChoiceOff) which we do not care for here
    System.out.println("Total number of NoGoods: " + n);
    System.out.println("Number of NoGoods of unknown type: " + other);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood)

Example 27 with NoGood

use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.

the class AlphaHeuristicTestAssumptions method testIsAtomChoice.

private void testIsAtomChoice(Predicate<? super Integer> isRuleBody) {
    Collection<NoGood> noGoods = getNoGoods();
    assignment.growForMaxAtomId();
    choiceManager.growForMaxAtomId(atomStore.getMaxAtomId());
    choiceManager.addChoiceInformation(grounder.getChoiceAtoms(), grounder.getHeadsToBodies());
    for (NoGood noGood : noGoods) {
        for (Integer literal : noGood) {
            int atom = atomOf(literal);
            String atomToString = atomStore.atomToString(atom);
            if (atomToString.startsWith("_R_")) {
                assertTrue(isRuleBody.test(atom), "Atom not choice: " + atomToString);
            }
        }
    }
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood)

Example 28 with NoGood

use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.

the class HeuristicTestUtils method addNoGoods.

static void addNoGoods(AtomStore atomStore, WritableAssignment assignment, NoGoodStoreAlphaRoaming noGoodStore, VSIDS vsids, NoGood... noGoods) {
    int numberOfAtoms = Arrays.stream(noGoods).flatMapToInt(NoGood::stream).map(Literals::atomOf).max().getAsInt();
    TestUtils.fillAtomStore(atomStore, numberOfAtoms);
    assignment.growForMaxAtomId();
    noGoodStore.growForMaxAtomId(numberOfAtoms);
    vsids.growForMaxAtomId(numberOfAtoms);
    Collection<NoGood> setOfNoGoods = new HashSet<>();
    int noGoodId = 1;
    for (NoGood noGood : noGoods) {
        setOfNoGoods.add(noGood);
        noGoodStore.add(noGoodId++, noGood);
    }
    vsids.heapOfActiveAtoms.newNoGoods(setOfNoGoods);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Literals(at.ac.tuwien.kr.alpha.core.atoms.Literals) HashSet(java.util.HashSet)

Example 29 with NoGood

use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.

the class GroundConflictNoGoodLearnerTest method subCurrentDLPropagationWithChoiceCauseOfConflict.

@Test
@Disabled("TrailAssignment no longer propagates at lower decision level.")
public void subCurrentDLPropagationWithChoiceCauseOfConflict() {
    GroundConflictNoGoodLearner learner = new GroundConflictNoGoodLearner(assignment, atomStore);
    NoGood n1 = new NoGood(fromOldLiterals(1, -2));
    NoGood n2 = new NoGood(fromOldLiterals(2, 3));
    store.add(10, n1);
    assignment.choose(1, ThriceTruth.TRUE);
    assignment.choose(3, ThriceTruth.TRUE);
    store.propagate();
    assertEquals(ThriceTruth.MBT, assignment.get(2).getTruth());
    assertEquals(1, assignment.get(2).getDecisionLevel());
    ConflictCause conflictCause = store.add(11, n2);
    assertNotNull(conflictCause);
    assertNotNull(conflictCause.getAntecedent());
    GroundConflictNoGoodLearner.ConflictAnalysisResult conflictAnalysisResult = learner.analyzeConflictingNoGood(conflictCause.getAntecedent());
    assertNull(conflictAnalysisResult.learnedNoGood);
    assertEquals(2, conflictAnalysisResult.backjumpLevel);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) ConflictCause(at.ac.tuwien.kr.alpha.core.solver.ConflictCause) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 30 with NoGood

use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.

the class NoGoodStoreAlphaRoamingTest method conflictingFact.

@Test
public void conflictingFact() {
    final NoGood noGood = fact(fromOldLiterals(-1));
    assignment.assign(1, FALSE);
    ConflictCause conflictCause = store.add(1, noGood);
    assertNotNull(conflictCause);
    assertTrue(antecedentsEquals(noGood.asAntecedent(), conflictCause.getAntecedent()));
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test)

Aggregations

NoGood (at.ac.tuwien.kr.alpha.core.common.NoGood)91 Test (org.junit.jupiter.api.Test)73 Disabled (org.junit.jupiter.api.Disabled)10 TrailAssignment (at.ac.tuwien.kr.alpha.core.solver.TrailAssignment)4 LinkedHashMap (java.util.LinkedHashMap)4 Substitution (at.ac.tuwien.kr.alpha.api.grounder.Substitution)3 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)3 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)3 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)3 BasicSubstitution (at.ac.tuwien.kr.alpha.commons.substitutions.BasicSubstitution)3 RuleAtom (at.ac.tuwien.kr.alpha.core.atoms.RuleAtom)3 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)3 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)3 StratifiedEvaluation (at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluation)3 CompiledRule (at.ac.tuwien.kr.alpha.core.rules.CompiledRule)3 ConflictAnalysisResult (at.ac.tuwien.kr.alpha.core.solver.learning.GroundConflictNoGoodLearner.ConflictAnalysisResult)3 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)2 Literal (at.ac.tuwien.kr.alpha.api.programs.literals.Literal)2 Literals.atomToLiteral (at.ac.tuwien.kr.alpha.core.atoms.Literals.atomToLiteral)2 Literals.atomToNegatedLiteral (at.ac.tuwien.kr.alpha.core.atoms.Literals.atomToNegatedLiteral)2