Commit 92827ce4 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Устранена ошибка с оптимизацией 3.

parent 9e4d4fde
...@@ -1242,7 +1242,7 @@ public class Task { ...@@ -1242,7 +1242,7 @@ public class Task {
writeArray(writer, "bunker_start_loc", bunkerStartLoc, (Integer val) -> val + 1, Optional.of(-1)); writeArray(writer, "bunker_start_loc", bunkerStartLoc, (Integer val) -> val + 1, Optional.of(-1));
} }
void dataForOptimization3() throws IOException { void dataForOptimization3(boolean isInseparable) throws IOException {
ArrayList<ArrayList<Integer>> min_positive_cargo_val = arrayOfIntegerArrays(sectionNById.size()); ArrayList<ArrayList<Integer>> min_positive_cargo_val = arrayOfIntegerArrays(sectionNById.size());
ArrayList<ArrayList<Integer>> max_negative_cargo_val = arrayOfIntegerArrays(sectionNById.size()); ArrayList<ArrayList<Integer>> max_negative_cargo_val = arrayOfIntegerArrays(sectionNById.size());
ArrayList<ArrayList<Boolean>> can_obj_leave_loc_only_alone = new ArrayList<>(); ArrayList<ArrayList<Boolean>> can_obj_leave_loc_only_alone = new ArrayList<>();
...@@ -1274,10 +1274,19 @@ public class Task { ...@@ -1274,10 +1274,19 @@ public class Task {
sections.add(new Pair<>(sectionIdToN(op.getStorage(), op.getCargo()), -val)); sections.add(new Pair<>(sectionIdToN(op.getStorage(), op.getCargo()), -val));
} }
for (Pair<Integer, Integer> p : sections) { for (Pair<Integer, Integer> p : sections) {
if (p.getValue() > 0) { Integer value = p.getValue();
min_positive_cargo_val.get(p.getKey()).set(loc, Math.min(p.getValue(), min_positive_cargo_val.get(p.getKey()).get(loc))); if (! isInseparable) {
if (value < 0) {
value = -1;
}
if (value > 0) {
value = 1;
}
}
if (value > 0) {
min_positive_cargo_val.get(p.getKey()).set(loc, Math.min(value, min_positive_cargo_val.get(p.getKey()).get(loc)));
} else { } else {
max_negative_cargo_val.get(p.getKey()).set(loc, Math.max(p.getValue(), max_negative_cargo_val.get(p.getKey()).get(loc))); max_negative_cargo_val.get(p.getKey()).set(loc, Math.max(value, max_negative_cargo_val.get(p.getKey()).get(loc)));
} }
} }
} else if (t instanceof MovingTemplate) { } else if (t instanceof MovingTemplate) {
...@@ -1290,16 +1299,22 @@ public class Task { ...@@ -1290,16 +1299,22 @@ public class Task {
} }
} }
write2DArrayOfInt(writer, "min_positive_cargo_val", min_positive_cargo_val, false); write2DArrayOfInt(writer, "min_positive_cargo_val", min_positive_cargo_val, false);
write2DArrayOfInt(writer, "max_negative_cargo_val", max_negative_cargo_val, false); write2DArrayOfInt(writer, "max_negative_cargo_val", max_negative_cargo_val, false);
locWrite2DArray(writer, "can_obj_leave_loc_only_alone", can_obj_leave_loc_only_alone, Objects::toString); locWrite2DArray(writer, "can_obj_leave_loc_only_alone", can_obj_leave_loc_only_alone, Objects::toString);
writer.write("\n"); writer.write("\n");
} }
void portToMiniZinc_2_sep() {
portToMiniZinc_2(false);
}
void portToMiniZinc_2_inSep() {
portToMiniZinc_2(true);
}
/* С типизацией. */ /* С типизацией. */
void portToMiniZinc_2() { private void portToMiniZinc_2(boolean isInseparable) {
if (!task.isTypified()) { if (!task.isTypified()) {
throw new ParserException("Attempt to convert untyped task as typified."); throw new ParserException("Attempt to convert untyped task as typified.");
} }
...@@ -1336,7 +1351,7 @@ public class Task { ...@@ -1336,7 +1351,7 @@ public class Task {
boundaryStorageStates(); boundaryStorageStates();
cargoFlows(); cargoFlows();
cargoOperations(); cargoOperations();
dataForOptimization3(); dataForOptimization3(isInseparable);
fixedOperations(); fixedOperations();
} catch (IOException e) { } catch (IOException e) {
...@@ -1512,7 +1527,7 @@ public class Task { ...@@ -1512,7 +1527,7 @@ public class Task {
throw new ParserException("Attempt to convert untyped task as typified."); throw new ParserException("Attempt to convert untyped task as typified.");
} }
try { try {
portToMiniZinc_2(); portToMiniZinc_2(false);
dataForGreediness(); dataForGreediness();
} catch (IOException e) { } catch (IOException e) {
throw new UncheckedIOException(e); throw new UncheckedIOException(e);
...@@ -1539,7 +1554,10 @@ public class Task { ...@@ -1539,7 +1554,10 @@ public class Task {
startConversion(task, fileName, Task::portToMiniZinc_1); startConversion(task, fileName, Task::portToMiniZinc_1);
} }
static public void portToMiniZinc_2(TaskCase task, String fileName) { static public void portToMiniZinc_2(TaskCase task, String fileName) {
startConversion(task, fileName, Task::portToMiniZinc_2); startConversion(task, fileName, Task::portToMiniZinc_2_inSep);
}
static public void portToMiniZinc_2_separable(TaskCase task, String fileName) {
startConversion(task, fileName, Task::portToMiniZinc_2_sep);
} }
static public void portToMiniZincGreedy(TaskCase task, String fileName) { static public void portToMiniZincGreedy(TaskCase task, String fileName) {
startConversion(task, fileName, Task::portToMiniZinc_2_greedy); startConversion(task, fileName, Task::portToMiniZinc_2_greedy);
......
...@@ -20,7 +20,7 @@ public class Testing { ...@@ -20,7 +20,7 @@ public class Testing {
public static Solver getTaskWithPartialCargoOp_Solver() { public static Solver getTaskWithPartialCargoOp_Solver() {
return new Solver("conversion_2_with_partial_cargo_operations.mzn", return new Solver("conversion_2_with_partial_cargo_operations.mzn",
Task::portToMiniZinc_2, Task::portToMiniZinc_2_separable,
MZnResultsResolver::resolveMiniZincResults); MZnResultsResolver::resolveMiniZincResults);
} }
......
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