Search in sources :

Example 86 with NoGood

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

the class BerkMinTest method countNegativeLiteralsOnce.

@Test
public void countNegativeLiteralsOnce() {
    NoGood violatedNoGood = new NoGood(fromOldLiterals(-1, -2));
    berkmin.violatedNoGood(violatedNoGood);
    berkmin.analyzedConflict(pseudo(violatedNoGood));
    assertEquals(1, berkmin.getActivity(fromOldLiterals(-1)), DOUBLE_COMPARISON_EPSILON);
    assertEquals(1, berkmin.getActivity(fromOldLiterals(-2)), DOUBLE_COMPARISON_EPSILON);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test)

Example 87 with NoGood

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

the class BerkMinTest method learnNoGood.

@Test
public void learnNoGood() {
    NoGood learnedNoGood = NoGood.learnt(fromOldLiterals(1, 2));
    int backjumpLevel = 1;
    @SuppressWarnings("unused") boolean clearLastChoiceAfterBackjump = true;
    Collection<Integer> resolutionAtoms = Collections.emptySet();
    berkmin.analyzedConflict(new ConflictAnalysisResult(learnedNoGood, backjumpLevel, resolutionAtoms));
    assertEquals(learnedNoGood, berkmin.getCurrentTopClause());
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) ConflictAnalysisResult(at.ac.tuwien.kr.alpha.core.solver.learning.GroundConflictNoGoodLearner.ConflictAnalysisResult) Test(org.junit.jupiter.api.Test)

Example 88 with NoGood

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

the class HeapOfActiveAtomsTest method testAllAtomsEqualScore.

@Test
public void testAllAtomsEqualScore() {
    int lit1 = Literals.atomToLiteral(1);
    int lit2 = Literals.atomToLiteral(2);
    int lit3 = Literals.atomToLiteral(3);
    HeuristicTestUtils.addNoGoods(atomStore, assignment, noGoodStore, vsids, new NoGood(lit1, lit2), new NoGood(lit2, lit3), new NoGood(lit1, lit3));
    double activity1 = vsids.heapOfActiveAtoms.getActivity(lit1);
    double activity2 = vsids.heapOfActiveAtoms.getActivity(lit2);
    double activity3 = vsids.heapOfActiveAtoms.getActivity(lit3);
    assertEquals(activity1, activity2, DOUBLE_COMPARISON_EPSILON);
    assertEquals(activity2, activity3, DOUBLE_COMPARISON_EPSILON);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test)

Example 89 with NoGood

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

the class HeapOfActiveAtomsTest method testOneAtomHigherScore.

@Test
public void testOneAtomHigherScore() {
    int lit1 = Literals.atomToLiteral(1);
    int lit2 = Literals.atomToLiteral(2);
    int lit3 = Literals.atomToLiteral(3);
    int lit1Neg = Literals.atomToLiteral(1, false);
    int lit2Neg = Literals.atomToLiteral(2, false);
    int lit3Neg = Literals.atomToLiteral(3, false);
    HeuristicTestUtils.addNoGoods(atomStore, assignment, noGoodStore, vsids, new NoGood(lit1, lit2Neg), new NoGood(lit1Neg, lit2), new NoGood(lit2, lit3Neg), new NoGood(lit2Neg, lit3));
    double activity1 = vsids.heapOfActiveAtoms.getActivity(lit1);
    double activity2 = vsids.heapOfActiveAtoms.getActivity(lit2);
    double activity3 = vsids.heapOfActiveAtoms.getActivity(lit3);
    assertLessThan(activity1, activity2);
    assertLessThan(activity3, activity2);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) Test(org.junit.jupiter.api.Test)

Example 90 with NoGood

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

the class VSIDSTest method testConflict.

/**
 * Tests the following artificial situation:
 * Static nogoods: { {-1, -2}, {-3, -4}}
 * Learnt nogood: { 2, 3 }
 * Atoms resolved out during conflict analysis: { 1 }
 */
@Test
public void testConflict() {
    HeuristicTestUtils.addNoGoods(atomStore, assignment, noGoodStore, vsids, new NoGood(lit1Neg, lit2Neg), new NoGood(lit3Neg, lit4Neg));
    // to make VSIDS ingest buffered nogoods
    vsids.chooseLiteral();
    assertEquals(vsids.getActivity(lit1), vsids.getActivity(lit2), DOUBLE_COMPARISON_EPSILON);
    assertEquals(vsids.getActivity(lit2), vsids.getActivity(lit3), DOUBLE_COMPARISON_EPSILON);
    assertEquals(vsids.getActivity(lit3), vsids.getActivity(lit4), DOUBLE_COMPARISON_EPSILON);
    NoGood learnedNoGood = new NoGood(lit2, lit3);
    Collection<Integer> resolutionAtoms = Arrays.asList(1);
    ConflictAnalysisResult analysisResult = new ConflictAnalysisResult(learnedNoGood, 1, resolutionAtoms);
    vsids.analyzedConflict(analysisResult);
    assertEquals(vsids.getActivity(lit1), vsids.getActivity(lit2), DOUBLE_COMPARISON_EPSILON);
    assertEquals(vsids.getActivity(lit2), vsids.getActivity(lit3), DOUBLE_COMPARISON_EPSILON);
    assertLessThan(vsids.getActivity(lit4), vsids.getActivity(lit3));
    assertEquals(0, vsids.getSignBalance(1));
    assertEquals(1, vsids.getSignBalance(2));
    assertEquals(1, vsids.getSignBalance(3));
    assertEquals(0, vsids.getSignBalance(4));
}
Also used : NoGood(at.ac.tuwien.kr.alpha.core.common.NoGood) ConflictAnalysisResult(at.ac.tuwien.kr.alpha.core.solver.learning.GroundConflictNoGoodLearner.ConflictAnalysisResult) 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