Search in sources :

Example 61 with NoGood

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

the class GroundConflictNoGoodLearnerTest method smallConflictNonTrivial1UIP.

@Test
public void smallConflictNonTrivial1UIP() {
    GroundConflictNoGoodLearner learner = new GroundConflictNoGoodLearner(assignment, atomStore);
    NoGood n1 = new NoGood(fromOldLiterals(2, -8, 1));
    NoGood n2 = new NoGood(fromOldLiterals(-1, -7));
    NoGood n3 = new NoGood(fromOldLiterals(-3, 1));
    NoGood n4 = new NoGood(fromOldLiterals(5, 3));
    NoGood n5 = new NoGood(fromOldLiterals(6, -5));
    NoGood n6 = new NoGood(fromOldLiterals(4, -2));
    NoGood n7 = new NoGood(fromOldLiterals(-6, -4));
    store.add(10, n1);
    store.add(11, n2);
    store.add(12, n3);
    store.add(13, n4);
    store.add(14, n5);
    store.add(15, n6);
    store.add(16, n7);
    assignment.choose(9, ThriceTruth.TRUE);
    assignment.choose(8, ThriceTruth.FALSE);
    assertNull(store.propagate());
    assertFalse(store.didPropagate());
    assignment.choose(7, ThriceTruth.FALSE);
    ConflictCause conflictCause = store.propagate();
    assertTrue(store.didPropagate());
    assertNotNull(conflictCause);
    Antecedent violatedNoGood = conflictCause.getAntecedent();
    assertNotNull(violatedNoGood);
    assertTrue(antecedentsEquals(violatedNoGood, n5.asAntecedent()) || antecedentsEquals(violatedNoGood, n7.asAntecedent()));
    GroundConflictNoGoodLearner.ConflictAnalysisResult analysisResult = learner.analyzeConflictingNoGood(conflictCause.getAntecedent());
    NoGood learnedNoGood = analysisResult.learnedNoGood;
    assertEquals(new NoGood(fromOldLiterals(1, -8)), learnedNoGood);
    int backjumpingDecisionLevel = analysisResult.backjumpLevel;
    assertEquals(backjumpingDecisionLevel, 2);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) ConflictCause(at.ac.tuwien.kr.alpha.core.solver.ConflictCause) Antecedent(at.ac.tuwien.kr.alpha.core.solver.Antecedent) Test(org.junit.jupiter.api.Test)

Example 62 with NoGood

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

the class NaiveNoGoodStoreTest method conflictingNary.

@Test
@Disabled("Checks for conflict detection in add.")
public void conflictingNary() {
    final NoGood noGood = new NoGood(fromOldLiterals(1, 2, 3));
    assignment.assign(1, TRUE);
    assignment.assign(2, TRUE);
    assignment.assign(3, 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 63 with NoGood

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

the class NaiveNoGoodStoreTest method naryNoGoodViolatedDuringAdditionAllMbt.

@Test
@Disabled("Checks for conflict detection in add.")
public void naryNoGoodViolatedDuringAdditionAllMbt() {
    NoGood noGood = new NoGood(fromOldLiterals(1, 2, 3));
    assertNull(assignment.assign(1, MBT));
    assertNull(assignment.assign(2, MBT));
    assertNull(assignment.assign(3, MBT));
    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 64 with NoGood

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

the class NaiveNoGoodStoreTest method propagateBinaryMBTTwiceOutofSync.

@Test
public void propagateBinaryMBTTwiceOutofSync() {
    store.add(1, new NoGood(fromOldLiterals(-1, 2)));
    store.add(2, new NoGood(fromOldLiterals(-3, 1)));
    assignment.assign(2, MBT);
    store.propagate();
    assertEquals(MBT, assignment.getTruth(1));
    assertEquals(MBT, assignment.getTruth(3));
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test)

Example 65 with NoGood

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

the class NaiveNoGoodStoreTest method naryNoGoodViolatedAfterAddition.

@Test
public void naryNoGoodViolatedAfterAddition() {
    NoGood noGood = new NoGood(fromOldLiterals(1, 2, 3));
    assertNull(store.add(11, noGood));
    assertNull(assignment.assign(1, MBT));
    assertNull(assignment.assign(2, MBT));
    assertNull(assignment.assign(3, MBT));
    assertNotNull(store.propagate());
}
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