From 9e9a0615d81ae08fc9c0c0b6d473659c3c6d1a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=81=D0=B5=D0=BB=D1=91=D0=B2=20=D0=92=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2?= Date: Mon, 19 Nov 2018 15:01:35 +0300 Subject: [PATCH] cleanup and new tests --- .gitignore | 5 + experiment/run.bat | 8 + test/conversion_0.dzn | 20 -- test/conversion_0.mzn | 186 ------------------ test/in_1.ipp | 63 ------ test/run.bat | 8 - tests/cargo_handling_and_moving.ipp | 51 +++++ .../shortest_path_with_weather.ipp | 0 tests/simple_cargo_flow.ipp | 37 ++++ {test => tests}/simple_shortest_path.ipp | 0 10 files changed, 101 insertions(+), 277 deletions(-) create mode 100644 experiment/run.bat delete mode 100644 test/conversion_0.dzn delete mode 100644 test/conversion_0.mzn delete mode 100644 test/in_1.ipp delete mode 100644 test/run.bat create mode 100644 tests/cargo_handling_and_moving.ipp rename {test => tests}/shortest_path_with_weather.ipp (100%) create mode 100644 tests/simple_cargo_flow.ipp rename {test => tests}/simple_shortest_path.ipp (100%) diff --git a/.gitignore b/.gitignore index b3b9ebf..fc20335 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ Conversion.iml .idea/dictionaries/Vlad_kv.xml test/result.txt test/out_1.mzn +test/raw_result.txt +experiment/raw_result.txt +experiment/result.txt +experiment/in.ipp +experiment/conversion_0.dzn diff --git a/experiment/run.bat b/experiment/run.bat new file mode 100644 index 0000000..4178246 --- /dev/null +++ b/experiment/run.bat @@ -0,0 +1,8 @@ +del raw_result.txt +del result.txt + +java -classpath "../out/production/Conversion" inport.Main to_MiniZinc in.ipp conversion_0.dzn + +minizinc --solver Gecode "../constraints/conversion_0.mzn" conversion_0.dzn >> raw_result.txt + +java -classpath "../out/production/Conversion" inport.Main resolve_result in.ipp raw_result.txt result.txt diff --git a/test/conversion_0.dzn b/test/conversion_0.dzn deleted file mode 100644 index 6942c13..0000000 --- a/test/conversion_0.dzn +++ /dev/null @@ -1,20 +0,0 @@ -n_intervals = 24; -n_operations = 16; -n_locations = 6; -n_moving_obj = 2; - -arrival_op = - [| {2, 4}, {}, {1, 6}, {}, {3, 5}, {} - | {8, 10}, {}, {7, 12}, {}, {9, 11}, {} - |]; -departure_op = - [| {1, 3}, {}, {2, 5}, {}, {4, 6}, {} - | {7, 9}, {}, {8, 11}, {}, {10, 12}, {} - |]; -initial_m_obj_loc = [1, 1]; - -operations_duration = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0]; -is_moving_operation = [true, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false]; -final_m_obj_loc = [0, 0]; -operations_start_loc = [0, 2, 0, 4, 2, 4, 0, 2, 0, 4, 2, 4, 0, 0, 0, 0]; -operations_resources = [{1}, {1}, {1}, {1}, {1}, {1}, {2}, {2}, {2}, {2}, {2}, {2}, {}, {}, {}, {}]; diff --git a/test/conversion_0.mzn b/test/conversion_0.mzn deleted file mode 100644 index ad5a95e..0000000 --- a/test/conversion_0.mzn +++ /dev/null @@ -1,186 +0,0 @@ -include "globals.mzn"; - -int : n_intervals; -int : n_operations; -int : n_locations; -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_start; -array [1..n_operations, 0..(n_intervals + 1)] of var bool : op_fin; - -% 0 - локация не определена. -array [1..n_moving_obj, 0..(n_intervals + 1)] of var 0..n_locations : m_obj_loc; % Moving object location. - -array [1..n_moving_obj, 1..n_locations] of set of 1..n_operations : arrival_op; -array [1..n_moving_obj, 1..n_locations] of set of 1..n_operations : departure_op; - -% Определение m_obj_loc. -constraint forall (obj in 1..n_moving_obj, j in 1..(n_intervals + 1)) - ((m_obj_loc[obj, j] != 0) -> ( - (m_obj_loc[obj, j] == m_obj_loc[obj, j - 1] /\ (forall (k in departure_op[obj, m_obj_loc[obj, j]]) (op_status[k, j - 1] == 0))) - \/ - (not (forall (k in arrival_op[obj, m_obj_loc[obj, j]]) (op_fin[k, j - 1] == 0))) - )); - -% Начальное состояние. -array [1..n_moving_obj] of var 0..n_locations : initial_m_obj_loc; -constraint forall (i in 1..n_moving_obj) (m_obj_loc[i, 0] = initial_m_obj_loc[i]); - -% Конечное состояние. -array [1..n_moving_obj] of var 0..n_locations : final_m_obj_loc; -constraint forall (i in 1..n_moving_obj) ( - (final_m_obj_loc[i] != 0) -> - (m_obj_loc[i, n_intervals + 1] = final_m_obj_loc[i]) -); - -constraint forall (i in 1..n_operations, j in {0, n_intervals + 1}) (op_status[i, j] == 0); % Краевые значения. - -% Определение op_start и op_fin. -constraint forall (op in 1..n_operations, j in {0, n_intervals + 1}) - (op_start[op, j] == 0 /\ op_fin[op, j] == 0); -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])); - -% Непрерывность перемещения и швартовки. -array [1..n_operations] of var int : operations_duration; -array [1..n_operations] of var bool : is_continuous_operation; - -% TODO -%constraint forall (i in 1..n_operations) ( -% if (is_continuous_operation[i]) then ( -% forall (j in 1..n_intervals) ( -% let {var int : len = operations_duration[i]} in -% if (j + len > n_intervals + 1) then -% op_start[i, j] == 0 -% else ( -% (op_start[i, j] == 1) -> ( -% (forall (k in 1..(len - 1)) -% (op_status[i, j + k] == 1) -% ) /\ -% (op_status[i, j + len] == 0) -% ) -% ) -% endif -% ) -% ) else true -% endif -%); - - -constraint forall (i in 1..n_operations) ( - if (is_continuous_operation[i]) then ( - let {var int : len = operations_duration[i]} in - (forall (j in 1..(n_intervals - len + 1)) ( - (op_start[i, j] == 1) -> ( - (forall (k in 1..(len - 1)) - (op_status[i, j + k] == 1) - ) /\ - (op_status[i, j + len] == 0) - ) - )) /\ - (forall (j in (n_intervals - len + 2)..(n_intervals + 1)) - (op_start[i, j] == 0) - ) - ) else true - endif -); - -% Наличие всех ресурсов на месте во время начала операции перемещения. -array [1..n_operations] of set of 1..n_moving_obj : operations_resources; -array [1..n_operations] of 0..n_locations : operations_start_loc; - -constraint forall (op in 1..n_operations, j in 1..n_intervals) ( - forall (obj in operations_resources[op]) ( - (op_start[op, j]) -> (m_obj_loc[obj, j] == operations_start_loc[op]) - ) -); - -% Конфликтующие операции. -int : n_conflicting_op; - -array [1..n_conflicting_op] of 1..n_operations : confl_op_1; -array [1..n_conflicting_op] of 1..n_operations : confl_op_2; - -constraint forall (t in 0..(n_intervals + 1), i in 1..n_conflicting_op) ( - (op_status[confl_op_1[i], t] -> not op_status[confl_op_2[i], t]) - /\ - (op_status[confl_op_2[i], t] -> not op_status[confl_op_1[i], t]) -); - -% Окна непогоды. -int : n_bad_weather_windows; -array [1..n_bad_weather_windows] of 1..n_operations : bw_op; -array [1..n_bad_weather_windows] of 0..(n_intervals + 1) : bw_start; -array [1..n_bad_weather_windows] of 0..(n_intervals + 1) : bw_fin; % Включительно. - -constraint forall (i in 1..n_bad_weather_windows) ( - forall (t in bw_start[i]..bw_fin[i]) (op_status[bw_op[i], t] == 0) -); - -% Грузоообработка. -int : n_cargo_types; -int : n_obj_with_storage; -array [1..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types] of var int : storage_used_volume; % Первые n_moving_obj соответствуют наполненности соответствующих движущихся объектов. - -% Ограничения на вместимость. -array [1..n_obj_with_storage] of int : max_storage_vol; -constraint forall (storage in 1..n_obj_with_storage, t in 0..(n_intervals + 1)) ( - (sum (cargo in 1..n_cargo_types) (storage_used_volume[storage, t, cargo]) <= max_storage_vol[storage]) - /\ - (forall (cargo in 1..n_cargo_types) (0 <= storage_used_volume[storage, t, cargo])) -); - - -% Ограничения на граничные значения. -array [1..n_obj_with_storage, 1..n_cargo_types] of int : initial_storage_vol; -array [1..n_obj_with_storage, 1..n_cargo_types] of int : final_storage_vol; -constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types) ( - (storage_used_volume[storage, 0, cargo] == initial_storage_vol[storage, cargo]) - /\ - (if final_storage_vol[storage, cargo] >= 0 then - (storage_used_volume[storage, (n_intervals + 1), cargo] == final_storage_vol[storage, cargo]) - else true - endif) -); - -% Изменение грузов в хранилищах. -array [1..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types] of int : cargo_flows; - -int : n_loading_op; -array [1..n_obj_with_storage, 1..n_cargo_types] of set of 1..n_loading_op : involved_operations; -array [1..n_loading_op] of int : loading_op_delta; -array [1..n_loading_op] of 1..n_operations : loading_op_n; % Номера среди общего списка операций. - -constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types, t in 1..(n_intervals + 1)) ( - storage_used_volume[storage, t, cargo] = - storage_used_volume[storage, t - 1, cargo] + - cargo_flows[storage, t, cargo] + - sum (inv_op in involved_operations[storage, cargo]) ( - loading_op_delta[inv_op] * op_status[loading_op_n[inv_op], t] - ) -); - -% Критерий оптимизации -array [0..(n_intervals + 1)] of var bool : is_not_terminated; -constraint (is_not_terminated[0] == 0 /\ is_not_terminated[n_intervals + 1] == 0); -constraint forall (t in 1..n_intervals) ( - is_not_terminated[t] == ( - (not (forall (op in 1..n_operations) (op_status[op, t] == 0))) - \/ - is_not_terminated[t + 1] - ) -); - -solve minimize sum(is_not_terminated); - -output [show(sum(is_not_terminated)), "\n", - show(op_status), "\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", - "arrival_op = ", show(arrival_op), "\n\n", - "departure_op = ", show(departure_op), "\n\n", - "is_not_terminated = ", show(is_not_terminated), "\n\n", - "storage_used_volume = ", show(storage_used_volume), "\n\n" - ]; diff --git a/test/in_1.ipp b/test/in_1.ipp deleted file mode 100644 index dfdfc67..0000000 --- a/test/in_1.ipp +++ /dev/null @@ -1,63 +0,0 @@ -Cargoes -0;LNG;0.0 -Berths -1;Raid -2;Pier 1 -3;Pier 2 -Storages -4;Storage 1;0;10000.0 -Bunkers -Tows -Loading Equipments -Transport Ships -5;Ship 1;2000.0 -6;Ship 2;2000.0 - -Templates -7;mov;[];5;1;2;[];1.0 -8;mov;[];5;2;1;[];1.0 -9;mov;[];5;1;3;[];1.0 -10;mov;[];5;3;1;[];1.0 -11;mov;[];5;2;3;[];1.0 -12;mov;[];5;3;2;[];1.0 -13;mov;[];6;1;2;[];1.0 -14;mov;[];6;2;1;[];1.0 -15;mov;[];6;1;3;[];1.0 -16;mov;[];6;3;1;[];1.0 -17;mov;[];6;2;3;[];1.0 -18;mov;[];6;3;2;[];1.0 -19;loa;[];4;0;5;2;[];100.0 -20;loa;[];4;0;5;3;[];50.0 -21;loa;[];4;0;6;2;[];100.0 -22;loa;[];4;0;6;3;[];50.0 - -Cargo Flows -Initial Vessel State -5;1 -6;1 -Initial Storage State -0;5;0.0 -0;6;0.0 -0;4;10000.0 -Final Vessel State -5;1 -6;1 -Final Storage State -0;5;1000.0 -0;6;1000.0 - -Task Properties -24.0;0 - -Solution -16.0 -7; R; 1.0; 1.0 -10; R; 16.0; 1.0 -11; R; 9.0; 1.0 -14; R; 16.0; 1.0 -15; R; 1.0; 1.0 -18; R; 8.0; 1.0 -19; R; 2.0; 7.0 -20; R; 10.0; 6.0 -21; R; 9.0; 7.0 -22; R; 2.0; 6.0 diff --git a/test/run.bat b/test/run.bat deleted file mode 100644 index 713e768..0000000 --- a/test/run.bat +++ /dev/null @@ -1,8 +0,0 @@ -del raw_result.txt -del result.txt - -java -classpath "../out/production/Conversion" inport.Main to_MiniZinc in_1.ipp conversion_0.dzn - -minizinc --solver Gecode conversion_0.mzn conversion_0.dzn >> raw_result.txt - -java -classpath "../out/production/Conversion" inport.Main resolve_result in_1.ipp raw_result.txt result.txt diff --git a/tests/cargo_handling_and_moving.ipp b/tests/cargo_handling_and_moving.ipp new file mode 100644 index 0000000..2b013c8 --- /dev/null +++ b/tests/cargo_handling_and_moving.ipp @@ -0,0 +1,51 @@ +Cargoes +0; Груз1 +Berths +1;Raid +2;Pier 1 +3;Pier 2 +4;Pier 3 +5;Pier 4 +6;Pier 5 +7;Pier 6 +Storages +1001; Хранилище; 0; 20 +Bunkers +Tows +Loading Equipments +Transport Ships +11; Ship 1; 8.0 + +Templates +101;mov;[];11;1;4;[];3.0 +102;mov;[];11;1;2;[];4.0 +103;mov;[];11;1;5;[];10.0 +104;mov;[];11;2;3;[];9.0 +105;mov;[];11;3;1;[];5.0 +106;mov;[];11;4;6;[];2.0 +107;mov;[];11;5;6;[];1.0 +108;mov;[];11;6;3;[];1.0 +109;mov;[];11;6;7;[];5.0 +110;mov;[];11;7;3;[];3.0 + +201; mrn; []; 11; 5; []; 1 +202; unm; []; 11; 5; []; 1 + +301; loa; []; 1001; 0; 11; 5; []; 2 + +Cargo Flows +Initial Vessel State +11;1 +Initial Storage State +0; 11; 0.0 +0; 1001; 20.0 +Final Vessel State +11;3 +Final Storage State +0; 11; 2.0 + +Task Properties +15.0;0 + +Solution +12.0 diff --git a/test/shortest_path_with_weather.ipp b/tests/shortest_path_with_weather.ipp similarity index 100% rename from test/shortest_path_with_weather.ipp rename to tests/shortest_path_with_weather.ipp diff --git a/tests/simple_cargo_flow.ipp b/tests/simple_cargo_flow.ipp new file mode 100644 index 0000000..4f1fbb4 --- /dev/null +++ b/tests/simple_cargo_flow.ipp @@ -0,0 +1,37 @@ +Cargoes +0; Груз1 +Berths +1; Raid +2; Pier 4 + +Storages +1001; Хранилище; 0; 10 +Bunkers +Tows +Loading Equipments +Transport Ships +11; Ship 1; 5.0 + +Templates +103; mov; []; 11; 1; 2;[]; 1 +201; mrn; []; 11; 2; []; 1 +202; unm; []; 11; 2; []; 1 +301; loa; []; 1001; 0; 11; 2; []; 1 + +Cargo Flows +1001; 0; [0:0, 5:1] +Initial Vessel State +11; 1 +Initial Storage State +0; 11; 0.0 +0; 1001; 1.0 +Final Vessel State +11; 2 +Final Storage State +0; 11; 2.0 + +Task Properties +10.0;0 + +Solution +7.0 diff --git a/test/simple_shortest_path.ipp b/tests/simple_shortest_path.ipp similarity index 100% rename from test/simple_shortest_path.ipp rename to tests/simple_shortest_path.ipp -- GitLab