Commit e9578ce1 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Улучшен дебажный вывод.

parent e5a324ff
......@@ -17,7 +17,7 @@ public class MZnResultsResolver {
return lim2 - lim1 + 1;
}
private static void parseArray(Map<String, ArrayList<ArrayList<String>>> arrays, int pos, String line, TaskCase taskCase, String name) {
public static ArrayList<ArrayList<String>> parse2dArray(int pos, String line, TaskCase taskCase) {
int index = line.indexOf("array", pos);
if (index >= pos) { // Из flatzinc-а.
......@@ -36,7 +36,7 @@ public class MZnResultsResolver {
res.get(i).add(values[i * dim2 + j].trim());
}
}
arrays.put(name, res);
return res;
}
} else { // Из minizinc-а
while ((pos < line.length()) && (line.charAt(pos) != '[') && (line.charAt(pos) != '{')) {
......@@ -81,9 +81,10 @@ public class MZnResultsResolver {
}
res.add(subRes);
}
arrays.put(name, res);
return res;
}
}
return null;
}
public static void resolveMiniZincResults(TaskCase taskCase, String fileName) {
......@@ -118,7 +119,12 @@ public class MZnResultsResolver {
if (name.matches("\\d+")) {
continue;
}
parseArray(arrays, pos, line, taskCase, name);
{
ArrayList<ArrayList<String>> res = parse2dArray(pos, line, taskCase);
if (res != null) {
arrays.put(name, res);
}
}
}
for (String keyArray : Arrays.asList("op_status", "participation_as_resource")) {
......
......@@ -25,6 +25,11 @@ public class Solver {
private int timeLimitS;
private String flatZincSolver = "";
private String solverResults = "";
public void setSolverResults(String solverResults) {
this.solverResults = solverResults;
}
public void setTask(TaskCase task) {
this.task = task;
}
......@@ -75,7 +80,10 @@ public class Solver {
tempDir = tempDir + "/" + i + "/";
String minizincData = tempDir + "minizinc_data.dzn";
String solverResults = tempDir + "solver_results.txt";
if (solverResults.isEmpty()) {
solverResults = tempDir + "solver_results.txt";
}
String constraints = tempDir + "constraints.mzn";
String flatZincConstraints = tempDir + "model.fzn";
......@@ -199,7 +207,7 @@ public class Solver {
} catch (UncheckedIOException | IOException | InterruptedException | ParserException ex) {
return ex.getMessage();
} finally {
removeDirectory(candidate);
// removeDirectory(candidate);
}
return "";
}
......
......@@ -207,7 +207,7 @@ public class Main {
private static void debug(Solver solver, int timeLimitS) {
String fileName = "experiment/in.ipp";
String solverResults = "temp_data/solver_results.txt";
String solverResults = "experiment/solver_results.txt";
String output = "experiment/debug_info.txt";
TaskCase task = new TaskCase();
......@@ -223,6 +223,7 @@ public class Main {
solver.setTimeLimitS(timeLimitS);
solver.setTempDir("temp_data");
solver.setTask(task);
solver.setSolverResults(solverResults);
String error = solver.solve();
long finish = System.currentTimeMillis();
......@@ -235,8 +236,7 @@ public class Main {
task.serialize(fileName);
}
// TODO переделать для or-tools
// debugInfo(task, solverResults, output);
debugInfo(task, solverResults, output);
}
private static void debugReadWrite() {
......@@ -287,115 +287,53 @@ public class Main {
}
String line;
int linesNumber = 0;
while (((line = br.readLine()) != null)) {
System.out.println("line : " + line);
line = line.trim();
if (line.equals("")) {
continue;
}
linesNumber++;
if (linesNumber <= 1) {
continue;
}
int pos = 0;
while ((pos < line.length()) && (line.charAt(pos) != ' ')) {
pos++;
}
String name = line.substring(0, pos);
if (name.equals("----------")) {
if ((name.equals("----------")) || (name.equals("=====UNSATISFIABLE====="))) {
break;
}
while ((pos < line.length()) && (line.charAt(pos) != '[') && (line.charAt(pos) != '{')) {
pos++;
}
int arrayFirstDim = ((int) task.getPlanningInterval()) + 2;
int arraySecondDim = 0;
if (line.charAt(pos) == '{') {
pos++;
int nextPos = pos;
while (line.charAt(nextPos) != '}') {
nextPos++;
}
String []dimensions = line.substring(pos, nextPos).trim().split(" ");
if (dimensions.length > 0) {
arrayFirstDim = Integer.valueOf(dimensions[0].trim());
}
if (dimensions.length > 1) {
arraySecondDim = Integer.valueOf(dimensions[1].trim());
}
pos = nextPos + 1;
while (line.charAt(pos) != '[') {
pos++;
}
}
int pos2 = pos;
while ((pos2 < line.length()) && (line.charAt(pos2) != ']')) {
pos2++;
}
String values = line.substring(pos + 1, pos2);
ArrayList<String> elements = new ArrayList<>();
for (String val : values.split(",")) {
elements.add(val.trim());
}
System.out.println(name);
{ // bool to int
for (int i = 0; i < elements.size(); i++) {
if (elements.get(i).equals("true")) {
elements.set(i, "1");
}
if (elements.get(i).equals("false")) {
elements.set(i, "0");
}
}
}
ArrayList<ArrayList<String>> array = MZnResultsResolver.parse2dArray(pos, line, task);
if (array != null) {
int maxSize = 0;
int maxLength = 0;
for (String val : elements) {
maxLength = Math.max(maxLength, val.length());
for (ArrayList<String> a : array) {
for (int j = 0; j < a.size(); j++) {
if (a.get(j).equals("true")) {
a.set(j, "1");
}
if ((arrayFirstDim != 0) && (elements.size() % arrayFirstDim == 0) && ((arraySecondDim == 0) || (elements.size() % (arrayFirstDim * arraySecondDim) != 0))) {
writer.write(name + " :\n");
for (int i = 0; i < elements.size(); i += arrayFirstDim) {
writer.write(" ");
for (int j = 0; j < arrayFirstDim; j++) {
String val = elements.get(i + j);
for (int k = val.length(); k < maxLength; k++) {
writer.write(" ");
if (a.get(j).equals("false")) {
a.set(j, "0");
}
writer.write(val + " ");
maxSize = Math.max(maxSize, a.get(j).length());
}
writer.write("\n");
}
writer.write("\n");
} else if ((arrayFirstDim != 0) && (arraySecondDim != 0) && (elements.size() % (arrayFirstDim * arraySecondDim) == 0)) {
writer.write(name + " :\n");
for (int i = 0; i < elements.size(); i += arrayFirstDim * arraySecondDim) {
for (int j = 0; j < arrayFirstDim; j++) {
writer.write(" ");
for (int k = 0; k < arraySecondDim; k++) {
String val = elements.get(i + j * arraySecondDim + k);
for (int l = val.length(); l < maxLength; l++) {
for (ArrayList<String> a : array) {
writer.write(" ");
}
writer.write(val + " ");
}
writer.write("\n");
for (String val : a) {
writer.write(new String(new char[maxSize - val.length()]).replace("\0", " ")
+ val + " ");
}
writer.write("\n");
}
writer.write("\n");
}
}
writer.close();
} catch (IOException e) {
System.out.println(e.getMessage());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment