use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.
the class DefaultSolver method learnBackjumpAddFromConflict.
/**
* Analyzes the conflict and learns a new NoGood (causing backjumping and addition to the NoGood store).
*
* @return false iff the analysis result shows that the set of NoGoods is unsatisfiable.
*/
private boolean learnBackjumpAddFromConflict(ConflictCause conflictCause) {
GroundConflictNoGoodLearner.ConflictAnalysisResult analysisResult = learner.analyzeConflictingNoGood(conflictCause.getAntecedent());
LOGGER.debug("Analysis result: {}", analysisResult);
if (analysisResult == UNSAT) {
// Halt if unsatisfiable.
return false;
}
branchingHeuristic.analyzedConflict(analysisResult);
if (analysisResult.learnedNoGood == null) {
throw oops("Did not learn new NoGood from conflict.");
}
choiceManager.backjump(analysisResult.backjumpLevel);
final NoGood learnedNoGood = analysisResult.learnedNoGood;
int noGoodId = grounder.register(learnedNoGood);
return addAndBackjumpIfNecessary(noGoodId, learnedNoGood, analysisResult.lbd);
}
use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.
the class DefaultSolver method prepareForSubsequentAnswerSet.
private void prepareForSubsequentAnswerSet() {
// We already found one Answer-Set and are requested to find another one.
searchState.afterAllAtomsAssigned = false;
if (assignment.getDecisionLevel() == 0) {
// Solver is at decision level 0 again after finding some answer-set
searchState.isSearchSpaceCompletelyExplored = true;
return;
}
// Create enumeration NoGood to avoid finding the same Answer-Set twice.
final NoGood enumerationNoGood = choiceManager.computeEnumeration();
final int backjumpLevel = assignment.minimumConflictLevel(enumerationNoGood);
if (backjumpLevel == -1) {
throw oops("Enumeration nogood is not violated");
}
if (backjumpLevel == 0) {
// Search space exhausted (only happens if first choice is for TRUE at decision level 1 for an atom that was MBT at decision level 0 already).
searchState.isSearchSpaceCompletelyExplored = true;
return;
}
// Backjump instead of backtrackSlow, enumerationNoGood will invert last choice.
choiceManager.backjump(backjumpLevel - 1);
LOGGER.debug("Adding enumeration nogood: {}", enumerationNoGood);
if (!addAndBackjumpIfNecessary(grounder.register(enumerationNoGood), enumerationNoGood, Integer.MAX_VALUE)) {
searchState.isSearchSpaceCompletelyExplored = true;
}
}
use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.
the class NaiveNoGoodStore method propagate.
@Override
public ConflictCause propagate() {
hasInferredAssignments = false;
boolean any = false;
boolean retry;
do {
retry = false;
ConflictCause conflictCause;
for (NoGood noGood : delegate.values()) {
hasInferredAssignments = false;
conflictCause = propagateWeakly(noGood);
if (conflictCause != null) {
return conflictCause;
}
if (hasInferredAssignments) {
any = true;
hasInferredAssignments = false;
retry = true;
}
}
for (NoGood noGood : delegate.values()) {
hasInferredAssignments = false;
conflictCause = propagateStrongly(noGood);
if (conflictCause != null) {
return conflictCause;
}
if (hasInferredAssignments) {
any = true;
hasInferredAssignments = false;
retry = true;
}
}
} while (retry);
for (NoGood noGood : delegate.values()) {
if (assignment.violates(noGood)) {
return new ConflictCause(noGood.asAntecedent());
}
}
if (any) {
hasInferredAssignments = true;
}
return null;
}
use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.
the class NogoodRegistry method register.
void register(Iterable<NoGood> noGoods, Map<Integer, NoGood> difference) {
for (NoGood noGood : noGoods) {
// Check if noGood was already derived earlier, add if it is new
if (!registeredIdentifiers.containsKey(noGood)) {
int noGoodId = ID_GENERATOR.getNextId();
registeredIdentifiers.put(noGood, noGoodId);
difference.put(noGoodId, noGood);
}
}
}
use of at.ac.tuwien.kr.alpha.core.common.NoGood in project Alpha by alpha-asp.
the class NaiveGrounderTest method groundRuleAlreadyGround.
/**
* Asserts that a ground rule whose positive body is not satisfied by the empty assignment
* is grounded immediately.
*/
@Test
public void groundRuleAlreadyGround() {
ASPCore2Program program = PROGRAM_PARSER.parse("a :- not b. " + "b :- not a. " + "c :- b.");
NormalProgram normal = NORMALIZE_TRANSFORM.apply(program);
CompiledProgram prog = new StratifiedEvaluation().apply(AnalyzedProgram.analyzeNormalProgram(normal));
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", prog, atomStore, true);
Map<Integer, NoGood> noGoods = grounder.getNoGoods(new TrailAssignment(atomStore));
int litCNeg = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("c")), false);
int litB = Literals.atomToLiteral(atomStore.get(PROGRAM_PART_PARSER.parseBasicAtom("b")));
assertExistsNoGoodContaining(noGoods.values(), litCNeg);
assertExistsNoGoodContaining(noGoods.values(), litB);
}
Aggregations