Search in sources :

Example 1 with InputProgram

use of at.ac.tuwien.kr.alpha.core.programs.InputProgram in project Alpha by alpha-asp.

the class ThreeColouringTestWithRandom method testThreeColouring.

private void testThreeColouring(int n, boolean shuffle, int seed, RegressionTestConfig cfg) {
    ASPCore2Program tmpPrg = new ProgramParserImpl().parse("col(V,C) :- v(V), c(C), not ncol(V,C)." + "ncol(V,C) :- col(V,D), c(C), C != D." + ":- e(V,U), col(V,C), col(U,C).");
    InputProgram.Builder prgBuilder = InputProgram.builder().accumulate(tmpPrg);
    prgBuilder.addFacts(createColors("1", "2", "3"));
    prgBuilder.addFacts(createVertices(n));
    prgBuilder.addFacts(createEdges(n, shuffle, seed));
    InputProgram program = prgBuilder.build();
    Solver solver = buildSolverForRegressionTest(program, cfg);
    @SuppressWarnings("unused") Optional<AnswerSet> answerSet = solver.stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Example 2 with InputProgram

use of at.ac.tuwien.kr.alpha.core.programs.InputProgram 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());
}
Also used : SystemConfig(at.ac.tuwien.kr.alpha.api.config.SystemConfig) ProgramParser(at.ac.tuwien.kr.alpha.api.programs.ProgramParser) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) Test(org.junit.jupiter.api.Test)

Example 3 with InputProgram

use of at.ac.tuwien.kr.alpha.core.programs.InputProgram in project Alpha by alpha-asp.

the class SolverTests method testObjectProgram.

@RegressionTest
public void testObjectProgram(RegressionTestConfig cfg) {
    final Thingy thingy = new Thingy();
    final Atom fact = Atoms.newBasicAtom(Predicates.getPredicate("foo", 1), Terms.newConstant(thingy));
    final InputProgram program = new InputProgram(Collections.emptyList(), Collections.singletonList(fact), new InlineDirectivesImpl());
    assertEquals(singleton(new AnswerSetBuilder().predicate("foo").instance(thingy).build()), collectRegressionTestAnswerSets(program, cfg));
}
Also used : AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) Atom(at.ac.tuwien.kr.alpha.api.programs.atoms.Atom) InlineDirectivesImpl(at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) TestUtils.buildSolverForRegressionTest(at.ac.tuwien.kr.alpha.core.test.util.TestUtils.buildSolverForRegressionTest)

Example 4 with InputProgram

use of at.ac.tuwien.kr.alpha.core.programs.InputProgram in project Alpha by alpha-asp.

the class ThreeColouringWheelTest method testThreeColouring.

private void testThreeColouring(int n, RegressionTestConfig cfg) {
    ASPCore2Program tmpPrg = new ProgramParserImpl().parse("col(V,C) :- v(V), c(C), not ncol(V,C)." + "ncol(V,C) :- col(V,D), c(C), C != D." + ":- e(V,U), col(V,C), col(U,C).");
    InputProgram.Builder prgBuilder = InputProgram.builder(tmpPrg);
    prgBuilder.addFacts(createColors("red", "blue", "green"));
    prgBuilder.addFacts(createVertices(n));
    prgBuilder.addFacts(createEdges(n));
    InputProgram program = prgBuilder.build();
    maybeShuffle(program);
    Solver solver = buildSolverForRegressionTest(program, cfg);
    @SuppressWarnings("unused") Optional<AnswerSet> answerSet = solver.stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Solver(at.ac.tuwien.kr.alpha.api.Solver) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Example 5 with InputProgram

use of at.ac.tuwien.kr.alpha.core.programs.InputProgram in project Alpha by alpha-asp.

the class ThreeColouringRandomGraphTest method testThreeColouring.

private void testThreeColouring(int nVertices, int nEdges, RegressionTestConfig cfg) {
    ASPCore2Program tmpPrg = new ProgramParserImpl().parse("blue(N) :- v(N), not red(N), not green(N)." + "red(N) :- v(N), not blue(N), not green(N)." + "green(N) :- v(N), not red(N), not blue(N)." + ":- e(N1,N2), blue(N1), blue(N2)." + ":- e(N1,N2), red(N1), red(N2)." + ":- e(N1,N2), green(N1), green(N2).");
    InputProgram.Builder prgBuilder = InputProgram.builder(tmpPrg);
    prgBuilder.addFacts(createVertices(nVertices));
    prgBuilder.addFacts(createEdges(nVertices, nEdges));
    InputProgram program = prgBuilder.build();
    maybeShuffle(program);
    @SuppressWarnings("unused") Optional<AnswerSet> answerSet = buildSolverForRegressionTest(program, cfg).stream().findAny();
// System.out.println(answerSet);
// TODO: check correctness of answer set
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) ProgramParserImpl(at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram)

Aggregations

InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)12 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)6 ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)5 BasicRule (at.ac.tuwien.kr.alpha.core.rules.BasicRule)5 Rule (at.ac.tuwien.kr.alpha.api.rules.Rule)4 Head (at.ac.tuwien.kr.alpha.api.rules.heads.Head)4 InlineDirectivesImpl (at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl)4 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)4 ArrayList (java.util.ArrayList)4 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)3 AnswerSetBuilder (at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder)3 Test (org.junit.jupiter.api.Test)3 Solver (at.ac.tuwien.kr.alpha.api.Solver)2 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)2 HashSet (java.util.HashSet)2 ComparisonOperator (at.ac.tuwien.kr.alpha.api.ComparisonOperator)1 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)1 ProgramParser (at.ac.tuwien.kr.alpha.api.programs.ProgramParser)1 AggregateElement (at.ac.tuwien.kr.alpha.api.programs.atoms.AggregateAtom.AggregateElement)1 AggregateFunctionSymbol (at.ac.tuwien.kr.alpha.api.programs.atoms.AggregateAtom.AggregateFunctionSymbol)1