use of at.ac.tuwien.kr.alpha.api.programs.ProgramParser in project Alpha by alpha-asp.
the class StratifiedEvaluationTest method testNegatedExternalLiteral.
@Test
public void testNegatedExternalLiteral() throws Exception {
String asp = "claimedTruth(bla). truth(X) :- claimedTruth(X), &sayTrue[X]. lie(X) :- claimedTruth(X), not &sayTrue[X].";
Map<String, PredicateInterpretation> externals = new HashMap<>();
externals.put("sayTrue", Externals.processPredicateMethod(this.getClass().getMethod("sayTrue", Object.class)));
ProgramParser parserWithExternals = new ProgramParserImpl();
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(normalizer.apply(parserWithExternals.parse(asp, externals)));
CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
Set<AnswerSet> answerSets = solveCompiledProg.apply(evaluated);
TestUtils.assertAnswerSetsEqual("claimedTruth(bla), truth(bla)", answerSets);
}
use of at.ac.tuwien.kr.alpha.api.programs.ProgramParser in project Alpha by alpha-asp.
the class StratifiedEvaluationRegressionTest method runTest.
@ParameterizedTest
@MethodSource("at.ac.tuwien.kr.alpha.core.programs.transformation.StratifiedEvaluationRegressionTest#params")
public void runTest(String aspString, Consumer<CompiledProgram> programVerifier, Consumer<Set<AnswerSet>> resultVerifier) {
// Parse and pre-evaulate program
ProgramParser parser = new ProgramParserImpl();
ASPCore2Program prog = parser.parse(aspString);
AnalyzedProgram analyzed = AnalyzedProgram.analyzeNormalProgram(new NormalizeProgramTransformation(SystemConfig.DEFAULT_AGGREGATE_REWRITING_CONFIG).apply(prog));
CompiledProgram evaluated = new StratifiedEvaluation().apply(analyzed);
// Verify stratified evaluation result
programVerifier.accept(evaluated);
// Solve remaining program
AtomStore atomStore = new AtomStoreImpl();
Grounder grounder = GrounderFactory.getInstance("naive", evaluated, atomStore, false);
Solver solver = SolverFactory.getInstance(new SystemConfig(), atomStore, grounder);
Set<AnswerSet> answerSets = solver.collectSet();
resultVerifier.accept(answerSets);
}
use of at.ac.tuwien.kr.alpha.api.programs.ProgramParser in project Alpha by alpha-asp.
the class UnifierTest method parseAtom.
private BasicAtom parseAtom(String atom) {
ProgramParser programParser = new ProgramParserImpl();
ASPCore2Program program = programParser.parse(atom + ".");
return (BasicAtom) program.getFacts().get(0);
}
use of at.ac.tuwien.kr.alpha.api.programs.ProgramParser 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());
}
use of at.ac.tuwien.kr.alpha.api.programs.ProgramParser in project Alpha by alpha-asp.
the class RuleParser method parse.
public static Rule<Head> parse(String str) {
ProgramParser parser = new ProgramParserImpl();
ASPCore2Program prog = parser.parse(str);
if (!prog.getFacts().isEmpty()) {
throw new IllegalArgumentException("Expected exactly one rule and no facts!");
}
if (prog.getRules().size() != 1) {
throw new IllegalArgumentException("Expected exactly one rule");
}
return prog.getRules().get(0);
}
Aggregations