Search in sources :

Example 51 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program 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)

Example 52 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class ParserTest method parseChoiceRule.

@Test
public void parseChoiceRule() {
    ASPCore2Program parsedProgram = parser.parse("dom(1). dom(2). { a ; b } :- dom(X).");
    ChoiceHead choiceHead = (ChoiceHead) parsedProgram.getRules().get(0).getHead();
    assertEquals(2, choiceHead.getChoiceElements().size());
    assertTrue(choiceHead.getChoiceElements().get(0).getChoiceAtom().toString().equals("a"));
    assertTrue(choiceHead.getChoiceElements().get(1).getChoiceAtom().toString().equals("b"));
    assertEquals(null, choiceHead.getLowerBound());
    assertEquals(null, choiceHead.getUpperBound());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) ChoiceHead(at.ac.tuwien.kr.alpha.api.rules.heads.ChoiceHead) Test(org.junit.jupiter.api.Test)

Example 53 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class ParserTest method parseChoiceRuleBounded.

@Test
public void parseChoiceRuleBounded() {
    ASPCore2Program parsedProgram = parser.parse("dom(1). dom(2). 1 < { a: p(v,w), not r; b } <= 13 :- dom(X). foo.");
    ChoiceHead choiceHead = (ChoiceHead) parsedProgram.getRules().get(0).getHead();
    assertEquals(2, choiceHead.getChoiceElements().size());
    assertTrue(choiceHead.getChoiceElements().get(0).getChoiceAtom().toString().equals("a"));
    assertTrue(choiceHead.getChoiceElements().get(1).getChoiceAtom().toString().equals("b"));
    List<Literal> conditionalLiterals = choiceHead.getChoiceElements().get(0).getConditionLiterals();
    assertEquals(2, conditionalLiterals.size());
    assertFalse(conditionalLiterals.get(0).isNegated());
    assertTrue(conditionalLiterals.get(1).isNegated());
    assertEquals(Terms.newConstant(1), choiceHead.getLowerBound());
    assertEquals(ComparisonOperators.LT, choiceHead.getLowerOperator());
    assertEquals(Terms.newConstant(13), choiceHead.getUpperBound());
    assertEquals(ComparisonOperators.LE, choiceHead.getUpperOperator());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) ChoiceHead(at.ac.tuwien.kr.alpha.api.rules.heads.ChoiceHead) Literal(at.ac.tuwien.kr.alpha.api.programs.literals.Literal) AggregateLiteral(at.ac.tuwien.kr.alpha.api.programs.literals.AggregateLiteral) Test(org.junit.jupiter.api.Test)

Example 54 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class ParserTest method parseBuiltinAtom.

@Test
public void parseBuiltinAtom() {
    ASPCore2Program parsedProgram = parser.parse("a :- p(X), X != Y, q(Y).");
    assertEquals(1, parsedProgram.getRules().size());
    assertEquals(3, parsedProgram.getRules().get(0).getBody().size());
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Test(org.junit.jupiter.api.Test)

Example 55 with ASPCore2Program

use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.

the class ParserTest method parseEnumerationDirective.

@Test
public void parseEnumerationDirective() {
    ASPCore2Program parsedProgram = parser.parse("p(a,1)." + "# enumeration_predicate_is mune." + "r(X) :- p(X), mune(X)." + "p(b,2).");
    String directive = parsedProgram.getInlineDirectives().getDirectiveValue(InlineDirectives.DIRECTIVE.enum_predicate_is);
    assertEquals("mune", directive);
}
Also used : ASPCore2Program(at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program) Test(org.junit.jupiter.api.Test)

Aggregations

ASPCore2Program (at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program)89 Test (org.junit.jupiter.api.Test)70 AnswerSet (at.ac.tuwien.kr.alpha.api.AnswerSet)23 NormalProgram (at.ac.tuwien.kr.alpha.api.programs.NormalProgram)22 Alpha (at.ac.tuwien.kr.alpha.api.Alpha)21 InputConfig (at.ac.tuwien.kr.alpha.api.config.InputConfig)19 AnalyzedProgram (at.ac.tuwien.kr.alpha.core.programs.AnalyzedProgram)15 ProgramParserImpl (at.ac.tuwien.kr.alpha.core.parser.ProgramParserImpl)14 DependencyGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.DependencyGraph)12 CompiledProgram (at.ac.tuwien.kr.alpha.core.programs.CompiledProgram)11 Atom (at.ac.tuwien.kr.alpha.api.programs.atoms.Atom)10 Disabled (org.junit.jupiter.api.Disabled)9 SystemConfig (at.ac.tuwien.kr.alpha.api.config.SystemConfig)8 AtomStoreImpl (at.ac.tuwien.kr.alpha.core.common.AtomStoreImpl)8 InputProgram (at.ac.tuwien.kr.alpha.core.programs.InputProgram)8 HashSet (java.util.HashSet)8 Predicate (at.ac.tuwien.kr.alpha.api.programs.Predicate)7 ComponentGraph (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph)7 SCComponent (at.ac.tuwien.kr.alpha.api.programs.analysis.ComponentGraph.SCComponent)7 AtomStore (at.ac.tuwien.kr.alpha.core.common.AtomStore)7