Skip to content

Commit

Permalink
Add berkmin heuristic reset for reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbehofsics committed Jul 26, 2023
1 parent 20c6ebd commit 8bfecd7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,12 @@ private boolean isUnassigned(int atom) {
public String toString() {
return this.getClass().getSimpleName();
}

@Override
public void reset() {
activityCounters = new LinkedHashMap<>();
signCounters = new LinkedHashMap<>();
stackOfNoGoods = new ArrayDeque<>();
stepsSinceLastDecay = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ protected void pushToStack(NoGood noGood) {
}
}
}

@Override
public void reset() {
activeLiterals = new LinkedList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void fillAtomStore(AtomStore atomStore, int numberOfAtomsToFill) {
atomStore.putIfAbsent(Atoms.newBasicAtom(predA, Terms.newConstant(i)));
}
}

public static Atom atom(String predicateName, String... termStrings) {
Term[] terms = new Term[termStrings.length];
for (int i = 0; i < termStrings.length; i++) {
Expand All @@ -75,11 +75,11 @@ public static Atom atom(String predicateName, int... termInts) {
}
return Atoms.newBasicAtom(Predicates.getPredicate(predicateName, terms.length), terms);
}

public static void printNoGoods(AtomStore atomStore, Collection<NoGood> noGoods) {
System.out.println(noGoods.stream().map(atomStore::noGoodToString).collect(Collectors.toSet()));
}

public static void assertAnswerSetsEqual(Set<AnswerSet> expected, Set<AnswerSet> actual) {
if (expected == null) {
if (actual != null) {
Expand Down Expand Up @@ -161,15 +161,15 @@ private static Solver buildSolverFromSystemConfig(ASPCore2Program prog, SystemCo
: InternalProgram.fromNormalProgram(normalProg);
return SolverFactory.getInstance(cfg, atomStore, GrounderFactory.getInstance(cfg.getGrounderName(), preprocessed, atomStore, cfg.isDebugInternalChecks()));
}

public static Solver buildSolverForRegressionTest(ASPCore2Program prog, RegressionTestConfig cfg) {
return buildSolverFromSystemConfig(prog, cfg.toSystemConfig());
}

public static Solver buildSolverForRegressionTest(String prog, RegressionTestConfig cfg) {
return buildSolverFromSystemConfig(new ProgramParserImpl().parse(prog), cfg.toSystemConfig());
}

public static Solver buildSolverForRegressionTest(AtomStore atomStore, Grounder grounder, RegressionTestConfig cfg) {
SystemConfig systemCfg = cfg.toSystemConfig();
return SolverFactory.getInstance(systemCfg, atomStore, grounder);
Expand All @@ -178,7 +178,7 @@ public static Solver buildSolverForRegressionTest(AtomStore atomStore, Grounder
public static Set<AnswerSet> collectRegressionTestAnswerSets(ASPCore2Program prog, RegressionTestConfig cfg) {
return buildSolverForRegressionTest(prog, cfg).collectSet();
}

public static Set<AnswerSet> collectRegressionTestAnswerSets(String aspstr, RegressionTestConfig cfg) {
ASPCore2Program prog = new ProgramParserImpl().parse(aspstr);
return collectRegressionTestAnswerSets(prog, cfg);
Expand All @@ -188,40 +188,35 @@ public static void assertRegressionTestAnswerSet(RegressionTestConfig cfg, Strin
Set<AnswerSet> actualAnswerSets = collectRegressionTestAnswerSets(program, cfg);
TestUtils.assertAnswerSetsEqual(answerSet, actualAnswerSets);
}

public static void assertRegressionTestAnswerSets(RegressionTestConfig cfg, String program, String... answerSets) {
Set<AnswerSet> actualAnswerSets = collectRegressionTestAnswerSets(program, cfg);
TestUtils.assertAnswerSetsEqual(answerSets, actualAnswerSets);
TestUtils.assertAnswerSetsEqual(answerSets, actualAnswerSets);
}

public static void assertRegressionTestAnswerSetsWithBase(RegressionTestConfig cfg, String program, String base, String... answerSets) {
Set<AnswerSet> actualAnswerSets = collectRegressionTestAnswerSets(program, cfg);
TestUtils.assertAnswerSetsEqualWithBase(base, answerSets, actualAnswerSets);
TestUtils.assertAnswerSetsEqualWithBase(base, answerSets, actualAnswerSets);
}

public static void runWithTimeout(RegressionTestConfig cfg, long baseTimeout, long timeoutFactor, Executable action) {
long timeout = cfg.isDebugChecks() ? timeoutFactor * baseTimeout : baseTimeout;
assertTimeoutPreemptively(Duration.ofMillis(timeout), action);
}

public static void ignoreTestForNaiveSolver(RegressionTestConfig cfg) {
Assumptions.assumeFalse(cfg.getSolverName().equals("naive"));
}

public static void ignoreTestForNonDefaultDomainIndependentHeuristics(RegressionTestConfig cfg) {
Assumptions.assumeTrue(cfg.getBranchingHeuristic() == Heuristic.VSIDS);
}

public static void ignoreTestForSimplifiedSumAggregates(RegressionTestConfig cfg) {
Assumptions.assumeTrue(cfg.isSupportNegativeSumElements());
}

public static void ignoreTestForRebootEnabled(RegressionTestConfig cfg) {
Assumptions.assumeFalse(cfg.isRebootEnabled());
}

public static void ignoreTestForRebootDisabled(RegressionTestConfig cfg) {
Assumptions.assumeTrue(cfg.isRebootEnabled());
}

}

0 comments on commit 8bfecd7

Please sign in to comment.