Commit 472f041f authored by Vladislav Kiselev's avatar Vladislav Kiselev

Упрощение constraint-ов, вырезан op_fin.

parent 31e84e09
...@@ -7,7 +7,6 @@ int : n_moving_obj; ...@@ -7,7 +7,6 @@ int : n_moving_obj;
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_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_start;
array [1..n_operations, 0..(n_intervals + 1)] of var bool : op_fin;
array [1..n_moving_obj, 1..n_operations] of bool : moving_op_of_obj; array [1..n_moving_obj, 1..n_operations] of bool : moving_op_of_obj;
...@@ -16,19 +15,15 @@ array [1..n_moving_obj, 1..n_operations] of bool : moving_op_of_obj; ...@@ -16,19 +15,15 @@ array [1..n_moving_obj, 1..n_operations] of bool : moving_op_of_obj;
array [1..n_moving_obj, 0..(n_intervals + 1)] of var 0..n_operations : 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)) ( 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]] (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] constraint forall (op in 1..n_operations, t in 1..n_intervals where is_moving_operation[op]) (
where is_moving_operation[op]) ( op_status[op, t] -> (current_moving_operation[main_obj_of_operation[op], t] = op)
op_status[op, t] -> (current_moving_operation[obj, t] = op)
); );
% TODO упростить в conversion_1
% Связь current_moving_operation c op_status. % Связь current_moving_operation c op_status.
constraint forall (obj in 1..n_moving_obj, constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) (
t in 0..(n_intervals + 1)) (
(current_moving_operation[obj, t] != 0) -> (op_status[current_moving_operation[obj, t], t]) (current_moving_operation[obj, t] != 0) -> (op_status[current_moving_operation[obj, t], t])
); );
...@@ -72,17 +67,17 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац ...@@ -72,17 +67,17 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
array [1..n_moving_obj, 0..(n_intervals + 1)] of var 1..n_locations : m_obj_loc; array [1..n_moving_obj, 0..(n_intervals + 1)] of var 1..n_locations : m_obj_loc;
% Главный объект (субъект) операции. % Главный объект (субъект) операции.
array [1..n_operations] of 1..n_moving_obj : main_obj_of_operation; array [0..n_operations] of 1..n_moving_obj : main_obj_of_operation;
% Является ли операция швартовкой/отшвартовкой. % Является ли операция швартовкой/отшвартовкой.
array [1..n_operations] of bool : is_mooring_op; array [0..n_operations] of bool : is_mooring_op;
% За фиктивный нулевой интервал объект не успевает ничего сделать с начальным положением. % За фиктивный нулевой интервал объект не успевает ничего сделать с начальным положением.
constraint forall (obj in 1..n_moving_obj) ( constraint forall (obj in 1..n_moving_obj) (
m_obj_loc[obj, 1] = m_obj_loc[obj, 0] m_obj_loc[obj, 1] = m_obj_loc[obj, 0]
); );
% TODO исправить в conversion_1.mzn
% Направление движения/местоположение объекта может измениться только если перед этим началась операция перемещения. % Направление движения/местоположение объекта может измениться только если перед этим началась операция перемещения, и он не вспомогательный при операции швартовки.
constraint forall (obj in 1..n_moving_obj, t in 2..(n_intervals + 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] != current_moving_operation[obj, t - 2]) /\
(current_moving_operation[obj, t - 1] != 0) /\ (current_moving_operation[obj, t - 1] != 0) /\
...@@ -93,19 +88,14 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац ...@@ -93,19 +88,14 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
) -> (m_obj_loc[obj, t] = operations_destination[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)) ( 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] = current_moving_operation[obj, t - 2]) \/
(current_moving_operation[obj, t - 1] != 0) /\ (current_moving_operation[obj, t - 1] = 0) \/
((obj != main_obj_of_operation[current_moving_operation[obj, t - 1]]) ((obj != main_obj_of_operation[current_moving_operation[obj, t - 1]])
/\ /\
( is_mooring_op[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]) ) -> (m_obj_loc[obj, t] = m_obj_loc[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)
) -> (m_obj_loc[obj, t] = m_obj_loc[obj, t - 1])
);
% Начальное состояние. % Начальное состояние.
array [1..n_moving_obj] of 0..n_locations : initial_m_obj_loc; array [1..n_moving_obj] of 0..n_locations : initial_m_obj_loc;
...@@ -118,13 +108,11 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац ...@@ -118,13 +108,11 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
(m_obj_loc[i, n_intervals + 1] = final_m_obj_loc[i]) (m_obj_loc[i, n_intervals + 1] = final_m_obj_loc[i])
); );
% Определение op_status, op_start и op_fin. % Определение op_status, op_start.
constraint forall (i in 1..n_operations, j in {0, n_intervals + 1}) (op_status[i, j] == 0); % Краевые значения. constraint forall (i in 1..n_operations, j in {0, n_intervals + 1}) (op_status[i, j] == 0); % Краевые значения.
constraint forall (op in 1..n_operations, j in {0, n_intervals + 1}) constraint forall (op in 1..n_operations, j in {0, n_intervals + 1}) (op_start[op, j] = false);
(op_start[op, j] = false /\ op_fin[op, j] = false);
constraint forall (i in 1..n_operations, j in 1..(n_intervals + 1)) (op_start[i, j] = (op_status[i, j] /\ not op_status[i, j - 1])); constraint forall (i in 1..n_operations, j in 1..(n_intervals + 1)) (op_start[i, j] = (op_status[i, j] /\ not op_status[i, j - 1]));
constraint forall (i in 1..n_operations, j in 1..n_intervals ) (op_fin [i, j] = (op_status[i, j] /\ not op_status[i, j + 1]));
% Связь ресурсов с операцией и основным объектом. % Связь ресурсов с операцией и основным объектом.
% Операции, которые могут задействовать данный объект как ресурс. % Операции, которые могут задействовать данный объект как ресурс.
...@@ -401,7 +389,6 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац ...@@ -401,7 +389,6 @@ array [1..n_operations] of 1..n_locations : operations_destination; % Локац
output [show(sum(is_not_terminated)), "\n", output [show(sum(is_not_terminated)), "\n",
"op_status = ", show(op_status), "\n\n", "op_status = ", show(op_status), "\n\n",
"m_obj_loc = ", show(m_obj_loc), "\n\n", "m_obj_loc = ", show(m_obj_loc), "\n\n",
"op_fin = ", show(op_fin), "\n\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",
......
...@@ -166,19 +166,44 @@ public class ConversionUtil { ...@@ -166,19 +166,44 @@ public class ConversionUtil {
writer.write(" |];\n"); writer.write(" |];\n");
} }
static private <T, E> void writeArray(FileWriter writer, String name, ArrayList<T> data, Function<T, E> f) throws IOException { static private <T, E> void writeArray(FileWriter writer,
writer.write(name + " = ["); String name,
ArrayList<T> data,
Function<T, E> f,
Optional<T> dummyZeroElement) throws IOException {
writer.write(name + " = array1d(" + (dummyZeroElement.isPresent() ? 0 : 1) + ".." + data.size() + ", [");
boolean isFirst = true;
if (dummyZeroElement.isPresent()) {
isFirst = false;
writer.write(f.apply(dummyZeroElement.get()).toString());
}
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
if (i != 0) { if (isFirst) {
isFirst = false;
} else {
writer.write(", "); writer.write(", ");
} }
writer.write(f.apply(data.get(i)).toString() + ""); writer.write(f.apply(data.get(i)).toString());
} }
writer.write("];\n"); writer.write("]);\n");
} }
static private <T> void writeArray(FileWriter writer, String name, ArrayList<T> data) throws IOException { static private <T> void writeArray(FileWriter writer, String name, ArrayList<T> data) throws IOException {
writeArray(writer, name, data, (T val) -> val); writeArray(writer, name, data, (T val) -> val, Optional.empty());
}
static private <T, E> void writeArray(FileWriter writer,
String name,
ArrayList<T> data,
Function<T, E> f) throws IOException {
writeArray(writer, name, data, f, Optional.empty());
}
static private <T, E> void writeArray(FileWriter writer,
String name,
ArrayList<T> data,
Optional<T> dummyZeroElement) throws IOException {
writeArray(writer, name, data, (T val) -> val, dummyZeroElement);
} }
static private <T> String setToString(Set<T> s) { static private <T> String setToString(Set<T> s) {
...@@ -877,8 +902,8 @@ public class ConversionUtil { ...@@ -877,8 +902,8 @@ public class ConversionUtil {
private void movingObjectLocationDefinition(boolean isV1) throws IOException { private void movingObjectLocationDefinition(boolean isV1) throws IOException {
if (! isV1) { if (! isV1) {
writeArray(writer, "is_mooring_op", isMooringOp); writeArray(writer, "is_mooring_op", isMooringOp, Optional.of(false));
writeArray(writer, "main_obj_of_operation", mainObjOfOperation, (Integer val) -> val + 1); writeArray(writer, "main_obj_of_operation", mainObjOfOperation, (Integer val) -> val + 1, Optional.of(1));
ArrayList<ArrayList<Boolean>> locMovingOpOfObj = new ArrayList<>(); ArrayList<ArrayList<Boolean>> locMovingOpOfObj = new ArrayList<>();
for (ArrayList<Integer> operations : movingOpOfObj) { for (ArrayList<Integer> operations : movingOpOfObj) {
......
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