use of at.ac.tuwien.kr.alpha.api.config.SystemConfig in project Alpha by alpha-asp.
the class StratifiedEvaluationRegressionTest method runTest.
@ParameterizedTest
@MethodSource("at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluationRegressionTest#params")
public void runTest(String aspString, Consumer<CompiledProgram> programVerifier, Consumer<Set<AnswerSet>> resultVerifier) {
// Parse and pre-evaulate program
ProgramParser parser = new ProgramParserImpl();
ASPCore2Program prog = parser.parse(aspString);
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(new NormalizeProgramTransformation(SystemConfig.DEFAULT_AGGREGATE_REWRITING_CONFIG).apply(prog));
CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
// Verify stratified evaluation result
programVerifier.accept(evaluated);
// Solve remaining program
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", evaluated, atomStore, false);
Solver solver = SolverFactory.getInstance(new SystemConfig(), atomStore, grounder);
Set<AnswerSet> answerSets = solver.collectSet();
resultVerifier.accept(answerSets);
}
use of at.ac.tuwien.kr.alpha.api.config.SystemConfig in project Alpha by alpha-asp.
the class AlphaImplTest method problematicRun_3col_1119718541727902_sorted_400.
/**
* Runs a test that formerly caused some sort of exception.
*/
@Test
public void problematicRun_3col_1119718541727902_sorted_400() throws IOException {
/*
* NOTE: This was constructed from the following commandline invocation:
* -DebugEnableInternalChecks -q -g naive -s default -sort -n 400 -i 3col-20-38.txt
*/
SystemConfig cfg = new SystemConfig();
cfg.setGrounderName("naive");
cfg.setSolverName("default");
cfg.setNogoodStoreName("alpharoaming");
cfg.setDebugInternalChecks(true);
cfg.setSeed(1119718541727902L);
final Alpha system = new AlphaImpl(cfg);
final Path path = Paths.get("src", "test", "resources", "PreviouslyProblematic").resolve("3col-20-38.txt");
InputConfig inputCfg = new InputConfig();
List<String> files = new ArrayList<>();
files.add(path.toString());
inputCfg.setFiles(files);
ASPCore2Program prog = system.readProgram(inputCfg);
assertFalse(system.solve(prog).sorted().limit(400).collect(Collectors.toList()).isEmpty());
}
use of at.ac.tuwien.kr.alpha.api.config.SystemConfig in project Alpha by alpha-asp.
the class RegressionTestConfig method toSystemConfig.
public SystemConfig toSystemConfig() {
SystemConfig retVal = new SystemConfig();
retVal.setGrounderName(this.grounderName);
retVal.setSolverName(this.solverName);
retVal.setNogoodStoreName(this.noGoodStoreName);
retVal.setSeed(this.seed);
retVal.setBranchingHeuristic(this.branchingHeuristic);
retVal.setDebugInternalChecks(this.debugChecks);
retVal.setEvaluateStratifiedPart(this.evaluateStratifiedPart);
retVal.setGrounderAccumulatorEnabled(this.disableInstanceRemoval);
retVal.setGrounderToleranceRules(this.grounderToleranceRules);
retVal.setGrounderToleranceConstraints(this.grounderToleranceConstraints);
retVal.getAggregateRewritingConfig().setUseSortingGridEncoding(this.encodeAggregatesUsingSortingGrid);
retVal.getAggregateRewritingConfig().setSupportNegativeValuesInSums(this.supportNegativeSumElements);
return retVal;
}
use of at.ac.tuwien.kr.alpha.api.config.SystemConfig in project Alpha by alpha-asp.
the class AlphaImplTest method testLearnedUnaryNoGoodCausingOutOfOrderLiteralsConflict.
// Detailed reproduction test-case for github issue #239.
@Test
public void testLearnedUnaryNoGoodCausingOutOfOrderLiteralsConflict() throws IOException {
final ProgramParser parser = new ProgramParserImpl();
InputProgram.Builder bld = InputProgram.builder();
bld.accumulate(parser.parse(Files.newInputStream(Paths.get("src", "test", "resources", "HanoiTower_Alpha.asp"), StandardOpenOption.READ)));
bld.accumulate(parser.parse(Files.newInputStream(Paths.get("src", "test", "resources", "HanoiTower_instances", "simple.asp"), StandardOpenOption.READ)));
InputProgram parsedProgram = bld.build();
SystemConfig config = new SystemConfig();
config.setSolverName("default");
config.setNogoodStoreName("alpharoaming");
config.setSeed(0);
config.setBranchingHeuristic(Heuristic.valueOf("VSIDS"));
config.setDebugInternalChecks(true);
config.setDisableJustificationSearch(false);
config.setEvaluateStratifiedPart(false);
config.setReplayChoices(Arrays.asList(21, 26, 36, 56, 91, 96, 285, 166, 101, 290, 106, 451, 445, 439, 448, 433, 427, 442, 421, 415, 436, 409, 430, 397, 391, 424, 385, 379, 418, 373, 412, 406, 394, 388, 382, 245, 232, 208));
Alpha alpha = new AlphaImpl(config);
Optional<AnswerSet> answerSet = alpha.solve(parsedProgram).findFirst();
assertTrue(answerSet.isPresent());
}
use of at.ac.tuwien.kr.alpha.api.config.SystemConfig in project Alpha by alpha-asp.
the class Main method computeAndConsumeAnswerSets.
private static void computeAndConsumeAnswerSets(Solver solver, AlphaConfig alphaCfg) {
SystemConfig sysCfg = alphaCfg.getSystemConfig();
InputConfig inputCfg = alphaCfg.getInputConfig();
Stream<AnswerSet> stream = solver.stream();
if (sysCfg.isSortAnswerSets()) {
stream = stream.sorted();
}
int limit = inputCfg.getNumAnswerSets();
if (limit > 0) {
stream = stream.limit(limit);
}
if (!sysCfg.isQuiet()) {
AtomicInteger counter = new AtomicInteger(0);
final BiConsumer<Integer, AnswerSet> answerSetHandler;
final AnswerSetFormatter<String> fmt = new SimpleAnswerSetFormatter(sysCfg.getAtomSeparator());
BiConsumer<Integer, AnswerSet> stdoutPrinter = (n, as) -> {
System.out.println("Answer set " + Integer.toString(n) + ":" + System.lineSeparator() + fmt.format(as));
};
if (inputCfg.isWriteAnswerSetsAsXlsx()) {
BiConsumer<Integer, AnswerSet> xlsxWriter = new AnswerSetToXlsxWriter(inputCfg.getAnswerSetFileOutputPath());
answerSetHandler = stdoutPrinter.andThen(xlsxWriter);
} else {
answerSetHandler = stdoutPrinter;
}
stream.forEach(as -> {
int cnt = counter.incrementAndGet();
answerSetHandler.accept(cnt, as);
});
if (counter.get() == 0) {
System.out.println("UNSATISFIABLE");
if (inputCfg.isWriteAnswerSetsAsXlsx()) {
try {
AnswerSetToXlsxWriter.writeUnsatInfo(Paths.get(inputCfg.getAnswerSetFileOutputPath() + ".UNSAT.xlsx"));
} catch (IOException ex) {
System.err.println("Failed writing unsat file!");
}
}
} else {
System.out.println("SATISFIABLE");
}
} else {
// Note: Even though we are not consuming the result, we will still compute
// answer sets.
stream.collect(Collectors.toList());
}
if (sysCfg.isPrintStats()) {
if (solver instanceof StatisticsReportingSolver) {
((StatisticsReportingSolver) solver).printStatistics();
} else {
// Note: Should not happen with proper validation of commandline args
System.err.println("Solver of type " + solver.getClass().getSimpleName() + " does not support solving statistics!");
}
}
}
Aggregations