Search in sources :

Example 61 with AnswerSet

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();
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet)

Example 62 with AnswerSet

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();
}
Also used : Path(java.nio.file.Path) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) File(java.io.File) Workbook(org.apache.poi.ss.usermodel.Workbook) AnswerSetToWorkbookMapperTest(at.ac.tuwien.kr.alpha.app.mappers.AnswerSetToWorkbookMapperTest) Test(org.junit.jupiter.api.Test)

Example 63 with AnswerSet

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);
}
Also used : AlphaImpl(at.ac.tuwien.kr.alpha.api.impl.AlphaImpl) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.jupiter.api.Test)

Example 64 with AnswerSet

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"));
    }
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.jupiter.api.Test)

Example 65 with AnswerSet

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);
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) SimpleAnswerSetFormatter(at.ac.tuwien.kr.alpha.commons.util.SimpleAnswerSetFormatter) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)80 Test (org.junit.jupiter.api.Test)64 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)25 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)24 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)20 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)17 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)14 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)14 HashSet (java.util.HashSet)13 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)10 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)9 Solver (at.ac.tuwien.kr.alpha.api.Solver)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)7 Disabled (org.junit.jupiter.api.Disabled)7 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)4 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)4 ConstantTerm (at.ac.tuwien.kr.alpha.api.terms.ConstantTerm)4 TestUtils.assertRegressionTestAnswerSet (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.assertRegressionTestAnswerSet)4 TestUtils.buildSolverForRegressionTest (at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)4 HashMap (java.util.HashMap)4