use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class DefaultSolver method provideAnswerSet.
private void provideAnswerSet(Consumer<? super AnswerSet> action) {
// NOTE: If we would do optimization, we would now have a guaranteed upper bound.
AnswerSet as = translate(assignment.getTrueAssignments());
LOGGER.debug("Answer-Set found: {}", as);
action.accept(as);
logStats();
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AnswerSetToXlsxWriterTest method writeAnswerSetFilesTest.
@Test
public void writeAnswerSetFilesTest() throws IOException {
AnswerSet as = new AnswerSetBuilder().predicate("bla").instance("blubb", "blubb").instance("foo", "bar").predicate("foo").instance("bar").instance("baz").predicate("complex").instance(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)).build();
Path tmpDir = Files.createTempDirectory("alpha-test-xlsx-output");
AnswerSetToXlsxWriter writer = new AnswerSetToXlsxWriter(tmpDir.toString() + "/alphaAnswerSet");
writer.accept(0, as);
File tmpDirFile = tmpDir.toFile();
File[] generatedFiles = tmpDirFile.listFiles();
assertEquals(1, generatedFiles.length);
File answerSetFile = generatedFiles[0];
assertEquals("alphaAnswerSet.0.xlsx", answerSetFile.getName());
try (Workbook wb = WorkbookFactory.create(answerSetFile)) {
AnswerSetToWorkbookMapperTest.assertWorkbookMatchesAnswerSet(wb, as);
}
// clean up
answerSetFile.delete();
tmpDirFile.delete();
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AnswerSetToWorkbookMapperTest method solveAndWriteWorkbookTest.
@Test
public void solveAndWriteWorkbookTest() {
// @formatter:off
String progstr = "aFlag. oneMoreFlag. yetAnotherFlag. createPs. maxP(5). r(s(1, 2, 3), 4). r(bla, blubb). r(foo, bar(baaz))." + "p(0) :- createPs. " + "p(N) :- p(I), N = I + 1, N <= MX, maxP(MX)." + "q(A, B) :- p(A), p(B).";
// @formatter:on
Alpha alpha = new AlphaImpl();
List<AnswerSet> answerSets = alpha.solve(alpha.readProgramString(progstr)).collect(Collectors.toList());
assertEquals(1, answerSets.size());
AnswerSet as = answerSets.get(0);
Workbook answerSetWorkbook = this.mapper.mapFromAnswerSet(as);
AnswerSetToWorkbookMapperTest.assertWorkbookMatchesAnswerSet(answerSetWorkbook, as);
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class AnswerSetToWorkbookMapperTest method smokeTest.
@Test
public void smokeTest() throws IOException {
AnswerSet as = new AnswerSetBuilder().predicate("bla").instance("blubb", "blubb").instance("foo", "bar").predicate("foo").instance("bar").instance("baz").predicate("complex").instance(Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3)).build();
try (Workbook wb = this.mapper.mapFromAnswerSet(as)) {
assertNotNull(wb.getSheet("Flags"));
assertNotNull(wb.getSheet("bla_2"));
assertNotNull(wb.getSheet("foo_1"));
assertNotNull(wb.getSheet("complex_3"));
}
}
use of at.ac.tuwien.kr.alpha.api.AnswerSet in project Alpha by alpha-asp.
the class SimpleAnswerSetFormatterTest method basicFormatterWithSeparator.
@Test
public void basicFormatterWithSeparator() {
AnswerSetFormatter<String> fmt = new SimpleAnswerSetFormatter(" bla ");
AnswerSet as = new AnswerSetBuilder().predicate("p").instance("a").predicate("q").instance("b").build();
String formatted = fmt.format(as);
assertEquals("{ p(\"a\") bla q(\"b\") }", formatted);
}
Aggregations