Commit 62bd0d72 authored by Vladislav Kiselev's avatar Vladislav Kiselev

few bugs fixed

parent 57cda042
...@@ -41,7 +41,7 @@ array [1..n_moving_obj, 0..(n_intervals + 1)] of var bool : is_m_obj_in_movement ...@@ -41,7 +41,7 @@ array [1..n_moving_obj, 0..(n_intervals + 1)] of var bool : is_m_obj_in_movement
if (current_moving_operation[obj, t - 1] = 0) then if (current_moving_operation[obj, t - 1] = 0) then
is_m_obj_in_movement_before_start[obj, t] = false is_m_obj_in_movement_before_start[obj, t] = false
else else
is_m_obj_in_movement_before_start[obj, t] = (current_moving_operation[obj, t - 1] != current_moving_operation[obj, t]) is_m_obj_in_movement_before_start[obj, t] = (current_moving_operation[obj, t - 1] == current_moving_operation[obj, t])
endif endif
); );
...@@ -285,6 +285,8 @@ output [show(sum(is_not_terminated)), "\n", ...@@ -285,6 +285,8 @@ output [show(sum(is_not_terminated)), "\n",
"op_start = ", show(op_start), "\n\n", "op_start = ", show(op_start), "\n\n",
"is_not_terminated = ", show(is_not_terminated), "\n\n", "is_not_terminated = ", show(is_not_terminated), "\n\n",
"storage_used_volume = ", show(storage_used_volume), "\n\n", "storage_used_volume = ", show(storage_used_volume), "\n\n",
"is_m_obj_in_movement_before_start = ", show(is_m_obj_in_movement_before_start), "\n\n",
"current_moving_operation = ", show(current_moving_operation), "\n\n"
% "prev_m_obj_loc = ", show(prev_m_obj_loc), "\n\n", % "prev_m_obj_loc = ", show(prev_m_obj_loc), "\n\n",
% "next_m_obj_loc = ", show(next_m_obj_loc), "\n\n", % "next_m_obj_loc = ", show(next_m_obj_loc), "\n\n",
% "is_interval_useful = ", show(is_interval_useful), "\n\n" % "is_interval_useful = ", show(is_interval_useful), "\n\n"
......
...@@ -201,8 +201,8 @@ public class ConversionUtil { ...@@ -201,8 +201,8 @@ public class ConversionUtil {
return null; return null;
} }
static private List<Object> getResources(OperationTemplate t) { static private List<MovingObject> getResources(OperationTemplate t) {
List<Object> res = new ArrayList<>(); List<MovingObject> res = new ArrayList<>();
if (t instanceof LoadingTemplate) { if (t instanceof LoadingTemplate) {
res.addAll(((LoadingTemplate) t).getResources()); res.addAll(((LoadingTemplate) t).getResources());
} }
...@@ -218,11 +218,11 @@ public class ConversionUtil { ...@@ -218,11 +218,11 @@ public class ConversionUtil {
static private boolean isCompatible(OperationTemplate t1, OperationTemplate t2) { static private boolean isCompatible(OperationTemplate t1, OperationTemplate t2) {
MovingObject exec1 = getExecutor(t1); MovingObject exec1 = getExecutor(t1);
Berth place1 = t1.getStartLocation(); Berth place1 = t1.getStartLocation();
List<Object> resources1 = getResources(t1); List<MovingObject> resources1 = getResources(t1);
MovingObject exec2 = getExecutor(t2); MovingObject exec2 = getExecutor(t2);
Berth place2 = t2.getStartLocation(); Berth place2 = t2.getStartLocation();
List<Object> resources2 = getResources(t2); List<MovingObject> resources2 = getResources(t2);
// Пересекаемость ресурсов // Пересекаемость ресурсов
for (Object res2 : resources2) for (Object res2 : resources2)
if (resources1.contains(res2)) if (resources1.contains(res2))
...@@ -643,6 +643,8 @@ public class ConversionUtil { ...@@ -643,6 +643,8 @@ public class ConversionUtil {
BiConsumer<MovingObject, Integer> addUsOp = (MovingObject obj, Integer op) -> BiConsumer<MovingObject, Integer> addUsOp = (MovingObject obj, Integer op) ->
objUsefulOperations.get(mObjToN.apply(obj)).add(op + 1); objUsefulOperations.get(mObjToN.apply(obj)).add(op + 1);
BiConsumer<MovingObject, Integer> addMovingOp = (MovingObject obj, Integer op) ->
movingOpOfObj.get(mObjToN.apply(obj)).add(op + 1);
for (int i = 0; i < movingObjects.size(); i++) { for (int i = 0; i < movingObjects.size(); i++) {
movingOpOfObj.add(new TreeSet<>()); movingOpOfObj.add(new TreeSet<>());
...@@ -654,20 +656,20 @@ public class ConversionUtil { ...@@ -654,20 +656,20 @@ public class ConversionUtil {
if (t instanceof MovingTemplate) { if (t instanceof MovingTemplate) {
MovingTemplate op = (MovingTemplate)t; MovingTemplate op = (MovingTemplate)t;
int id = mObjToN.apply(op.getMover()); addMovingOp.accept(op.getMover(), i);
movingOpOfObj.get(id).add(i + 1);
for (MovingObject obj : op.getResources()) { for (MovingObject obj : op.getResources()) {
addUsOp.accept(obj, i); addUsOp.accept(obj, i);
addMovingOp.accept(obj, i);
} }
} else if (t instanceof MooringTemplate) { } else if (t instanceof MooringTemplate) {
MooringTemplate op = (MooringTemplate)t; MooringTemplate op = (MooringTemplate)t;
int id = mObjToN.apply(op.getMoorer()); addMovingOp.accept(op.getMoorer(), i);
movingOpOfObj.get(id).add(i + 1);
for (MovingObject obj : op.getResources()) { for (MovingObject obj : op.getResources()) {
addUsOp.accept(obj, i); addUsOp.accept(obj, i);
addMovingOp.accept(obj, i);
} }
if (!op.isDirect()) { // Отшвартовка. if (!op.isDirect()) { // Отшвартовка.
...@@ -730,12 +732,17 @@ public class ConversionUtil { ...@@ -730,12 +732,17 @@ public class ConversionUtil {
movingOpOfObj.add(new TreeSet<>()); movingOpOfObj.add(new TreeSet<>());
} }
BiConsumer<MovingObject, Integer> addMovingOp = (MovingObject obj, Integer op) ->
movingOpOfObj.get(mObjToN.apply(obj)).add(op + 1);
for (int i = 0; i < operationTemplates.size(); i++) { for (int i = 0; i < operationTemplates.size(); i++) {
OperationTemplate t = operationTemplates.get(i); OperationTemplate t = operationTemplates.get(i);
if ((t instanceof MovingTemplate) || (t instanceof MooringTemplate)) { if ((t instanceof MovingTemplate) || (t instanceof MooringTemplate)) {
int id = mObjToN.apply(getExecutor(t)); addMovingOp.accept(getExecutor(t), i);
movingOpOfObj.get(id).add(i + 1); for (MovingObject obj : getResources(t)) {
addMovingOp.accept(obj, i);
}
} }
if (t instanceof MovingTemplate) { if (t instanceof MovingTemplate) {
MovingTemplate op = (MovingTemplate)t; MovingTemplate op = (MovingTemplate)t;
...@@ -835,8 +842,14 @@ public class ConversionUtil { ...@@ -835,8 +842,14 @@ public class ConversionUtil {
taskData.portToMiniZinc_1(); taskData.portToMiniZinc_1();
} }
private static class OperationsComparator implements Comparator<Operation> {
public int compare(Operation op1, Operation op2) {
return Double.compare(op1.getStart(), op2.getStart());
}
}
static public void resolveMiniZincResults(TaskCase task, String fileName) throws IOException, ParserException { static public void resolveMiniZincResults(TaskCase task, String fileName) throws IOException, ParserException {
List<Operation> operations = null; ArrayList<Operation> operations = null;
Integer result = null; Integer result = null;
try (FileInputStream fstream = new FileInputStream(fileName)) { try (FileInputStream fstream = new FileInputStream(fileName)) {
...@@ -906,6 +919,7 @@ public class ConversionUtil { ...@@ -906,6 +919,7 @@ public class ConversionUtil {
if (result == null) { if (result == null) {
throw new ParserException("No result in input"); throw new ParserException("No result in input");
} }
operations.sort(new OperationsComparator());
task.setSolution(operations); task.setSolution(operations);
task.setSolution_result(result); task.setSolution_result(result);
} }
......
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