Skip to content

Commit

Permalink
reading out pyclingo output in a proper way
Browse files Browse the repository at this point in the history
  • Loading branch information
anan02-admin authored and anan02-admin committed Mar 9, 2023
1 parent 871c411 commit 098feac
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ private boolean executeInternalSolver(Problem problem, final int i) {

private boolean extractFactsFormSolverResult(final BufferedReader in, Problem problem) throws IOException, ClingoException {
ArrayList<String> factsFromSolver = new ArrayList();
ArrayList<String> factsFromPyClingo = new ArrayList();
boolean stat = true;
boolean pyclingo = false;
boolean readPyclingo = false;
String line;
/* example output of the solver:
* ... more stupid stuff, looking for the Answer line
Expand All @@ -153,12 +156,23 @@ private boolean extractFactsFormSolverResult(final BufferedReader in, Problem pr
while ( (line = in.readLine()) != null) {
LOG.info(line);
if (line.startsWith("SATISFIABLE")) {
problem.setFacts(factsFromSolver);
if (pyclingo) {
problem.setFacts(factsFromPyClingo);
break;
} else {
problem.setFacts(factsFromSolver);
}
} else if (line.startsWith("UNSATISFIABLE")) {
stat = false;
break;
} else if (line.toLowerCase().contains("error") || line.startsWith("UNKNOWN") ) {
throw new ClingoException("Solver error:" + line, null);
} else if (line.startsWith("pyclingo")) {
pyclingo = true;
} else if (pyclingo && line.startsWith("Answer")) {
readPyclingo = true;
} else if (readPyclingo) {
factsFromPyClingo.add(line);
} else {
// preemptively read all other lines.
// they may be facts or error messages, but we won't know that
Expand Down

0 comments on commit 098feac

Please sign in to comment.