Commit 455a088c authored by Vladislav Kiselev's avatar Vladislav Kiselev

Другая реализация жадного алгоритма.

Последний тест, на котором работает - 2 причала, 1 судно. Судно едет на второй причал, загружается, возвращаются. Все действия по одной секунде. Горизонт планирования 6 - ещё работает, 10 - слишком долго и начинает расти память.
parent 5ef77a15
...@@ -345,7 +345,8 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -345,7 +345,8 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
array [1..n_loading_op] of 1..n_operations : loading_op_n; % Номера среди общего списка операций. array [1..n_loading_op] of 1..n_operations : loading_op_n; % Номера среди общего списка операций.
array [1..n_all_storage_sections] of set of 1..n_loading_op : involved_operations; array [1..n_all_storage_sections] of set of 1..n_loading_op : involved_operations;
array [1..n_moving_obj] of set of 1..n_all_storage_sections : sections_of_moving_obj;
array [1..n_moving_obj] of bool : is_sections_of_moving_obj_empty;
array [0..n_all_storage_sections] of int : storage_greedy_upper_limit; array [0..n_all_storage_sections] of int : storage_greedy_upper_limit;
array [0..n_all_storage_sections] of int : storage_greedy_lower_limit; array [0..n_all_storage_sections] of int : storage_greedy_lower_limit;
...@@ -358,13 +359,14 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -358,13 +359,14 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections, 1..(n_intervals + 1)] of var int : nominal_cargo_value; array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections, 1..(n_intervals + 1)] of var int : nominal_cargo_value;
array [0..n_sections_of_real_storage_and_bunkers, 0..(max_number_of_connected_sections + 1), 1..(n_intervals + 1)] of var int : cargo_overflow_remains; array [0..n_sections_of_real_storage_and_bunkers, 0..(max_number_of_connected_sections + 1), 1..(n_intervals + 1)] of var int : cargo_overflow_remains;
array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections, 1..(n_intervals + 1)] of var int : real_cargo_value; array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections, 1..(n_intervals + 1)] of var int : real_cargo_value;
array [0..n_sections_of_real_storage_and_bunkers, 1..(n_intervals + 1)] of var int : total_sum;
% Определение real_cargo_value % Определение real_cargo_value
array [0..n_operations] of 0..n_all_storage_sections : operations_main_stor_no_in_secondary; array [0..n_operations] of 0..n_all_storage_sections : operations_main_stor_no_in_secondary;
array [0..n_operations] of 0..n_all_storage_sections : operations_secondary_stor_no_in_main; array [0..n_operations] of 0..n_all_storage_sections : operations_secondary_stor_no_in_main;
array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections] of set of 1..n_operations : connected_op_to_pair_of_sections; array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections] of set of 1..n_operations : connected_op_to_pair_of_sections;
/*
array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections, 1..(n_intervals + 1)] of var int : debug_1; array [0..n_sections_of_real_storage_and_bunkers, 0..max_number_of_connected_sections, 1..(n_intervals + 1)] of var int : debug_1;
constraint forall (op in 1..n_operations, t in 1..(n_intervals + 1) where operations_main_stor_no_in_secondary[op] != 0) ( constraint forall (op in 1..n_operations, t in 1..(n_intervals + 1) where operations_main_stor_no_in_secondary[op] != 0) (
op_status[op, t] -> ( op_status[op, t] -> (
...@@ -381,19 +383,41 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -381,19 +383,41 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
-> ->
(debug_1[section_1, section_2, t] = 0) (debug_1[section_1, section_2, t] = 0)
); );
*/
% Определение nominal_cargo_value % Определение nominal_cargo_value
% Операция грузообработки активна -> нужные номинальные значения согласованы с ней. % Операция грузообработки активна -> нужные номинальные значения согласованы с ней.
constraint forall (op in 1..n_operations, t in 1..(n_intervals + 1) where operations_main_stor_no_in_secondary[op] != 0) ( constraint forall (op in 1..n_operations,
op_status[op, t] -> ( t in 1..(n_intervals + 1),
nominal_cargo_value[operations_secondary_stor[op], operations_main_stor_no_in_secondary[op], t] = section_1 = operations_main_stor[op],
-max( section_2 = operations_secondary_stor[op],
min(storage_greedy_upper_limit[operations_main_stor[op]] - storage_used_volume[operations_main_stor[op], t - 1], pos = operations_main_stor_no_in_secondary[op]
loading_op_delta_of_main_obj[op]), where pos != 0) (
storage_greedy_lower_limit[operations_main_stor[op]] - storage_used_volume[operations_main_stor[op], t - 1]) let {var int : total_vol = storage_used_volume[section_1, t - 1] + loading_op_delta_of_main_obj[op];} in
(op_status[op, t] /\ total_vol > storage_greedy_upper_limit[section_1]) -> (
nominal_cargo_value[section_2, pos, t] = -(loading_op_delta_of_main_obj[op] - (total_vol - storage_greedy_upper_limit[section_1]))
)
);
constraint forall (op in 1..n_operations,
t in 1..(n_intervals + 1),
section_1 = operations_main_stor[op],
section_2 = operations_secondary_stor[op],
pos = operations_main_stor_no_in_secondary[op]
where pos != 0) (
let {var int : total_vol = storage_used_volume[section_1, t - 1] + loading_op_delta_of_main_obj[op];} in
(op_status[op, t] /\ total_vol < storage_greedy_lower_limit[section_1]) -> (
nominal_cargo_value[section_2, pos, t] = -(loading_op_delta_of_main_obj[op] - (total_vol - storage_greedy_lower_limit[section_1]))
)
);
constraint forall (op in 1..n_operations,
t in 1..(n_intervals + 1),
section_1 = operations_main_stor[op],
section_2 = operations_secondary_stor[op],
pos = operations_main_stor_no_in_secondary[op]
where pos != 0) (
let {var int : total_vol = storage_used_volume[section_1, t - 1] + loading_op_delta_of_main_obj[op];} in
(op_status[op, t] /\ (total_vol >= storage_greedy_lower_limit[section_1])
/\ (total_vol <= storage_greedy_upper_limit[section_1])) -> (
nominal_cargo_value[section_2, pos, t] = -loading_op_delta_of_main_obj[op]
) )
); );
...@@ -422,16 +446,34 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -422,16 +446,34 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
); );
% Определение cargo_overflow_remains. % Определение cargo_overflow_remains.
% array [0..n_sections_of_real_storage_and_bunkers, 1..(n_intervals + 1)] of var int : total_sum;
constraint forall (t in 1..(n_intervals + 1), section in 1..n_sections_of_real_storage_and_bunkers) (
total_sum[section, t] = sum (i in 1..number_of_connected_sections[section]) (nominal_cargo_value[section, i, t])
);
constraint forall (t in 1..(n_intervals + 1)) (total_sum[0, t] = 0);
% Переполнение. % Переполнение.
constraint forall (t in 1..(n_intervals + 1), section in 1..n_sections_of_real_storage_and_bunkers) ( constraint forall (t in 1..(n_intervals + 1), section in 1..n_sections_of_real_storage_and_bunkers) (
let {var int : delta = sum (i in 1..number_of_connected_sections[section]) (nominal_cargo_value[section, i, t]); (total_sum[section, t] + storage_used_volume[section, t - 1] > storage_greedy_upper_limit[section])
var int : real_delta = min(max(delta, ->
storage_greedy_lower_limit[section] - storage_used_volume[section, t - 1]), (cargo_overflow_remains[section, number_of_connected_sections[section] + 1, t] =
storage_greedy_upper_limit[section] - storage_used_volume[section, t - 1]); total_sum[section, t] + storage_used_volume[section, t - 1] - storage_greedy_upper_limit[section]
} in ( )
cargo_overflow_remains[section, number_of_connected_sections[section] + 1, t] = (delta - real_delta) );
constraint forall (t in 1..(n_intervals + 1), section in 1..n_sections_of_real_storage_and_bunkers) (
(total_sum[section, t] + storage_used_volume[section, t - 1] < storage_greedy_lower_limit[section])
->
(cargo_overflow_remains[section, number_of_connected_sections[section] + 1, t] =
total_sum[section, t] + storage_used_volume[section, t - 1] - storage_greedy_lower_limit[section]
) )
); );
constraint forall (t in 1..(n_intervals + 1), section in 1..n_sections_of_real_storage_and_bunkers) (
let {var int : total = total_sum[section, t] + storage_used_volume[section, t - 1]} in
((storage_greedy_lower_limit[section] <= total) /\ (total <= storage_greedy_upper_limit[section]))
->
(cargo_overflow_remains[section, number_of_connected_sections[section] + 1, t] = 0)
);
% Избавляемся от лишнего. % Избавляемся от лишнего.
% Если остаток переполнения и номналное значение одного знака, то полностью отменяем это номинальное значение. % Если остаток переполнения и номналное значение одного знака, то полностью отменяем это номинальное значение.
...@@ -566,6 +608,7 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -566,6 +608,7 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
array [1..n_fixed_op] of int : fixed_op_intensity; array [1..n_fixed_op] of int : fixed_op_intensity;
array [0..n_operations, 0..n_intervals] of bool : is_fixed; array [0..n_operations, 0..n_intervals] of bool : is_fixed;
array [0..n_moving_obj, 0..(n_intervals + 1)] of bool : is_obj_involved_in_fixed_op;
constraint forall (no in 1..n_fixed_op, op = fixed_op[no]) ( constraint forall (no in 1..n_fixed_op, op = fixed_op[no]) (
forall (t in fixed_op_start[no]..fixed_op_end[no]) ( forall (t in fixed_op_start[no]..fixed_op_end[no]) (
...@@ -654,6 +697,9 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -654,6 +697,9 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
(op_start[op, t] /\ (not is_fixed[op, t])) -> not is_op_possible[op, t - 1] (op_start[op, t] /\ (not is_fixed[op, t])) -> not is_op_possible[op, t - 1]
); );
*/ */
array [1..n_moving_obj, 1..n_locations, 1..n_intervals] of bool : is_fixed_op_planned_in_future;
% Критерий оптимизации % Критерий оптимизации
array [1..(n_intervals + 1)] of var bool : is_not_terminated; array [1..(n_intervals + 1)] of var bool : is_not_terminated;
% В конце всё остановится. % В конце всё остановится.
...@@ -690,10 +736,13 @@ output [show(sum(is_not_terminated)), "\n", ...@@ -690,10 +736,13 @@ output [show(sum(is_not_terminated)), "\n",
"cargo_overflow_remains {", show(max_number_of_connected_sections + 2), " ", show(n_intervals + 1), "} = ", show(cargo_overflow_remains), "\n\n", "cargo_overflow_remains {", show(max_number_of_connected_sections + 2), " ", show(n_intervals + 1), "} = ", show(cargo_overflow_remains), "\n\n",
"real_cargo_value {", show(max_number_of_connected_sections + 1), " ", show(n_intervals + 1), "} = ", show(real_cargo_value), "\n\n", "real_cargo_value {", show(max_number_of_connected_sections + 1), " ", show(n_intervals + 1), "} = ", show(real_cargo_value), "\n\n",
"debug_1 {", show(max_number_of_connected_sections + 1), " ", show(n_intervals + 1), "} = ", show(debug_1), "\n\n", % "debug_1 {", show(max_number_of_connected_sections + 1), " ", show(n_intervals + 1), "} = ", show(debug_1), "\n\n",
% "debug_storage_used_volume = ", show(debug_storage_used_volume), "\n\n",
"total_sum {", show(n_intervals + 1), "} = ", show(total_sum), "\n\n",
"debug_storage_used_volume = ", show(debug_storage_used_volume), "\n\n",
/* /*
"is_op_possible {", show(n_intervals), "} = ", show(is_op_possible), "\n\n", "is_op_possible {", show(n_intervals), "} = ", show(is_op_possible), "\n\n",
......
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