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

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

parent 9e4d4fde
......@@ -1242,7 +1242,7 @@ public class Task {
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>> max_negative_cargo_val = arrayOfIntegerArrays(sectionNById.size());
ArrayList<ArrayList<Boolean>> can_obj_leave_loc_only_alone = new ArrayList<>();
......@@ -1274,10 +1274,19 @@ public class Task {
sections.add(new Pair<>(sectionIdToN(op.getStorage(), op.getCargo()), -val));
}
for (Pair<Integer, Integer> p : sections) {
if (p.getValue() > 0) {
min_positive_cargo_val.get(p.getKey()).set(loc, Math.min(p.getValue(), min_positive_cargo_val.get(p.getKey()).get(loc)));
Integer value = p.getValue();
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 {
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) {
......@@ -1290,16 +1299,22 @@ public class Task {
}
}
write2DArrayOfInt(writer, "min_positive_cargo_val", min_positive_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);
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()) {
throw new ParserException("Attempt to convert untyped task as typified.");
}
......@@ -1336,7 +1351,7 @@ public class Task {
boundaryStorageStates();
cargoFlows();
cargoOperations();
dataForOptimization3();
dataForOptimization3(isInseparable);
fixedOperations();
} catch (IOException e) {
......@@ -1512,7 +1527,7 @@ public class Task {
throw new ParserException("Attempt to convert untyped task as typified.");
}
try {
portToMiniZinc_2();
portToMiniZinc_2(false);
dataForGreediness();
} catch (IOException e) {
throw new UncheckedIOException(e);
......@@ -1539,7 +1554,10 @@ public class Task {
startConversion(task, fileName, Task::portToMiniZinc_1);
}
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) {
startConversion(task, fileName, Task::portToMiniZinc_2_greedy);
......
......@@ -20,7 +20,7 @@ public class Testing {
public static Solver getTaskWithPartialCargoOp_Solver() {
return new Solver("conversion_2_with_partial_cargo_operations.mzn",
Task::portToMiniZinc_2,
Task::portToMiniZinc_2_separable,
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