use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class AlphaImplTest method filterTest.
/**
* Verifies that filters are handled correctly (regression test case introduced when fixing issue #189).
*/
@Test
public void filterTest() {
String progstr = "a. b. c. d :- c. e(a, b) :- d.";
Alpha system = new AlphaImpl();
ASPCore2Program prog = system.readProgramString(progstr);
Set<AnswerSet> actual = system.solve(prog, (p) -> p.equals(Predicates.getPredicate("a", 0)) || p.equals(Predicates.getPredicate("e", 2))).collect(Collectors.toSet());
Set<AnswerSet> expected = new HashSet<>(singletonList(new AnswerSetBuilder().predicate("a").predicate("e").symbolicInstance("a", "b").build()));
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class AlphaImplTest method supplier.
@Test
public void supplier() throws Exception {
Alpha system = new AlphaImpl();
InputConfig cfg = InputConfig.forString("node(1). a :- &bestNode(X), node(X).");
cfg.addPredicateMethod("bestNode", Externals.processPredicate(() -> singleton(singletonList(Terms.newConstant(1)))));
ASPCore2Program prog = system.readProgram(cfg);
Set<AnswerSet> expected = AnswerSetsParser.parse("{ node(1), a }");
Set<AnswerSet> actual = system.solve(prog).collect(Collectors.toSet());
assertEquals(expected, actual);
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class StratificationAlgorithmTest method stratifyTwoRulesTest.
@Test
public void stratifyTwoRulesTest() {
StringBuilder bld = new StringBuilder();
bld.append("b :- a.").append("\n");
bld.append("c :- b.").append("\n");
ASPCore2Program prog = parser.parse(bld.toString());
NormalProgram normalProg = normalizeTransform.apply(prog);
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalProg);
DependencyGraph dg = analyzed.getDependencyGraph();
ComponentGraph cg = ComponentGraphImpl.buildComponentGraph(dg, StronglyConnectedComponentsAlgorithm.findStronglyConnectedComponents(dg));
List<SCComponent> strata = StratificationAlgorithm.calculateStratification(cg);
Predicate a = Predicates.getPredicate("a", 0);
Predicate b = Predicates.getPredicate("b", 0);
Predicate c = Predicates.getPredicate("c", 0);
assertEquals(3, strata.size());
assertTrue(predicateIsBeforePredicateInOrder(a, b, strata));
assertTrue(predicateIsBeforePredicateInOrder(b, c, strata));
assertTrue(predicateIsBeforePredicateInOrder(a, c, strata));
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class StratificationAlgorithmTest method avoidDuplicatesTest1.
@Test
public void avoidDuplicatesTest1() {
StringBuilder bld = new StringBuilder();
bld.append("b :- a.");
bld.append("c :- b.");
bld.append("c :- a.");
ASPCore2Program prog = parser.parse(bld.toString());
NormalProgram normalProg = normalizeTransform.apply(prog);
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalProg);
DependencyGraph dg = analyzed.getDependencyGraph();
ComponentGraph cg = ComponentGraphImpl.buildComponentGraph(dg, StronglyConnectedComponentsAlgorithm.findStronglyConnectedComponents(dg));
List<SCComponent> strata = StratificationAlgorithm.calculateStratification(cg);
Predicate a = Predicates.getPredicate("a", 0);
Predicate b = Predicates.getPredicate("b", 0);
Predicate c = Predicates.getPredicate("c", 0);
assertTrue(predicateIsBeforePredicateInOrder(a, b, strata));
assertTrue(predicateIsBeforePredicateInOrder(b, c, strata));
assertTrue(predicateIsBeforePredicateInOrder(a, c, strata));
assertEquals(3, strata.size());
}
use of at.ac.tuwien.kr.alpha.api.programs.ASPCore2Program in project Alpha by alpha-asp.
the class StratificationAlgorithmTest method stratifyOneRuleTest.
@Test
public void stratifyOneRuleTest() {
ASPCore2Program prog = parser.parse("a :- b.");
NormalProgram normalProg = normalizeTransform.apply(prog);
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalProg);
DependencyGraph dg = analyzed.getDependencyGraph();
ComponentGraph cg = ComponentGraphImpl.buildComponentGraph(dg, StronglyConnectedComponentsAlgorithm.findStronglyConnectedComponents(dg));
List<SCComponent> strata = StratificationAlgorithm.calculateStratification(cg);
Predicate a = Predicates.getPredicate("a", 0);
Predicate b = Predicates.getPredicate("b", 0);
assertEquals(2, strata.size());
assertTrue(predicateIsBeforePredicateInOrder(b, a, strata));
}
Aggregations