Search in sources :

Example 71 with NoGood

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

the class NaiveNoGoodStoreTest method addedBinaryNoGoodPropagatesTrueFromTrue.

@Test
public void addedBinaryNoGoodPropagatesTrueFromTrue() {
    NoGood noGood = headFirst(fromOldLiterals(-11, 12));
    assertNull(assignment.choose(12, TRUE));
    assertNull(store.add(5, noGood));
    store.propagate();
    assertEquals(TRUE, assignment.getTruth(11));
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test)

Example 72 with NoGood

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

the class NaiveNoGoodStoreTest method conflictingBinary.

@Test
@Disabled("Checks for conflict detection in add.")
public void conflictingBinary() {
    final NoGood noGood = new NoGood(fromOldLiterals(1, 2));
    assignment.assign(1, TRUE);
    assignment.assign(2, TRUE);
    ConflictCause conflictCause = store.add(1, noGood);
    assertTrue(antecedentsEquals(noGood.asAntecedent(), conflictCause.getAntecedent()));
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 73 with NoGood

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

the class NaiveNoGoodStoreTest method propagationAtLowerDecisionLevel.

@Test
@Disabled("Not decision-level aware.")
public void propagationAtLowerDecisionLevel() {
    NoGood noGood = headFirst(fromOldLiterals(-1, 2, -3));
    assertNull(assignment.choose(3, FALSE));
    assertNull(assignment.choose(2, TRUE));
    assertNull(assignment.choose(4, TRUE));
    assertNull(store.add(10, noGood));
    assertNull(store.propagate());
    assertEquals(TRUE, assignment.getTruth(1));
    Assignment.Entry entry = assignment.get(1);
    assertEquals(TRUE, entry.getTruth());
    assertEquals(2, entry.getDecisionLevel());
}
Also used : Assignment(at.ac.tuwien.kr.alpha.core.common.Assignment) NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 74 with NoGood

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

the class NaiveNoGoodStoreTest method binaryNoGoodViolatedDuringAdditionAllTrue.

@Test
@Disabled("Checks for conflict detection in add.")
public void binaryNoGoodViolatedDuringAdditionAllTrue() {
    NoGood noGood = new NoGood(fromOldLiterals(1, 2));
    assertNull(assignment.assign(1, TRUE));
    assertNull(assignment.assign(2, TRUE));
    ConflictCause conflictCause = store.add(11, noGood);
    assertNotNull(conflictCause);
    assertNotNull(conflictCause.getAntecedent());
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 75 with NoGood

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

the class DefaultSolver method learnFromConflict.

private void learnFromConflict(ConflictCause conflictCause) {
    LOGGER.debug("Violating assignment is: {}", assignment);
    Antecedent conflictAntecedent = conflictCause.getAntecedent();
    NoGood violatedNoGood = new NoGood(conflictAntecedent.getReasonLiterals().clone());
    // TODO: The violatedNoGood should not be necessary here, but this requires major type changes in heuristics.
    branchingHeuristic.violatedNoGood(violatedNoGood);
    if (searchState.afterAllAtomsAssigned) {
        LOGGER.debug("Assignment is violated after all unassigned atoms have been assigned false.");
        conflictsAfterClosing++;
        if (!treatConflictAfterClosing(conflictAntecedent)) {
            searchState.isSearchSpaceCompletelyExplored = true;
        }
        searchState.afterAllAtomsAssigned = false;
    } else {
        if (!learnBackjumpAddFromConflict(conflictCause)) {
            searchState.isSearchSpaceCompletelyExplored = true;
        }
    }
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood)

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