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);
}
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);
}
}
}
}
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);
}
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);
}
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()));
}
Aggregations