Search in sources :

Example 11 with InputProgram

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

the class AlphaImplTest method addsFacts.

@Test
public void addsFacts() {
    Alpha system = new AlphaImpl();
    Thingy a = new Thingy();
    Thingy b = new Thingy();
    List<Thingy> things = asList(a, b);
    InputProgram program = InputProgram.builder().addFacts(Externals.asFacts(Thingy.class, things)).build();
    Set<AnswerSet> actual = system.solve(program).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("thingy").instance(a).instance(b).build()));
    assertEquals(expected, actual);
}
Also used : AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 12 with InputProgram

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

the class AlphaImplTest method withExternalSubtype.

@Test
public void withExternalSubtype() throws Exception {
    SubThingy thingy = new SubThingy();
    BasicRule rule = new BasicRule(Heads.newNormalHead(Atoms.newBasicAtom(Predicates.getPredicate("p", 1), Terms.newConstant("x"))), singletonList(Literals.fromAtom(Atoms.newExternalAtom(Predicates.getPredicate("thinger", 1), new MethodPredicateInterpretation(this.getClass().getMethod("thinger", Thingy.class)), singletonList(Terms.newConstant(thingy)), emptyList()), true)));
    Alpha system = new AlphaImpl();
    InputProgram prog = new InputProgram(singletonList(rule), emptyList(), new InlineDirectivesImpl());
    Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
    Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("p").instance("x").build()));
    assertEquals(expected, actual);
}
Also used : BasicRule(at.ac.tuwien.kr.alpha.core.rules.BasicRule) AnswerSet(at.ac.tuwien.kr.alpha.api.AnswerSet) Alpha(at.ac.tuwien.kr.alpha.api.Alpha) MethodPredicateInterpretation(at.ac.tuwien.kr.alpha.core.common.fixedinterpretations.MethodPredicateInterpretation) AnswerSetBuilder(at.ac.tuwien.kr.alpha.commons.AnswerSetBuilder) InlineDirectivesImpl(at.ac.tuwien.kr.alpha.core.parser.InlineDirectivesImpl) InputProgram(at.ac.tuwien.kr.alpha.core.programs.InputProgram) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

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