Commit 659aa53d authored by Vladislav Kiselev's avatar Vladislav Kiselev

current_moving_operation теперь означает реальный номер операции.

parent 1b43d12e
......@@ -9,31 +9,27 @@ array [1..n_operations, 0..(n_intervals + 1)] of var bool : op_status;
array [1..n_operations, 0..(n_intervals + 1)] of var bool : op_start;
array [1..n_operations, 0..(n_intervals + 1)] of var bool : op_fin;
int : moving_op_of_obj_max_size;
array [1..n_moving_obj] of 0..moving_op_of_obj_max_size : moving_op_of_obj_sizes;
array [1..n_moving_obj, 0..moving_op_of_obj_max_size] of 1..n_operations : moving_op_of_obj; % Операции перемещения затрагивающие данный объект.
array [1..n_moving_obj, 1..n_operations] of bool : moving_op_of_obj;
% Определение current_moving_operation.
% Текущая операция операция перемещения, в которой задействован данный объект.
array [1..n_moving_obj, 0..(n_intervals + 1)] of var 0..moving_op_of_obj_max_size : current_moving_operation;
array [1..n_moving_obj, 0..(n_intervals + 1)] of var 0..n_operations : current_moving_operation;
% Текущая операция лежит в множестве тех, которые затрагивают данный объект.
constraint forall (obj in 1..n_moving_obj, t in 0..(n_intervals + 1)) (
current_moving_operation[obj, t] <= moving_op_of_obj_sizes[obj]
(current_moving_operation[obj, t] != 0) -> moving_op_of_obj[obj, current_moving_operation[obj, t]]
);
% Если операция, затрагивающая данный объект в качестве главного, выполняется - то именно она текущая операция перемещения для этого объекта.
constraint forall (op in 1..n_operations, t in 0..(n_intervals + 1), obj = main_obj_of_operation[op]
where is_moving_operation[op]) (
op_status[op, t] -> ((current_moving_operation[obj, t] != 0) /\
(moving_op_of_obj[obj, current_moving_operation[obj, t]] = op))
op_status[op, t] -> (current_moving_operation[obj, t] = op)
);
% TODO упростить в conversion_1
% Связь current_moving_operation c op_status.
constraint forall (obj in 1..n_moving_obj,
t in 0..(n_intervals + 1)) (
(current_moving_operation[obj, t] != 0)
-> (op_status[moving_op_of_obj[obj, current_moving_operation[obj, t]], t])
(current_moving_operation[obj, t] != 0) -> (op_status[current_moving_operation[obj, t], t])
);
% Ограничение на количество пришвартованных кораблей.
......@@ -90,18 +86,18 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
constraint forall (obj in 1..n_moving_obj, t in 2..(n_intervals + 1)) (
((current_moving_operation[obj, t - 1] != current_moving_operation[obj, t - 2]) /\
(current_moving_operation[obj, t - 1] != 0) /\
((obj = main_obj_of_operation[moving_op_of_obj[obj, current_moving_operation[obj, t - 1]]])
((obj = main_obj_of_operation[current_moving_operation[obj, t - 1]])
\/
(not is_mooring_op[moving_op_of_obj[obj, current_moving_operation[obj, t - 1]]])
(not is_mooring_op[current_moving_operation[obj, t - 1]])
)
) -> (m_obj_loc[obj, t] = operations_destination[moving_op_of_obj[obj, current_moving_operation[obj, t - 1]]])
) -> (m_obj_loc[obj, t] = operations_destination[current_moving_operation[obj, t - 1]])
);
constraint forall (obj in 1..n_moving_obj, t in 2..(n_intervals + 1)) (
((current_moving_operation[obj, t - 1] != current_moving_operation[obj, t - 2]) /\
(current_moving_operation[obj, t - 1] != 0) /\
((obj != main_obj_of_operation[moving_op_of_obj[obj, current_moving_operation[obj, t - 1]]])
((obj != main_obj_of_operation[current_moving_operation[obj, t - 1]])
/\
( is_mooring_op[moving_op_of_obj[obj, current_moving_operation[obj, t - 1]]])
( is_mooring_op[current_moving_operation[obj, t - 1]])
)
) -> (m_obj_loc[obj, t] = m_obj_loc[obj, t - 1])
);
......@@ -156,9 +152,9 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
% { Если объект движется, и движется как ресурс, то participation_as_resource должен отображать этот факт. }
constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) (
(current_moving_operation[obj, t] != 0) -> (
(moving_op_of_obj[obj, current_moving_operation[obj, t]] in operations_that_used_obj_as_resource[obj])
(current_moving_operation[obj, t] in operations_that_used_obj_as_resource[obj])
->
(participation_as_resource[obj, t] = moving_op_of_obj[obj, current_moving_operation[obj, t]])
(participation_as_resource[obj, t] = current_moving_operation[obj, t])
)
);
......@@ -168,7 +164,7 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
(is_moving_operation[participation_as_resource[obj, t]]) -> (
(current_moving_operation[obj, t] != 0)
/\
(participation_as_resource[obj, t] = moving_op_of_obj[obj, current_moving_operation[obj, t]])
(participation_as_resource[obj, t] = current_moving_operation[obj, t])
)
)
);
......@@ -350,7 +346,7 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) (
is_obj_involved_in_cargo_op[obj, t] = (
((participation_as_resource[obj, t] != 0) /\ (current_moving_operation[obj, t] = 1)) % В качестве ресурса.
((participation_as_resource[obj, t] != 0) /\ (current_moving_operation[obj, t] = 0)) % В качестве ресурса.
\/
exists (op in 1..n_operations where main_obj_of_operation[op] = obj) ( % В качестве главного объекта.
op_status[op, t]
......@@ -420,7 +416,6 @@ output [show(sum(is_not_terminated)), "\n",
"participation_as_resource = ", show(participation_as_resource), "\n\n",
"real_current_moving_operation = ", show(current_moving_operation), "\n\n",
"moving_op_of_obj {", show(moving_op_of_obj_max_size + 1), "}= ", show(moving_op_of_obj), "\n\n",
/*
"is_op_possible {", show(n_intervals), "} = ", show(is_op_possible), "\n\n",
"debug_1 {", show(n_intervals), "} = ", show(debug_1), "\n\n",
......
......@@ -197,6 +197,10 @@ public class ConversionUtil {
return res.toString();
}
static private <T> String arrayToStringAsSet(ArrayList<T> a) {
return setToString(new TreeSet<>(a));
}
static private ArrayList<Integer> integerArray(int size, int initVal) {
ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < size; i++) {
......@@ -331,10 +335,6 @@ public class ConversionUtil {
private ArrayList<Integer> mainObjOfOperation;
private ArrayList<Boolean> isMooringOp;
public ArrayList<ArrayList<Integer>> getMovingOpOfObj() {
return movingOpOfObj;
}
private ArrayList<Set<Integer>> objectsOfType;
Task(TaskCase task, String fileName) {
......@@ -879,7 +879,19 @@ public class ConversionUtil {
if (! isV1) {
writeArray(writer, "is_mooring_op", isMooringOp);
writeArray(writer, "main_obj_of_operation", mainObjOfOperation, (Integer val) -> val + 1);
writeArrayOfSetAs2DArray(writer, "moving_op_of_obj", movingOpOfObj, true, true);
ArrayList<ArrayList<Boolean>> locMovingOpOfObj = new ArrayList<>();
for (ArrayList<Integer> operations : movingOpOfObj) {
ArrayList<Boolean> lOperations = new ArrayList<>();
for (int i = 0; i < operationTemplates.size(); i++) {
lOperations.add(false);
}
for (Integer op : operations) {
lOperations.set(op - 1, true);
}
locMovingOpOfObj.add(lOperations);
}
locWrite2DArray(writer, "moving_op_of_obj", locMovingOpOfObj, Objects::toString);
} else {
writeArrayOfSetAs2DArray(writer, "moving_op_of_obj", movingOpOfObj, true, false);
}
......
......@@ -116,7 +116,6 @@ public class Main {
}
case "testing" :
test_2();
test_1();
break;
case "testing_2":
test_2_0();
......@@ -218,19 +217,6 @@ public class Main {
elements.add(val.trim());
}
if (name.equals("current_moving_operation")) {
ArrayList<ArrayList<Integer>> movingOpOfObj = t.getMovingOpOfObj();
for (int i = 0; i < elements.size(); i += arrayFirstDim) {
for (int j = 0; j < arrayFirstDim; j++) {
int val = Integer.valueOf(elements.get(i + j));
if (val != 0) {
elements.set(i + j, Integer.toString(movingOpOfObj.get(i / arrayFirstDim).get(val - 1)));
}
}
}
name = name + " *";
}
{ // bool to int
for (int i = 0; i < elements.size(); i++) {
if (elements.get(i).equals("true")) {
......
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