-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.java
68 lines (57 loc) · 2.27 KB
/
Task.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2020
// Author: Matei Simtinică
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* This is the abstract base class for all tasks that have to be implemented.
*/
public abstract class Task {
String inFilename;
String oracleInFilename;
String oracleOutFilename;
String outFilename;
public abstract void solve() throws IOException, InterruptedException;
public abstract void readProblemData() throws IOException;
public void formulateOracleQuestion() throws IOException {}
public void decipherOracleAnswer() throws IOException {}
public abstract void writeAnswer() throws IOException;
/**
* Stores the files paths as class attributes.
*
* @param inFilename the file containing the problem input
* @param oracleInFilename the file containing the oracle input
* @param oracleOutFilename the file containing the oracle output
* @param outFilename the file containing the problem output
*/
public void addFiles(String inFilename, String oracleInFilename, String oracleOutFilename, String outFilename) {
this.inFilename = inFilename;
this.oracleInFilename = oracleInFilename;
this.oracleOutFilename = oracleOutFilename;
this.outFilename = outFilename;
}
/**
* Asks the oracle for an answer to the formulated question.
*
* @throws IOException
* @throws InterruptedException
*/
void askOracle() throws IOException, InterruptedException {
ProcessBuilder builder = new ProcessBuilder();
builder.redirectErrorStream(true);
builder.command("python3", "sat_oracle.py", oracleInFilename, oracleOutFilename);
Process process = builder.start();
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
String buffer;
StringBuilder output = new StringBuilder();
while ((buffer = in.readLine()) != null) {
output.append(buffer).append("\n");
}
int exitCode = process.waitFor();
if (exitCode != 0) {
System.err.println("Error encountered while running oracle");
System.err.println(output.toString());
System.exit(-1);
}
}
}