Search in sources :

Example 31 with NoGood

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

the class DependencyDrivenHeuristic method chooseAtom.

/**
	 * {@link DependencyDrivenHeuristic} manages a stack of nogoods in the fashion of {@link BerkMin}
	 * and starts by looking at the most active atom <code>a</code> in the nogood currently at the top of the stack.
	 * If <code>a</code> is an active choice point (i.e. representing the body of an applicable rule), it is immediately chosen;
	 * else the most active choice point dependent on <code>a</code> is.
	 * If there is no such atom, we continue further down the stack.
	 * When choosing between dependent atoms, a {@link BodyActivityProvider} is employed to define the activity of a choice point.
	 */
@Override
public int chooseAtom() {
    for (NoGood noGood : stackOfNoGoods) {
        int mostActiveAtom = getMostActiveAtom(noGood);
        if (choiceManager.isActiveChoiceAtom(mostActiveAtom)) {
            return mostActiveAtom;
        }
        Collection<Integer> bodies = atomsToBodies.get(mostActiveAtom);
        Optional<Integer> mostActiveBody = bodies.stream().filter(this::isUnassigned).filter(choiceManager::isActiveChoiceAtom).max(Comparator.comparingDouble(bodyActivity::get));
        if (mostActiveBody.isPresent()) {
            return mostActiveBody.get();
        }
    }
    return DEFAULT_CHOICE_ATOM;
}
Also used : NoGood(at.ac.tuwien.kr.alpha.common.NoGood)

Example 32 with NoGood

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

the class ChoiceManagerTests method testIsAtomChoice.

@Test
public void testIsAtomChoice() {
    Collection<NoGood> noGoods = getNoGoods();
    choiceManager.addChoiceInformation(grounder.getChoiceAtoms());
    for (NoGood noGood : noGoods) {
        for (Integer literal : noGood) {
            int atom = atomOf(literal);
            String atomToString = grounder.atomToString(atom);
            if (atomToString.startsWith(RuleAtom.PREDICATE.getPredicateName())) {
                assertTrue("Atom not choice: " + atomToString, choiceManager.isAtomChoice(atom));
            }
        }
    }
}
Also used : NoGood(at.ac.tuwien.kr.alpha.common.NoGood) Test(org.junit.Test)

Example 33 with NoGood

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

the class GroundConflictNoGoodLearnerTest method subCurrentDLPropagationWithGuessCauseOfConflict.

@Test
public void subCurrentDLPropagationWithGuessCauseOfConflict() {
    GroundConflictNoGoodLearner learner = new GroundConflictNoGoodLearner(assignment);
    NoGood n1 = new NoGood(1, -2);
    NoGood n2 = new NoGood(2, 3);
    store.add(10, n1);
    assignment.guess(1, ThriceTruth.TRUE);
    assignment.guess(3, ThriceTruth.TRUE);
    store.propagate();
    assertEquals(ThriceTruth.MBT, assignment.get(2).getTruth());
    assertEquals(1, assignment.get(2).getDecisionLevel());
    NoGoodStore.ConflictCause conflictCause = store.add(11, n2);
    assertNotNull(conflictCause);
    assertNotNull(conflictCause.violatedNoGood);
    GroundConflictNoGoodLearner.ConflictAnalysisResult conflictAnalysisResult = learner.analyzeConflictingNoGood(conflictCause.violatedNoGood);
    assertNull(conflictAnalysisResult.learnedNoGood);
    assertEquals(2, conflictAnalysisResult.backjumpLevel);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.common.NoGood) Test(org.junit.Test)

Example 34 with NoGood

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

the class GroundConflictNoGoodLearnerTest method smallConflictNonTrivial1UIP.

@Test
public void smallConflictNonTrivial1UIP() {
    GroundConflictNoGoodLearner learner = new GroundConflictNoGoodLearner(assignment);
    NoGood n1 = new NoGood(2, -8, 1);
    NoGood n2 = new NoGood(-1, -7);
    NoGood n3 = new NoGood(-3, 1);
    NoGood n4 = new NoGood(5, 3);
    NoGood n5 = new NoGood(6, -5);
    NoGood n6 = new NoGood(4, -2);
    NoGood n7 = new NoGood(-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.guess(9, ThriceTruth.TRUE);
    assignment.guess(8, ThriceTruth.FALSE);
    assertFalse(store.propagate());
    assignment.guess(7, ThriceTruth.FALSE);
    assertEquals(true, store.propagate());
    NoGood violatedNoGood = store.getViolatedNoGood();
    assertNotNull(violatedNoGood);
    assertTrue(violatedNoGood.equals(n5) || violatedNoGood.equals(n7));
    GroundConflictNoGoodLearner.ConflictAnalysisResult analysisResult = learner.analyzeConflictingNoGood(violatedNoGood);
    NoGood learnedNoGood = analysisResult.learnedNoGood;
    assertEquals(new NoGood(1, -8), learnedNoGood);
    int backjumpingDecisionLevel = analysisResult.backjumpLevel;
    assertEquals(backjumpingDecisionLevel, 2);
    assertFalse(analysisResult.clearLastGuessAfterBackjump);
}
Also used : NoGood(at.ac.tuwien.kr.alpha.common.NoGood) Test(org.junit.Test)

Example 35 with NoGood

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

the class NoGoodStoreAlphaRoamingTest method propagateBinarySecondTrue.

@Test
public void propagateBinarySecondTrue() {
    assignment.assign(1, FALSE);
    store.add(1, new NoGood(new int[] { -1, 2 }, 1));
    store.propagate();
    assertEquals(FALSE, assignment.getTruth(2));
}
Also used : NoGood(at.ac.tuwien.kr.alpha.common.NoGood) Test(org.junit.Test)

Aggregations

NoGood (at.ac.tuwien.kr.alpha.common.NoGood)50 Test (org.junit.Test)41 AnswerSet (at.ac.tuwien.kr.alpha.common.AnswerSet)1 BooleanAssignmentReader (at.ac.tuwien.kr.alpha.grounder.BooleanAssignmentReader)1 ConflictAnalysisResult (at.ac.tuwien.kr.alpha.solver.GroundConflictNoGoodLearner.ConflictAnalysisResult)1