Commit ac2467fe authored by Vladislav Kiselev's avatar Vladislav Kiselev

Различные грузы теперь хранятся отдельно в хранилищах со своим объёмом, убраны...

Различные грузы теперь хранятся отдельно в хранилищах со своим объёмом, убраны избыточные хранилища с нулевым объёмом.
parent fcf4d282
...@@ -301,37 +301,37 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -301,37 +301,37 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
% Грузообработка. % Грузообработка.
int : n_cargo_types; int : n_cargo_types;
int : n_obj_with_storage; int : n_all_storage_sections;
array [0..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types] of var int : storage_used_volume; % Первые n_moving_obj соответствуют наполненности соответствующих движущихся объектов. array [0..n_all_storage_sections, 0..(n_intervals + 1)] of var int : storage_used_volume;
constraint forall (t in 0..(n_intervals + 1), cargo in 1..n_cargo_types) (storage_used_volume[0, t, cargo] = 0); % Фиктивный объект. constraint forall (t in 0..(n_intervals + 1)) (storage_used_volume[0, t] = 0); % Фиктивный объект.
% Ограничения на вместимость. % Ограничения на вместимость.
array [0..n_obj_with_storage] of int : max_storage_vol; array [0..n_all_storage_sections] of int : max_storage_vol;
% Максимальный объём. % Максимальный объём.
constraint forall (storage in 1..n_obj_with_storage, t in 0..(n_intervals + 1)) ( constraint forall (storage in 1..n_all_storage_sections, t in 0..(n_intervals + 1)) (
sum (cargo in 1..n_cargo_types) (storage_used_volume[storage, t, cargo]) <= max_storage_vol[storage] (storage_used_volume[storage, t]) <= max_storage_vol[storage]
); );
% Неотрицательность объёма. % Неотрицательность объёма.
constraint forall (storage in 1..n_obj_with_storage, t in 0..(n_intervals + 1), cargo in 1..n_cargo_types) ( constraint forall (storage in 1..n_all_storage_sections, t in 0..(n_intervals + 1)) (
0 <= storage_used_volume[storage, t, cargo] 0 <= storage_used_volume[storage, t]
); );
% Ограничения на граничные значения. % Ограничения на граничные значения.
array [0..n_obj_with_storage, 0..n_cargo_types] of int : initial_storage_vol; array [0..n_all_storage_sections] of int : initial_storage_vol;
array [0..n_obj_with_storage, 0..n_cargo_types] of int : final_storage_vol; array [0..n_all_storage_sections] of int : final_storage_vol;
constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types) ( % Initial values. constraint forall (storage in 1..n_all_storage_sections) ( % Initial values.
storage_used_volume[storage, 0, cargo] = initial_storage_vol[storage, cargo] storage_used_volume[storage, 0] = initial_storage_vol[storage]
); );
constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types % Final values. constraint forall (storage in 1..n_all_storage_sections % Final values.
where final_storage_vol[storage, cargo] >= 0) ( where final_storage_vol[storage] >= 0) (
storage_used_volume[storage, n_intervals + 1, cargo] = final_storage_vol[storage, cargo] storage_used_volume[storage, n_intervals + 1] = final_storage_vol[storage]
); );
% Изменение грузов в хранилищах. % Изменение грузов в хранилищах.
array [0..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types] of int : cargo_flows; array [0..n_all_storage_sections, 0..(n_intervals + 1)] of int : cargo_flows;
int : n_loading_op; int : n_loading_op;
...@@ -339,21 +339,21 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -339,21 +339,21 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
array [0..n_operations] of int : loading_op_abs_delta; array [0..n_operations] of int : loading_op_abs_delta;
array [0..n_operations] of {1, -1} : loading_op_direction; array [0..n_operations] of {1, -1} : loading_op_direction;
array [0..n_operations] of 1..n_obj_with_storage : operations_main_stor; array [0..n_operations] of 1..n_all_storage_sections : operations_main_stor;
array [0..n_operations] of 1..n_obj_with_storage : operations_secondary_stor; array [0..n_operations] of 1..n_all_storage_sections : operations_secondary_stor;
array [0..n_operations] of 1..n_cargo_types : operations_cargo_t; array [0..n_operations] of 1..n_cargo_types : operations_cargo_t;
array [1..n_loading_op] of int : loading_op_delta; array [1..n_loading_op] of int : loading_op_delta;
array [1..n_loading_op] of {1, -1} : loading_op_local_direction; array [1..n_loading_op] of {1, -1} : loading_op_local_direction;
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_obj_with_storage, 1..n_cargo_types] of set of 1..n_loading_op : involved_operations; array [1..n_all_storage_sections] of set of 1..n_loading_op : involved_operations;
constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types, t in 1..(n_intervals + 1)) ( constraint forall (storage in 1..n_all_storage_sections, t in 1..(n_intervals + 1)) (
storage_used_volume[storage, t, cargo] = ( storage_used_volume[storage, t] = (
storage_used_volume[storage, t - 1, cargo] + storage_used_volume[storage, t - 1] +
cargo_flows[storage, t, cargo] + cargo_flows[storage, t] +
sum (inv_op in involved_operations[storage, cargo]) ( sum (inv_op in involved_operations[storage]) (
loading_op_delta[inv_op] * loading_op_delta[inv_op] *
op_status[loading_op_n[inv_op], t] op_status[loading_op_n[inv_op], t]
) )
...@@ -427,15 +427,14 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -427,15 +427,14 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
) /\ % Если это операция пришвартовки, то в этот интервал ) /\ % Если это операция пришвартовки, то в этот интервал
% причал должен быть свободным. % причал должен быть свободным.
((not is_moving_operation[op]) -> ( ((not is_moving_operation[op]) -> (
let {1..n_obj_with_storage : m_stor = operations_main_stor[op]; let {1..n_all_storage_sections : m_stor = operations_main_stor[op];
1..n_obj_with_storage : s_stor = operations_secondary_stor[op]; 1..n_all_storage_sections : s_stor = operations_secondary_stor[op];
1..n_cargo_types : cargo = operations_cargo_t[op]; int : delta = loading_op_delta_of_main_obj[op];
int : delta = loading_op_delta_of_main_obj[op];
} in } in
(storage_used_volume[m_stor, t, cargo] + delta >= 0) /\ (storage_used_volume[m_stor, t] + delta >= 0) /\
((sum (c in 1..n_cargo_types) (storage_used_volume[m_stor, t, c])) + delta <= max_storage_vol[m_stor]) /\ (storage_used_volume[m_stor, t] + delta <= max_storage_vol[m_stor]) /\
(storage_used_volume[s_stor, t, cargo] - delta >= 0) /\ (storage_used_volume[s_stor, t] - delta >= 0) /\
((sum (c in 1..n_cargo_types) (storage_used_volume[s_stor, t, c])) - delta <= max_storage_vol[s_stor]) (storage_used_volume[s_stor, t] - delta <= max_storage_vol[s_stor])
)) /\ % Если это операция грузообработки, то она не выведет )) /\ % Если это операция грузообработки, то она не выведет
% объём берегового хранилища и хранилища судна за % объём берегового хранилища и хранилища судна за
% границы дозволенного. % границы дозволенного.
......
...@@ -81,7 +81,6 @@ array [0..n_moving_obj, 0..n_operations] of bool : moving_op_of_obj; ...@@ -81,7 +81,6 @@ array [0..n_moving_obj, 0..n_operations] of bool : moving_op_of_obj;
); );
array [1..n_locations] of 0..n_locations : twin_location = [i - 1 + (i mod 2) * 2 | i in 1..n_locations]; array [1..n_locations] of 0..n_locations : twin_location = [i - 1 + (i mod 2) * 2 | i in 1..n_locations];
% TODO нумерация с нуля
array [0..n_operations] of 0..n_locations : operations_destination; % Локация в которой окажется объект после завершения операции. array [0..n_operations] of 0..n_locations : operations_destination; % Локация в которой окажется объект после завершения операции.
...@@ -219,11 +218,9 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -219,11 +218,9 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
% Операции погрузки, которые используют этот объект в качестве главного или в качестве бункеровщика. % Операции погрузки, которые используют этот объект в качестве главного или в качестве бункеровщика.
array [0..n_moving_obj] of set of 0..n_operations : related_cargo_op; array [0..n_moving_obj] of set of 0..n_operations : related_cargo_op;
% TODO узнать про where
% Определение is_involved_in_cargo_op. % Определение is_involved_in_cargo_op.
constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) ( constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) (
is_involved_in_cargo_op[obj, t] = ( is_involved_in_cargo_op[obj, t] = (
% (exists (op in 1..n_operations where (not is_moving_operation[op]) /\ (main_obj_of_operation[op] = obj)) (
(exists (op in related_cargo_op[obj]) (op_status[op, t])) (exists (op in related_cargo_op[obj]) (op_status[op, t]))
\/ \/
((participation_as_resource[obj, t] != 0) /\ (not is_moving_operation[participation_as_resource[obj, t]])) ((participation_as_resource[obj, t] != 0) /\ (not is_moving_operation[participation_as_resource[obj, t]]))
...@@ -301,37 +298,37 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -301,37 +298,37 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
% Грузообработка. % Грузообработка.
int : n_cargo_types; int : n_cargo_types;
int : n_obj_with_storage; int : n_all_storage_sections;
array [0..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types] of var int : storage_used_volume; % Первые n_moving_obj соответствуют наполненности соответствующих движущихся объектов. array [0..n_all_storage_sections, 0..(n_intervals + 1)] of var int : storage_used_volume;
constraint forall (t in 0..(n_intervals + 1), cargo in 1..n_cargo_types) (storage_used_volume[0, t, cargo] = 0); % Фиктивный объект. constraint forall (t in 0..(n_intervals + 1)) (storage_used_volume[0, t] = 0); % Фиктивный объект.
% Ограничения на вместимость. % Ограничения на вместимость.
array [0..n_obj_with_storage] of int : max_storage_vol; array [0..n_all_storage_sections] of int : max_storage_vol;
% Максимальный объём. % Максимальный объём.
constraint forall (storage in 1..n_obj_with_storage, t in 0..(n_intervals + 1)) ( constraint forall (storage in 1..n_all_storage_sections, t in 0..(n_intervals + 1)) (
sum (cargo in 1..n_cargo_types) (storage_used_volume[storage, t, cargo]) <= max_storage_vol[storage] (storage_used_volume[storage, t]) <= max_storage_vol[storage]
); );
% Неотрицательность объёма. % Неотрицательность объёма.
constraint forall (storage in 1..n_obj_with_storage, t in 0..(n_intervals + 1), cargo in 1..n_cargo_types) ( constraint forall (storage in 1..n_all_storage_sections, t in 0..(n_intervals + 1)) (
0 <= storage_used_volume[storage, t, cargo] 0 <= storage_used_volume[storage, t]
); );
% Ограничения на граничные значения. % Ограничения на граничные значения.
array [0..n_obj_with_storage, 0..n_cargo_types] of int : initial_storage_vol; array [0..n_all_storage_sections] of int : initial_storage_vol;
array [0..n_obj_with_storage, 0..n_cargo_types] of int : final_storage_vol; array [0..n_all_storage_sections] of int : final_storage_vol;
constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types) ( % Initial values. constraint forall (storage in 1..n_all_storage_sections) ( % Initial values.
storage_used_volume[storage, 0, cargo] = initial_storage_vol[storage, cargo] storage_used_volume[storage, 0] = initial_storage_vol[storage]
); );
constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types % Final values. constraint forall (storage in 1..n_all_storage_sections % Final values.
where final_storage_vol[storage, cargo] >= 0) ( where final_storage_vol[storage] >= 0) (
storage_used_volume[storage, n_intervals + 1, cargo] = final_storage_vol[storage, cargo] storage_used_volume[storage, n_intervals + 1] = final_storage_vol[storage]
); );
% Изменение грузов в хранилищах. % Изменение грузов в хранилищах.
array [0..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types] of int : cargo_flows; array [0..n_all_storage_sections, 0..(n_intervals + 1)] of int : cargo_flows;
int : n_loading_op; int : n_loading_op;
...@@ -339,15 +336,15 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -339,15 +336,15 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
array [0..n_operations] of int : loading_op_abs_delta; array [0..n_operations] of int : loading_op_abs_delta;
array [0..n_operations] of {1, -1} : loading_op_direction; array [0..n_operations] of {1, -1} : loading_op_direction;
array [0..n_operations] of 1..n_obj_with_storage : operations_main_stor; array [0..n_operations] of 1..n_all_storage_sections : operations_main_stor;
array [0..n_operations] of 1..n_obj_with_storage : operations_secondary_stor; array [0..n_operations] of 1..n_all_storage_sections : operations_secondary_stor;
array [0..n_operations] of 1..n_cargo_types : operations_cargo_t; array [0..n_operations] of 1..n_cargo_types : operations_cargo_t;
array [1..n_loading_op] of int : loading_op_delta; array [1..n_loading_op] of int : loading_op_delta;
array [1..n_loading_op] of {1, -1} : loading_op_local_direction; array [1..n_loading_op] of {1, -1} : loading_op_local_direction;
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_obj_with_storage, 1..n_cargo_types] 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 [0..n_operations, 0..(n_intervals + 1)] of var int : cargo_op_intensity; array [0..n_operations, 0..(n_intervals + 1)] of var int : cargo_op_intensity;
...@@ -368,11 +365,11 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -368,11 +365,11 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
op_status[op, t] -> (cargo_op_intensity[op, t] > 0) op_status[op, t] -> (cargo_op_intensity[op, t] > 0)
); );
constraint forall (storage in 1..n_obj_with_storage, cargo in 1..n_cargo_types, t in 1..(n_intervals + 1)) ( constraint forall (storage in 1..n_all_storage_sections, t in 1..(n_intervals + 1)) (
storage_used_volume[storage, t, cargo] = ( storage_used_volume[storage, t] = (
storage_used_volume[storage, t - 1, cargo] + storage_used_volume[storage, t - 1] +
cargo_flows[storage, t, cargo] + cargo_flows[storage, t] +
sum (inv_op in involved_operations[storage, cargo]) ( sum (inv_op in involved_operations[storage]) (
cargo_op_intensity[loading_op_n[inv_op], t] * cargo_op_intensity[loading_op_n[inv_op], t] *
loading_op_local_direction[inv_op] loading_op_local_direction[inv_op]
) )
...@@ -433,15 +430,14 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац ...@@ -433,15 +430,14 @@ array [0..n_operations] of 0..n_locations : operations_destination; % Локац
constraint forall (op in 1..n_operations, t in 1..n_intervals) ( constraint forall (op in 1..n_operations, t in 1..n_intervals) (
is_cargo_op_not_exceeds_storage_limits[op, t] = is_cargo_op_not_exceeds_storage_limits[op, t] =
((not is_moving_operation[op]) -> ( ((not is_moving_operation[op]) -> (
let {1..n_obj_with_storage : m_stor = operations_main_stor[op]; let {1..n_all_storage_sections : m_stor = operations_main_stor[op];
1..n_obj_with_storage : s_stor = operations_secondary_stor[op]; 1..n_all_storage_sections : s_stor = operations_secondary_stor[op];
1..n_cargo_types : cargo = operations_cargo_t[op]; int : delta = loading_op_direction[op];
int : delta = loading_op_direction[op];
} in } in
(storage_used_volume[m_stor, t, cargo] + delta >= 0) /\ (storage_used_volume[m_stor, t] + delta >= 0) /\
((sum (c in 1..n_cargo_types) (storage_used_volume[m_stor, t, c])) + delta <= max_storage_vol[m_stor]) /\ (storage_used_volume[m_stor, t] + delta <= max_storage_vol[m_stor]) /\
(storage_used_volume[s_stor, t, cargo] - delta >= 0) /\ (storage_used_volume[s_stor, t] - delta >= 0) /\
((sum (c in 1..n_cargo_types) (storage_used_volume[s_stor, t, c])) - delta <= max_storage_vol[s_stor]) (storage_used_volume[s_stor, t] - delta <= max_storage_vol[s_stor])
)) ))
); );
......
...@@ -4,21 +4,26 @@ ...@@ -4,21 +4,26 @@
*/ */
package inport; package inport;
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.Map;
/** /**
* *
* @author topazh_ag * @author topazh_ag
*/ */
public class Bunker extends TransportShip { public class Bunker extends TransportShip {
public Bunker(int id, String name, double cargoMax) { public Bunker(int id, String name, ArrayList<Pair<Cargo, Double>> storageSections) {
super(id, name, cargoMax); super(id, name, storageSections);
} }
public Bunker() { public Bunker() {
super( ); super( );
} }
public Bunker(String s) { public Bunker(String s, Map<Integer, Cargo> mCargo) {
super(s); super(s, mCargo);
} }
} }
...@@ -389,7 +389,34 @@ public class ConversionUtil { ...@@ -389,7 +389,34 @@ public class ConversionUtil {
private final int nObjWithStorage; private final int nObjWithStorage;
private final Map<Integer, Integer> storNById; class StorageSectionId implements Comparable<StorageSectionId> {
boolean isRealStorage; // Not transport ship.
Integer localN;
Integer typeN;
StorageSectionId(boolean isRealStorage, Integer localN, Integer typeN) {
this.isRealStorage = isRealStorage;
this.localN = localN;
this.typeN = typeN;
}
@Override
public int compareTo(@NotNull StorageSectionId id) {
if (isRealStorage != id.isRealStorage) {
return (isRealStorage ? 1 : -1);
}
if (! localN.equals(id.localN)) {
return localN.compareTo(id.localN);
}
if (! typeN.equals(id.typeN)) {
return typeN.compareTo(id.typeN);
}
return 0;
}
}
private final Map<StorageSectionId, Integer> sectionNById;
private final Map<Integer, Integer> storageNById;
private final Map<Integer, Integer> cargoNById; private final Map<Integer, Integer> cargoNById;
private final Map<Integer, Integer> typeToN; private final Map<Integer, Integer> typeToN;
...@@ -412,7 +439,7 @@ public class ConversionUtil { ...@@ -412,7 +439,7 @@ public class ConversionUtil {
n_intervals = (int)task.getPlanningInterval(); n_intervals = (int)task.getPlanningInterval();
berths = new ArrayList<>(task.getBerths()); berths = new ArrayList<>(task.getBerths());
locationNumberById = new TreeMap<>(new PairComparator()); locationNumberById = new TreeMap<>(new PairComparator<>());
for (Berth berth : berths) { for (Berth berth : berths) {
locationNumberById.put(new Pair<>(berth.getId(), false), locationNumberById.size()); locationNumberById.put(new Pair<>(berth.getId(), false), locationNumberById.size());
locationNumberById.put(new Pair<>(berth.getId(), true), locationNumberById.size()); locationNumberById.put(new Pair<>(berth.getId(), true), locationNumberById.size());
...@@ -433,16 +460,36 @@ public class ConversionUtil { ...@@ -433,16 +460,36 @@ public class ConversionUtil {
storages = new ArrayList<>(task.getStorages()); storages = new ArrayList<>(task.getStorages());
cargoes = new ArrayList<>(task.getCargoes()); cargoes = new ArrayList<>(task.getCargoes());
storNById = new TreeMap<>();
for (int i = 0; i < storages.size(); i++) {
storNById.put(storages.get(i).getId(), i);
}
cargoNById = new TreeMap<>(); cargoNById = new TreeMap<>();
for (int i = 0; i < task.getCargoes().size(); i++) { for (int i = 0; i < task.getCargoes().size(); i++) {
cargoNById.put(cargoes.get(i).getId(), i); cargoNById.put(cargoes.get(i).getId(), i);
} }
int nextStorageNo = 0;
storageNById = new TreeMap<>();
sectionNById = new TreeMap<>();
for (int i = 0; i < storages.size(); i++) {
storageNById.put(storages.get(i).getId(), i);
}
for (MovingObject obj : movingObjects) {
if (obj instanceof TransportShip) {
for (Pair<Cargo, Double> p : ((TransportShip) obj).getStorageSections()) {
sectionNById.put(new StorageSectionId(false, mObjToN(obj), cargoNById.get(p.getKey().getId())), nextStorageNo++);
}
}
}
for (int i = 0; i < storages.size(); i++) {
storageNById.put(storages.get(i).getId(), i);
for (Pair<Cargo, Double> p : storages.get(i).getStorageSections()) {
sectionNById.put(new StorageSectionId(true, i, cargoNById.get(p.getKey().getId())), nextStorageNo++);
}
}
nObjWithStorage = movingObjects.size() + storages.size(); nObjWithStorage = movingObjects.size() + storages.size();
{ {
...@@ -689,112 +736,89 @@ public class ConversionUtil { ...@@ -689,112 +736,89 @@ public class ConversionUtil {
/* Ограничения на вместимость. */ /* Ограничения на вместимость. */
private void maxStorageVolume() throws IOException { private void maxStorageVolume() throws IOException {
ArrayList<Integer> maxStorageVol = new ArrayList<>(); ArrayList<Integer> maxStorageVol = integerArray(sectionNById.size(), 0);
for (MovingObject obj : movingObjects) { for (MovingObject obj : movingObjects) {
if (obj instanceof TransportShip) { if (obj instanceof TransportShip) {
maxStorageVol.add((int)Math.ceil(((TransportShip) obj).getCargoMax())); for (Pair<Cargo, Double> p : ((TransportShip) obj).getStorageSections()) {
} else { maxStorageVol.set(sectionNById.get(new StorageSectionId(false,
maxStorageVol.add(0); mObjToN(obj),
cargoNById.get(p.getKey().getId()))),
(int)Math.ceil(p.getValue()));
}
} }
} }
for (Storage storage : storages) { for (Storage storage : storages) {
maxStorageVol.add((int)Math.ceil(storage.getVolume())); for (Pair<Cargo, Double> p : storage.getStorageSections()) {
maxStorageVol.set(sectionNById.get(new StorageSectionId(true,
storageNById.get(storage.getId()),
cargoNById.get(p.getKey().getId()))),
(int)Math.ceil(p.getValue()));
}
} }
writeArray(writer, "max_storage_vol", maxStorageVol, Optional.of(0)); writeArray(writer, "max_storage_vol", maxStorageVol, Optional.of(0));
writer.write("\n"); writer.write("\n");
} }
/* Граничные состояния хранилищ. */ /* Граничные состояния хранилищ. */
private void boundaryStorageStates() throws IOException { private void boundaryStorageStates() throws IOException {
// TODO выделить отдельно общий код. // TODO выделить отдельно общий код.
ArrayList<ArrayList<Integer>> initialStorageVol = new ArrayList<>(); ArrayList<Integer> initialStorageVol = integerArray(sectionNById.size(), 0);
ArrayList<ArrayList<Integer>> finalStorageVol = new ArrayList<>(); ArrayList<Integer> finalStorageVol = integerArray(sectionNById.size(), -1);
for (int i = 0; i <= nObjWithStorage; i++) { BiConsumer<ArrayList<Integer>, StorageState> f = (ArrayList<Integer> a, StorageState st) -> {
initialStorageVol.add(integerArray(cargoes.size() + 1, 0));
finalStorageVol .add(integerArray(cargoes.size() + 1, -1));
}
for (StorageState st : task.getStorageInitialState()) {
int cargoN = cargoNById.get(st.getCargo().getId()); int cargoN = cargoNById.get(st.getCargo().getId());
int val = (int)st.getCargoState(); int val = (int)st.getCargoState();
boolean isRealStorage;
int localN;
if (st.getStorage() instanceof Storage) { if (st.getStorage() instanceof Storage) {
Storage storage = (Storage) st.getStorage(); Storage storage = (Storage) st.getStorage();
int stN = storNById.get(storage.getId()); isRealStorage = true;
initialStorageVol.get(movingObjects.size() + stN + 1).set(cargoN + 1, val); localN = storageNById.get(storage.getId());
} else if (st.getStorage() instanceof TransportShip) { } else {
assert st.getStorage() instanceof TransportShip;
isRealStorage = false;
TransportShip ship = (TransportShip) st.getStorage(); TransportShip ship = (TransportShip) st.getStorage();
initialStorageVol.get(mObjToN(ship) + 1).set(cargoN + 1, val); localN = mObjToN(ship);
} }
int sectionN = sectionNById.get(new StorageSectionId(isRealStorage, localN, cargoN));
a.set(sectionN, val);
};
for (StorageState st : task.getStorageInitialState()) {
f.accept(initialStorageVol, st);
} }
for (StorageState st : task.getStorageEndState()) { for (StorageState st : task.getStorageEndState()) {
int cargoN = cargoNById.get(st.getCargo().getId()); f.accept(finalStorageVol, st);
int val = (int)st.getCargoState();
if (st.getStorage() instanceof Storage) {
Storage storage = (Storage) st.getStorage();
int stN = storNById.get(storage.getId());
finalStorageVol.get(movingObjects.size() + stN + 1).set(cargoN + 1, val);
} else if (st.getStorage() instanceof TransportShip) {
TransportShip ship = (TransportShip) st.getStorage();
finalStorageVol.get(mObjToN(ship) + 1).set(cargoN + 1, val);
}
} }
write2DArrayOfInt(writer, "initial_storage_vol", initialStorageVol, true); writeArray(writer, "initial_storage_vol", initialStorageVol, Optional.of(0));
write2DArrayOfInt(writer, "final_storage_vol", finalStorageVol, true); writeArray(writer, "final_storage_vol", finalStorageVol, Optional.of(-1));
} }
/* Потоки грузов. */ /* Потоки грузов. */
private void cargoFlows() throws IOException { private void cargoFlows() throws IOException {
ArrayList<ArrayList<ArrayList<Integer>>> cargoFlows = new ArrayList<>(); ArrayList<ArrayList<Integer>> cargoFlows = new ArrayList<>();
for (int i = 0; i < nObjWithStorage; i++) { for (int i = 0; i <= sectionNById.size(); i++) {
cargoFlows.add(new ArrayList<>()); cargoFlows.add(integerArray(n_intervals + 2, 0));
for (int j = 0; j < n_intervals + 2; j++) {
cargoFlows.get(i).add(new ArrayList<>());
for (int k = 0; k < cargoes.size(); k++) {
cargoFlows.get(i).get(j).add(0);
}
}
} }
for (CargoFlow flow : task.getCargoFlows()) { for (CargoFlow flow : task.getCargoFlows()) {
int storageN = storNById.get(flow.getStorage().getId()); int storageN = sectionNById.get(new StorageSectionId(true,
int cargoN = cargoNById.get(flow.getCargo().getId()); storageNById.get(flow.getStorage().getId()),
cargoNById.get(flow.getCargo().getId())));
for (int i = 1; i < n_intervals + 2; i++) { for (int i = 1; i < n_intervals + 2; i++) {
cargoFlows.get(storageN + movingObjects.size()).get(i).set(cargoN, (int)flow.getCurrentValue(i - 0.1)); cargoFlows.get(storageN + 1).set(i, (int)flow.getCurrentValue(i - 0.1));
}
}
writer.write("cargo_flows = array3d(0..n_obj_with_storage, 0..(n_intervals + 1), 1..n_cargo_types, [");
boolean isFirst = true;
for (int j = 0; j < n_intervals + 2; j++) {
for (int k = 0; k < cargoes.size(); k++) {
if (isFirst) {
isFirst = false;
} else {
writer.write(", ");
}
writer.write("0");
} }
} }
for (int i = 0; i < nObjWithStorage; i++) { write2DArrayOfInt(writer,"cargo_flows", cargoFlows, true);
for (int j = 0; j < n_intervals + 2; j++) {
for (int k = 0; k < cargoes.size(); k++) {
if (isFirst) {
isFirst = false;
} else {
writer.write(", ");
}
writer.write(cargoFlows.get(i).get(j).get(k).toString());
}
}
}
writer.write("]);\n\n");
} }
/* Грузовые операции со всеми хранилищами. */ /* Грузовые операции со всеми хранилищами. */
private void cargoOperations() throws IOException { private void cargoOperations() throws IOException {
ArrayList<ArrayList<ArrayList<Integer>>> involvedOperations = new ArrayList<>(); ArrayList<ArrayList<Integer>> involvedOperations = new ArrayList<>();
ArrayList<Integer> loadingOpDelta = new ArrayList<>(); ArrayList<Integer> loadingOpDelta = new ArrayList<>();
ArrayList<Integer> loading_op_local_direction = new ArrayList<>(); ArrayList<Integer> loading_op_local_direction = new ArrayList<>();
ArrayList<Integer> loadingOpN = new ArrayList<>(); ArrayList<Integer> loadingOpN = new ArrayList<>();
...@@ -810,35 +834,35 @@ public class ConversionUtil { ...@@ -810,35 +834,35 @@ public class ConversionUtil {
ArrayList<Integer> bunker_of_cargo_op = new ArrayList<>(); ArrayList<Integer> bunker_of_cargo_op = new ArrayList<>();
for (int i = 0; i < nObjWithStorage; i++) { for (int i = 0; i < sectionNById.size(); i++) {
involvedOperations.add(new ArrayList<>()); involvedOperations.add(new ArrayList<>());
for (int j = 0; j < cargoes.size(); j++) {
involvedOperations.get(i).add(new ArrayList<>());
}
} }
for (int i = 0; i < operationTemplates.size(); i++) { for (int i = 0; i < operationTemplates.size(); i++) {
if (operationTemplates.get(i) instanceof LoadingTemplate) { if (operationTemplates.get(i) instanceof LoadingTemplate) {
LoadingTemplate op = (LoadingTemplate) operationTemplates.get(i); LoadingTemplate op = (LoadingTemplate) operationTemplates.get(i);
int shipN = mObjToN(op.getLoader());
int cargoN = cargoNById.get(op.getCargo().getId());
int storageN; int storageN;
if (op.getBunker().isPresent()) { if (op.getBunker().isPresent()) {
storageN = mObjToN(op.getBunker().get()); storageN = sectionNById.get(new StorageSectionId(false, mObjToN(op.getBunker().get()), cargoN));
} else { } else {
storageN = storNById.get(op.getStorage().getId()) + movingObjects.size(); storageN = sectionNById.get(new StorageSectionId(true, storageNById.get(op.getStorage().getId()), cargoN));
} }
int shipN = mObjToN(op.getLoader());
int cargoN = cargoNById.get(op.getCargo().getId()); int shipStorageN = sectionNById.get(new StorageSectionId(false, shipN, cargoN));
loadingOpDelta.add(-(int)op.getIntensity()); loadingOpDelta.add(-(int)op.getIntensity());
loading_op_local_direction.add(-(int)op.getIntensity() > 0 ? 1 : -1); loading_op_local_direction.add(-(int)op.getIntensity() > 0 ? 1 : -1);
loadingOpN.add(i); loadingOpN.add(i);
involvedOperations.get(storageN).get(cargoN).add(loadingOpDelta.size()); involvedOperations.get(storageN).add(loadingOpDelta.size());
loadingOpDelta.add((int)op.getIntensity()); loadingOpDelta.add((int)op.getIntensity());
loading_op_local_direction.add( (int)op.getIntensity() > 0 ? 1 : -1); loading_op_local_direction.add( (int)op.getIntensity() > 0 ? 1 : -1);
loadingOpN.add(i); loadingOpN.add(i);
involvedOperations.get(shipN).get(cargoN).add(loadingOpDelta.size()); involvedOperations.get(shipStorageN).add(loadingOpDelta.size());
loading_op_delta_of_main_obj.add((int)op.getIntensity()); loading_op_delta_of_main_obj.add((int)op.getIntensity());
loading_op_abs_delta.add(Math.abs((int)op.getIntensity())); loading_op_abs_delta.add(Math.abs((int)op.getIntensity()));
...@@ -860,11 +884,9 @@ public class ConversionUtil { ...@@ -860,11 +884,9 @@ public class ConversionUtil {
} }
} }
writer.write("n_loading_op = " + loadingOpDelta.size() + ";\n"); writer.write("n_loading_op = " + loadingOpDelta.size() + ";\n");
if (task.isTypified()) {
write2DArrayOfSet(writer, "involved_operations", involvedOperations); writeArray(writer, "involved_operations", involvedOperations, ConversionUtil::arrayToStringAsSet);
} else {
write2DArrayOfSetAs3DArray(writer, "involved_operations", involvedOperations);
}
writeArray(writer, "loading_op_delta", loadingOpDelta); writeArray(writer, "loading_op_delta", loadingOpDelta);
writeArray(writer, "loading_op_local_direction", loading_op_local_direction); writeArray(writer, "loading_op_local_direction", loading_op_local_direction);
writeArray(writer, "loading_op_n", loadingOpN, (Integer i) -> i + 1); writeArray(writer, "loading_op_n", loadingOpN, (Integer i) -> i + 1);
...@@ -1243,11 +1265,6 @@ public class ConversionUtil { ...@@ -1243,11 +1265,6 @@ public class ConversionUtil {
LoadingTemplate op1 = (LoadingTemplate) operationTemplates.get(i); LoadingTemplate op1 = (LoadingTemplate) operationTemplates.get(i);
LoadingTemplate op2 = (LoadingTemplate) operationTemplates.get(j); LoadingTemplate op2 = (LoadingTemplate) operationTemplates.get(j);
if ((! op1.getWithMooring()) && (! op2.getWithMooring()) &&
(op1.getStartLocation() == op2.getStartLocation()) &&
(op1.getLoader() != op2.getLoader())) {
conflictingOperationsG.get(i).add(j + 1);
}
if ((! op1.getWithMooring()) && (! op2.getWithMooring()) && if ((! op1.getWithMooring()) && (! op2.getWithMooring()) &&
(op1.getStartLocation() == op2.getStartLocation()) && (op1.getStartLocation() == op2.getStartLocation()) &&
(op1.getBunker().isPresent()) && (op2.getBunker().isPresent())) { (op1.getBunker().isPresent()) && (op2.getBunker().isPresent())) {
...@@ -1504,7 +1521,7 @@ public class ConversionUtil { ...@@ -1504,7 +1521,7 @@ public class ConversionUtil {
cargoOpUsingObj(); cargoOpUsingObj();
addOpWithNominallyMooring(); addOpWithNominallyMooring();
writer.write("n_obj_with_storage = " + nObjWithStorage + ";\n"); writer.write("n_all_storage_sections = " + sectionNById.size() + ";\n");
writer.write("n_cargo_types = " + cargoes.size() + ";\n"); writer.write("n_cargo_types = " + cargoes.size() + ";\n");
maxStorageVolume(); maxStorageVolume();
...@@ -1659,7 +1676,7 @@ public class ConversionUtil { ...@@ -1659,7 +1676,7 @@ public class ConversionUtil {
for (String val : opStatus.get(opNo)) { for (String val : opStatus.get(opNo)) {
if (val.equals("true") && (templates.get(opNo - 1) instanceof LoadingTemplate)) { if (val.equals("true") && (templates.get(opNo - 1) instanceof LoadingTemplate)) {
LoadingTemplate op = (LoadingTemplate)templates.get(opNo - 1); LoadingTemplate op = (LoadingTemplate)templates.get(opNo - 1);
cargoOpIntensity.get(opNo).add(Integer.toString((int)Math.ceil(op.getIntensity()))); cargoOpIntensity.get(opNo).add(Integer.toString((int)Math.ceil(Math.abs(op.getIntensity()))));
} else { } else {
cargoOpIntensity.get(opNo).add("0"); cargoOpIntensity.get(opNo).add("0");
} }
......
...@@ -5,16 +5,33 @@ import java.util.ArrayList; ...@@ -5,16 +5,33 @@ import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function;
import static inport.Testing.*; import static inport.Testing.*;
import static inport.Testing.solveTaskWithPartialCargoOp;
import inport.ConversionUtil.*; import inport.ConversionUtil.*;
public class Main { public class Main {
static final int DEFAULT_TIME_LIMIT_S = 1; private static final int DEFAULT_TIME_LIMIT_S = 3600;
private enum ConversionType {
Undefined (""),
WithoutSplitting("Without splitting"),
WithSplitting ("With splitting");
private final String text;
ConversionType(String text) {
this.text = text;
}
public static ConversionType fromString(String text) {
for (ConversionType t : ConversionType.values()) {
if (t.text.equalsIgnoreCase(text)) {
return t;
}
}
return Undefined;
}
}
public static void main(String[] args) { public static void main(String[] args) {
if (args.length == 0) { if (args.length == 0) {
...@@ -40,7 +57,37 @@ public class Main { ...@@ -40,7 +57,37 @@ public class Main {
if (!task.isTypified()) { if (!task.isTypified()) {
error = solveTask_1(task, DEFAULT_TIME_LIMIT_S); error = solveTask_1(task, DEFAULT_TIME_LIMIT_S);
} else { } else {
error = solveTask_2(task, DEFAULT_TIME_LIMIT_S); ConversionType t = (args.length == 2) ? ConversionType.WithoutSplitting
: ConversionType.fromString(args[2]);
String constraintName;
switch (t) {
case WithSplitting:
constraintName = "conversion_2_with_partial_cargo_operations.mzn";
break;
case WithoutSplitting:
constraintName = "conversion_2.mzn";
break;
default:
System.out.println("Undefined conversion type - \"" + args[2] + "\".");
ArrayList<String> values = new ArrayList<>();
for (ConversionType conversionType : ConversionType.values()) {
if (! conversionType.equals(ConversionType.Undefined)) {
values.add("\"" + conversionType.text + "\"");
}
}
System.out.print("Conversion type can be one of " + String.join(", ", values) + ".");
return;
}
error = solveTask(
task,
constraintName,
ConversionUtil::portToMiniZinc_2,
ConversionUtil::resolveMiniZincResults,
DEFAULT_TIME_LIMIT_S);
} }
long finish = System.currentTimeMillis(); long finish = System.currentTimeMillis();
...@@ -102,9 +149,16 @@ public class Main { ...@@ -102,9 +149,16 @@ public class Main {
debug(Testing::solveTaskWithPartialCargoOp, DEFAULT_TIME_LIMIT_S); debug(Testing::solveTaskWithPartialCargoOp, DEFAULT_TIME_LIMIT_S);
break; break;
} }
case "debug read-write" : {
debugReadWrite();
break;
}
case "testing" : case "testing" :
test_2(DEFAULT_TIME_LIMIT_S); test_2(DEFAULT_TIME_LIMIT_S);
break; break;
case "test_experiment":
testGroup("experiments", Testing::solveTask_2, DEFAULT_TIME_LIMIT_S);
break;
case "testing_with_partial_op": case "testing_with_partial_op":
testWithPartialOp(DEFAULT_TIME_LIMIT_S); testWithPartialOp(DEFAULT_TIME_LIMIT_S);
break; break;
...@@ -161,6 +215,19 @@ public class Main { ...@@ -161,6 +215,19 @@ public class Main {
debugInfo(task, solverResults, output); debugInfo(task, solverResults, output);
} }
private static void debugReadWrite() {
String fileName = "experiment/in.ipp";
TaskCase task = new TaskCase();
try {
task.deserialize(fileName);
} catch (IOException e) {
System.out.println(e.getMessage());
return;
}
task.serialize(fileName);
}
private static void debugInfo(TaskCase task, String solverResults, String output) { private static void debugInfo(TaskCase task, String solverResults, String output) {
try (FileInputStream fstream = new FileInputStream(solverResults)) { try (FileInputStream fstream = new FileInputStream(solverResults)) {
BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
*/ */
package inport; package inport;
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
/** /**
...@@ -13,44 +16,13 @@ import java.util.Map; ...@@ -13,44 +16,13 @@ import java.util.Map;
public class Storage { public class Storage {
private int id; private int id;
private String name; private String name;
private double volume; private ArrayList<Pair<Cargo, Double>> storageSections = new ArrayList<>();
private Cargo cargo;
/**
* Get the value of cargo
*
* @return the value of cargo
*/
public Cargo getCargo() {
return cargo;
}
/**
* Set the value of cargo
*
* @param cargo new value of cargo
*/
public void setCargo(Cargo cargo) {
this.cargo = cargo;
}
public ArrayList<Pair<Cargo, Double>> getStorageSections() {
/** return storageSections;
* Get the value of volume
*
* @return the value of volume
*/
public double getVolume() {
return volume;
} }
public void setStorageSections(ArrayList<Pair<Cargo, Double>> storageSections) {
/** this.storageSections = storageSections;
* Set the value of volume
*
* @param volume new value of volume
*/
public void setVolume(double volume) {
this.volume = volume;
} }
/** /**
...@@ -89,11 +61,10 @@ public class Storage { ...@@ -89,11 +61,10 @@ public class Storage {
this.id = id; this.id = id;
} }
public Storage(int id, String name, double volume, Cargo cargo) { public Storage(int id, String name, double volume, ArrayList<Pair<Cargo, Double>> storageSections) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.volume = volume; this.storageSections = storageSections;
this.cargo = cargo;
} }
public Storage() { public Storage() {
...@@ -101,15 +72,38 @@ public class Storage { ...@@ -101,15 +72,38 @@ public class Storage {
@Override @Override
public String toString() { public String toString() {
return id + "; " + name + "; " + cargo.getId() + "; " + volume; return id + "; " + name + "; " + storageSectionsToString(storageSections);
} }
public Storage(String s, Map<Integer, Cargo> cargoes) { public Storage(String s, Map<Integer, Cargo> cargoes) {
String[] tokens = s.split(";"); String[] tokens = s.split(";");
id = Integer.parseInt(tokens[0].trim()); id = Integer.parseInt(tokens[0].trim());
name = tokens[1].trim(); name = tokens[1].trim();
volume = Double.parseDouble(tokens[3].trim()); storageSections = storageSectionsFromString(tokens[2], cargoes);
int key = Integer.parseInt(tokens[2].trim()); }
cargo = cargoes.get(key);
static String storageSectionsToString(ArrayList<Pair<Cargo, Double>> storageSections) {
ArrayList<String> sections = new ArrayList<>();
for (Pair<Cargo, Double> p : storageSections) {
sections.add("(" + p.getKey().getId() + ", " + p.getValue() + ")");
}
return "[" + String.join(", ",sections) + "]";
}
static ArrayList<Pair<Cargo, Double>> storageSectionsFromString(String str, Map<Integer, Cargo> cargoes) {
ArrayList<Pair<Cargo, Double>> storageSections = new ArrayList<>();
String sections = str.substring(str.indexOf('[') + 1, str.indexOf(']'));
for (int pos = 0; pos < sections.length(); ) {
int p1 = sections.indexOf('(', pos);
int p2 = sections.indexOf(')', pos);
if ((p1 >= 0) && (p2 >= 0) && (p1 < p2)) {
int type = Integer.parseInt(sections.substring(p1 + 1, sections.indexOf(',', p1)).trim());
double cargoMax = Double.parseDouble(sections.substring(sections.indexOf(',', p1) + 1, p2).trim());
storageSections.add(new Pair<>(cargoes.get(type), cargoMax));
pos = p2 + 1;
} else {
break;
}
}
return storageSections;
} }
} }
...@@ -523,7 +523,7 @@ public class TaskCase { ...@@ -523,7 +523,7 @@ public class TaskCase {
equipmentTypes.put(Integer.parseInt(tokens[0].trim()), tokens[1].trim()); equipmentTypes.put(Integer.parseInt(tokens[0].trim()), tokens[1].trim());
break; break;
case Bunkers: case Bunkers:
Bunker bunker = new Bunker(strLine); Bunker bunker = new Bunker(strLine, m_cargo);
bunkers.add(bunker); bunkers.add(bunker);
m_bunker.put(bunker.getId(), bunker); m_bunker.put(bunker.getId(), bunker);
break; break;
...@@ -535,7 +535,7 @@ public class TaskCase { ...@@ -535,7 +535,7 @@ public class TaskCase {
break; break;
case Loading_Equipments: LoadingEquipment l = new LoadingEquipment(strLine); equipments.add(l); m_equipment.put(l.getId(), l); m_vessel.put(l.getId(), l); case Loading_Equipments: LoadingEquipment l = new LoadingEquipment(strLine); equipments.add(l); m_equipment.put(l.getId(), l); m_vessel.put(l.getId(), l);
break; break;
case Transport_Ships: TransportShip ts = new TransportShip(strLine); ships.add(ts); m_vessel.put(ts.getId(), ts); case Transport_Ships: TransportShip ts = new TransportShip(strLine, m_cargo); ships.add(ts); m_vessel.put(ts.getId(), ts);
break; break;
case Templates: tokens = strLine.split(";"); case Templates: tokens = strLine.split(";");
if (tokens[1].trim().equals("mov")) if (tokens[1].trim().equals("mov"))
...@@ -1400,7 +1400,7 @@ public class TaskCase { ...@@ -1400,7 +1400,7 @@ public class TaskCase {
writer.write("* Current Storage Volume Constraints \n"); writer.write("* Current Storage Volume Constraints \n");
for (Storage st : storages) for (Storage st : storages)
{ {
int V = (int)st.getVolume(); int V = (int) (double) st.getStorageSections().get(0).getValue();
double V0 = 0; double V0 = 0;
for (StorageState sst : storageInitialState) for (StorageState sst : storageInitialState)
if (sst.getStorage().equals(st)) if (sst.getStorage().equals(st))
...@@ -1737,7 +1737,7 @@ public class TaskCase { ...@@ -1737,7 +1737,7 @@ public class TaskCase {
{ {
int i = templates.indexOf(tp); int i = templates.indexOf(tp);
LoadingTemplate ltp = (LoadingTemplate)tp; LoadingTemplate ltp = (LoadingTemplate)tp;
if (ltp.getLoader().equals(s) && ltp.getStorage().getCargo().equals(c)) if (ltp.getLoader().equals(s) && ltp.getStorage().getStorageSections().get(0).getKey().equals(c))
{ {
vc.add(i); vc.add(i);
int itsv = (int)ltp.getIntensity(); int itsv = (int)ltp.getIntensity();
...@@ -1779,7 +1779,7 @@ public class TaskCase { ...@@ -1779,7 +1779,7 @@ public class TaskCase {
nCons++; nCons++;
} }
// Ограничение на грузоподъемность судна // Ограничение на грузоподъемность судна
int maxLoad = (int)(s.getCargoMax()+1.0); int maxLoad = (int)(s.getStorageSections().get(0).getValue() + 1.0);
if (sumplus > (maxLoad - start)) if (sumplus > (maxLoad - start))
{ {
writer.write(clause + " <= " + (maxLoad - start + epsilon) + " ;\n"); writer.write(clause + " <= " + (maxLoad - start + epsilon) + " ;\n");
......
package inport; package inport;
import javafx.util.Pair;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -260,7 +262,11 @@ public class Testing { ...@@ -260,7 +262,11 @@ public class Testing {
} }
} }
for (TransportShip ship : taskCase.getShips()) { for (TransportShip ship : taskCase.getShips()) {
ship.setCargoMax(ship.getCargoMax() * mult); ArrayList<Pair<Cargo, Double>> sections = new ArrayList<>();
for (Pair<Cargo, Double> p : ship.getStorageSections()) {
sections.add(new Pair<>(p.getKey(), p.getValue() * mult));
}
ship.setStorageSections(sections);
} }
for (StorageState state : taskCase.getStorageInitialState()) { for (StorageState state : taskCase.getStorageInitialState()) {
state.setCargoState(state.getCargoState() * mult); state.setCargoState(state.getCargoState() * mult);
...@@ -269,7 +275,11 @@ public class Testing { ...@@ -269,7 +275,11 @@ public class Testing {
state.setCargoState(state.getCargoState() * mult); state.setCargoState(state.getCargoState() * mult);
} }
for (Storage storage : taskCase.getStorages()) { for (Storage storage : taskCase.getStorages()) {
storage.setVolume(storage.getVolume() * mult); ArrayList<Pair<Cargo, Double>> sections = new ArrayList<>();
for (Pair<Cargo, Double> p : storage.getStorageSections()) {
sections.add(new Pair<>(p.getKey(), p.getValue() * mult));
}
storage.setStorageSections(sections);
} }
for (Operation operation : taskCase.getSolution()) { for (Operation operation : taskCase.getSolution()) {
final double m = mult; final double m = mult;
......
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
*/ */
package inport; package inport;
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.Map;
import java.util.OptionalInt; import java.util.OptionalInt;
/** /**
...@@ -11,20 +15,20 @@ import java.util.OptionalInt; ...@@ -11,20 +15,20 @@ import java.util.OptionalInt;
* @author topazh_ag * @author topazh_ag
*/ */
public class TransportShip extends MovingObject { public class TransportShip extends MovingObject {
private double cargoMax;
public double getCargoMax() { private ArrayList<Pair<Cargo, Double>> storageSections = new ArrayList<>();
return cargoMax;
public ArrayList<Pair<Cargo, Double>> getStorageSections() {
return storageSections;
} }
public void setCargoMax(double cargoMax) { public void setStorageSections(ArrayList<Pair<Cargo, Double>> storageSections) {
this.cargoMax = cargoMax; this.storageSections = storageSections;
} }
public TransportShip(int id, String name, double cargoMax) { public TransportShip(int id, String name, ArrayList<Pair<Cargo, Double>> storageSections) {
super(id, name); super(id, name);
this.cargoMax = cargoMax; this.storageSections = storageSections;
} }
public TransportShip() { public TransportShip() {
...@@ -32,17 +36,20 @@ public class TransportShip extends MovingObject { ...@@ -32,17 +36,20 @@ public class TransportShip extends MovingObject {
@Override @Override
public String toString() { public String toString() {
String res = getId() + "; " + getName() + "; " + cargoMax; String res = getId() + "; " + getName() + "; " + Storage.storageSectionsToString(storageSections);
if (getType().isPresent()) { if (getType().isPresent()) {
res += "; " + getType().getAsInt(); res += "; " + getType().getAsInt();
} }
return res; return res;
} }
public TransportShip(String s) { public TransportShip(String s, Map<Integer, Cargo> cargoes) {
super(s); super(s);
String[] tokens = s.split(";"); String[] tokens = s.split(";");
cargoMax = Double.parseDouble(tokens[2].trim());
storageSections = Storage.storageSectionsFromString(tokens[2], cargoes);
if (tokens.length >= 4) { if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim()))); setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
} }
......
...@@ -14,9 +14,9 @@ Berths ...@@ -14,9 +14,9 @@ Berths
1; Бункеровочный терминал Горская 1; Бункеровочный терминал Горская
Storages Storages
2001; Гоское хранилище СПГ; 10002; 1000000 2001; Гоское хранилище СПГ; [(10002, 1000000)]
2002; Хранилище СПГ Кировского завода; 10002; 1000000 2002; Хранилище СПГ Кировского завода; [(10002, 1000000)]
2003; Нефтехранилище; 10001; 1000000 2003; Нефтехранилище; [(10001, 1000000)]
Vessel Types Vessel Types
1002; Буксиры 1002; Буксиры
...@@ -26,17 +26,17 @@ Bunker Types ...@@ -26,17 +26,17 @@ Bunker Types
1001; Бункеровщики 1001; Бункеровщики
Bunkers Bunkers
11; Бункеровщик 1; 3000; 1001 11; Бункеровщик 1; [(10002, 3000)]; 1001
12; Бункеровщик 2; 3000; 1001 12; Бункеровщик 2; [(10002, 3000)]; 1001
13; Бункеровщик 3; 3000; 1001 13; Бункеровщик 3; [(10002, 3000)]; 1001
14; Бункеровщик 4; 3000; 1001 14; Бункеровщик 4; [(10002, 3000)]; 1001
Tows Tows
21; Буксир 1; 0; 1002 21; Буксир 1; []; 1002
22; Буксир 2; 0; 1002 22; Буксир 2; []; 1002
23; Буксир 3; 0; 1002 23; Буксир 3; []; 1002
24; Буксир 4; 0; 1002 24; Буксир 4; []; 1002
25; Буксир 5; 0; 1002 25; Буксир 5; []; 1002
Loading Equipment Types Loading Equipment Types
1004; Насосы 1004; Насосы
...@@ -45,14 +45,14 @@ Loading Equipments ...@@ -45,14 +45,14 @@ Loading Equipments
41; Насос 1; 1004 41; Насос 1; 1004
Transport Ships Transport Ships
31; Танкер 1; 45000; 1003 31; Танкер 1; [(10001, 45000), (10002, 4500)]; 1003
32; Танкер 2; 45000; 1003 32; Танкер 2; [(10001, 45000), (10002, 4500)]; 1003
33; Танкер 3; 45000; 1003 33; Танкер 3; [(10001, 45000), (10002, 4500)]; 1003
34; Танкер 4; 45000; 1003 34; Танкер 4; [(10001, 45000), (10002, 4500)]; 1003
35; Танкер 5; 45000; 1003 35; Танкер 5; [(10001, 45000), (10002, 4500)]; 1003
36; Танкер 6; 45000; 1003 36; Танкер 6; [(10001, 45000), (10002, 4500)]; 1003
37; Танкер 7; 45000; 1003 37; Танкер 7; [(10001, 45000), (10002, 4500)]; 1003
38; Танкер 8; 45000; 1003 38; Танкер 8; [(10001, 45000), (10002, 4500)]; 1003
Templates Templates
......
...@@ -10,22 +10,22 @@ Berths ...@@ -10,22 +10,22 @@ Berths
367; Терминал1 367; Терминал1
368; Терминал2 368; Терминал2
Storages Storages
369; Хранилище1; 363; 400 369; Хранилище1; [(363, 400)]
370; Хранилище2; 364; 400 370; Хранилище2; [(364, 400)]
371; Хранилище3; 365; 400 371; Хранилище3; [(365, 400)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
1002; Тип буксира1 1002; Тип буксира1
Tows Tows
374; Буксир1; 10000; 1002 374; Буксир1; []; 1002
375; Буксир2; 10000; 1002 375; Буксир2; []; 1002
376; Буксир3; 10000; 1002 376; Буксир3; []; 1002
Transport Ships Transport Ships
377; Судно1; 400; 1001 377; Судно1; [(363, 400), (364, 400), (365, 400)]; 1001
378; Судно2; 400; 1001 378; Судно2; [(363, 400), (364, 400), (365, 400)]; 1001
379; Судно3; 400; 1001 379; Судно3; [(363, 400), (364, 400), (365, 400)]; 1001
Loading Equipment Types Loading Equipment Types
1003; Тип насоса1 1003; Тип насоса1
......
...@@ -11,7 +11,7 @@ Berths ...@@ -11,7 +11,7 @@ Berths
3; Pier 2 3; Pier 2
Storages Storages
4; Storage 1; 10001; 10000.0 4; Storage 1; [(10001, 10000.0)]
Vessel Types Vessel Types
1001; Тип судна 1 1001; Тип судна 1
...@@ -20,8 +20,8 @@ Bunker Types ...@@ -20,8 +20,8 @@ Bunker Types
2001; Тип бункировщика 1 2001; Тип бункировщика 1
Bunkers Bunkers
201; Bunker 1; 2000.0; 2001 201; Bunker 1; [(10002, 2000.0)]; 2001
202; Bunker 2; 2000.0; 2001 202; Bunker 2; [(10002, 2000.0)]; 2001
Tows Tows
...@@ -30,8 +30,8 @@ Loading Equipment Types ...@@ -30,8 +30,8 @@ Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
101; Ship 1; 2000.0; 1001 101; Ship 1; [(10001, 2000.0), (10002, 200.0)]; 1001
102; Ship 2; 2000.0; 1001 102; Ship 2; [(10001, 2000.0), (10002, 200.0)]; 1001
Templates Templates
7; mov; []; 1001; 1; 2; []; 1.0 7; mov; []; 1001; 1; 2; []; 1.0
......
...@@ -10,7 +10,7 @@ Berths ...@@ -10,7 +10,7 @@ Berths
316; Терминал2 316; Терминал2
Storages Storages
317; Хранилище1; 313; 270.0 317; Хранилище1; [(313, 270.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -19,7 +19,7 @@ Vessel Types ...@@ -19,7 +19,7 @@ Vessel Types
Bunkers Bunkers
Tows Tows
320; Буксир1; 1000000; 1002 320; Буксир1; []; 1002
Loading Equipment Types Loading Equipment Types
1003; Кран 1003; Кран
...@@ -28,7 +28,7 @@ Loading Equipments ...@@ -28,7 +28,7 @@ Loading Equipments
323; Плавучий кран; 1003 323; Плавучий кран; 1003
Transport Ships Transport Ships
321; Судно1; 1000000.0; 1001 321; Судно1; [(313, 1000000.0)]; 1001
Templates Templates
8; mov; []; 1002; 314; 316; []; 1.0 8; mov; []; 1002; 314; 316; []; 1.0
......
...@@ -12,9 +12,9 @@ Berths ...@@ -12,9 +12,9 @@ Berths
88; Терминал2 88; Терминал2
Storages Storages
89; Хранилище1; 83; 1000.0 89; Хранилище1; [(83, 100.0)]
90; Хранилище2; 84; 1000.0 90; Хранилище2; [(84, 100.0)]
91; Хранилище3; 85; 1000.0 91; Хранилище3; [(85, 100.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -23,8 +23,8 @@ Vessel Types ...@@ -23,8 +23,8 @@ Vessel Types
Bunkers Bunkers
Tows Tows
94; Буксир1; 1000000; 1002 94; Буксир1; []; 1002
95; Буксир2; 1000000; 1002 95; Буксир2; []; 1002
Loading Equipment Types Loading Equipment Types
1003; Тип крана 1 1003; Тип крана 1
...@@ -37,7 +37,7 @@ Loading Equipments ...@@ -37,7 +37,7 @@ Loading Equipments
101; Плавучий кран 3; 1005 101; Плавучий кран 3; 1005
Transport Ships Transport Ships
96; Судно1; 1000000.0; 1001 96; Судно1; [(83, 1000.0), (84, 1000.0), (85, 1000.0)]; 1001
Templates Templates
10; mrn; []; 1001; 88; [1002,1002]; 1.0 10; mrn; []; 1001; 88; [1002,1002]; 1.0
...@@ -46,10 +46,10 @@ Templates ...@@ -46,10 +46,10 @@ Templates
15; mov; []; 1002; 87; 86; []; 1.0 15; mov; []; 1002; 87; 86; []; 1.0
11; mov; []; 1002; 88; 86; []; 1.0 11; mov; []; 1002; 88; 86; []; 1.0
8; mov; []; 1001; 86; 88; [1002]; 2.0 8; mov; []; 1001; 86; 88; [1002]; 2.0
2; loa; []; 1001; 83; 89; 88; [1003, 1004]; 20.0; M 2; loa; []; 1001; 83; 89; 88; [1003, 1004]; 2.0; M
4; loa; []; 1001; 84; 90; 88; [1003, 1005]; 10.0; M 4; loa; []; 1001; 84; 90; 88; [1003, 1005]; 1.0; M
5; loa; []; 1001; 84; 90; 88; [1004, 1005]; 10.0; M 5; loa; []; 1001; 84; 90; 88; [1004, 1005]; 1.0; M
7; loa; []; 1001; 85; 91; 88; [1005]; 10.0; M 7; loa; []; 1001; 85; 91; 88; [1005]; 1.0; M
Cargo Flows Cargo Flows
...@@ -65,9 +65,9 @@ Initial Storage State ...@@ -65,9 +65,9 @@ Initial Storage State
83; 89; 0.0 83; 89; 0.0
84; 90; 0.0 84; 90; 0.0
85; 91; 0.0 85; 91; 0.0
83; 96; 60.0 83; 96; 6.0
84; 96; 60.0 84; 96; 6.0
85; 96; 60.0 85; 96; 6.0
Final Vessel State Final Vessel State
...@@ -78,7 +78,7 @@ Final Storage State ...@@ -78,7 +78,7 @@ Final Storage State
Task Properties Task Properties
25.0; 0 26.0; 0
Solution Solution
......
...@@ -10,7 +10,7 @@ Berths ...@@ -10,7 +10,7 @@ Berths
3; Pier 2 3; Pier 2
Storages Storages
4; Storage 1; 0; 1000.0 4; Storage 1; [(0, 1000.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -24,8 +24,8 @@ Loading Equipment Types ...@@ -24,8 +24,8 @@ Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
5; Ship 1; 200.0; 1001 5; Ship 1; [(0, 200.0)]; 1001
6; Ship 2; 200.0; 1001 6; Ship 2; [(0, 200.0)]; 1001
Templates Templates
7; mov; []; 1001; 1; 2; []; 1.0 7; mov; []; 1001; 1; 2; []; 1.0
......
...@@ -10,7 +10,7 @@ Berths ...@@ -10,7 +10,7 @@ Berths
3; Pier 2 3; Pier 2
Storages Storages
4; Storage 1; 0; 270.0 4; Storage 1; [(0, 270.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -19,7 +19,7 @@ Vessel Types ...@@ -19,7 +19,7 @@ Vessel Types
Bunkers Bunkers
Tows Tows
6; Tow 1; 1000000; 1002 6; Tow 1; []; 1002
Loading Equipment Types Loading Equipment Types
1003; Кран 1003; Кран
...@@ -28,7 +28,7 @@ Loading Equipments ...@@ -28,7 +28,7 @@ Loading Equipments
5; Плавучий кран; 1003 5; Плавучий кран; 1003
Transport Ships Transport Ships
7; Ship 1; 2000.0; 1001 7; Ship 1; [(0, 2000.0)]; 1001
Templates Templates
8; mov; []; 1001; 1; 2; [1002]; 2.0 8; mov; []; 1001; 1; 2; [1002]; 2.0
......
...@@ -10,7 +10,7 @@ Berths ...@@ -10,7 +10,7 @@ Berths
3; Pier 2 3; Pier 2
Storages Storages
4; Storage 1; 0; 1000.0 4; Storage 1; [(0, 200)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -26,8 +26,8 @@ Loading Equipment Types ...@@ -26,8 +26,8 @@ Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
5; Ship 1; 200.0; 1001 5; Ship 1; [(0, 40.0)]; 1001
6; Ship 2; 200.0; 1001 6; Ship 2; [(0, 40.0)]; 1001
Templates Templates
7; mov; []; 1001; 1; 2; []; 1.0 7; mov; []; 1001; 1; 2; []; 1.0
...@@ -36,8 +36,8 @@ Templates ...@@ -36,8 +36,8 @@ Templates
10; mov; []; 1001; 3; 1; []; 1.0 10; mov; []; 1001; 3; 1; []; 1.0
11; mov; []; 1001; 2; 3; []; 1.0 11; mov; []; 1001; 2; 3; []; 1.0
12; mov; []; 1001; 3; 2; []; 1.0 12; mov; []; 1001; 3; 2; []; 1.0
19; loa; []; 4; 0; 1001; 2; []; 10.0; U 19; loa; []; 4; 0; 1001; 2; []; 2.0; U
20; loa; []; 4; 0; 1001; 3; []; 5.0; U 20; loa; []; 4; 0; 1001; 3; []; 1.0; U
Cargo Flows Cargo Flows
...@@ -48,15 +48,15 @@ Initial Vessel State ...@@ -48,15 +48,15 @@ Initial Vessel State
Initial Storage State Initial Storage State
0; 5; 0.0 0; 5; 0.0
0; 6; 0.0 0; 6; 0.0
0; 4; 1000.0 0; 4; 200.0
Final Vessel State Final Vessel State
5; 1 5; 1
6; 1 6; 1
Final Storage State Final Storage State
0; 5; 100.0 0; 5; 20.0
0; 6; 100.0 0; 6; 20.0
Task Properties Task Properties
......
...@@ -8,7 +8,7 @@ Berths ...@@ -8,7 +8,7 @@ Berths
86; Рейд 86; Рейд
Storages Storages
89; Хранилище1; 83; 1000.0 89; Хранилище1; [(83, 1000.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -22,8 +22,8 @@ Loading Equipment Types ...@@ -22,8 +22,8 @@ Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
101; Судно1; 1000000.0; 1001 101; Судно1; [(83, 1000000.0)]; 1001
102; Судно2; 1000000.0; 1001 102; Судно2; [(83, 1000000.0)]; 1001
Templates Templates
1; mrn; []; 1001; 86; []; 1.0 1; mrn; []; 1001; 86; []; 1.0
......
...@@ -9,7 +9,7 @@ Berths ...@@ -9,7 +9,7 @@ Berths
2; Pier 1 2; Pier 1
Storages Storages
4; Storage 1; 0; 10000.0 4; Storage 1; [(0, 10000.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -24,8 +24,8 @@ Loading Equipment Types ...@@ -24,8 +24,8 @@ Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
5; Ship 1; 2000.0; 1001 5; Ship 1; [(0, 2000.0)]; 1001
6; Ship 2; 2000.0; 1002 6; Ship 2; [(0, 2000.0)]; 1002
Templates Templates
7; mov; []; 1001; 1; 2; []; 2.0 7; mov; []; 1001; 1; 2; []; 2.0
......
...@@ -9,7 +9,7 @@ Berths ...@@ -9,7 +9,7 @@ Berths
16; Терминал1 16; Терминал1
Storages Storages
18; Хранилище1; 13; 6.0 18; Хранилище1; [(13, 6.0)]
Vessel Types Vessel Types
11; Тип судна1 11; Тип судна1
...@@ -18,18 +18,18 @@ Vessel Types ...@@ -18,18 +18,18 @@ Vessel Types
Bunkers Bunkers
Tows Tows
121; Буксир1; 1000000; 12 121; Буксир1; []; 12
122; Буксир2; 1000000; 12 122; Буксир2; []; 12
123; Буксир3; 1000000; 12 123; Буксир3; []; 12
124; Буксир4; 1000000; 12 124; Буксир4; []; 12
Loading Equipment Types Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
111; Судно1; 1000000.0; 11 111; Судно1; [(13, 1000000.0)]; 11
112; Судно2; 1000000.0; 11 112; Судно2; [(13, 1000000.0)]; 11
Templates Templates
61; mov; []; 11; 10; 16; [12,12]; 1.0 61; mov; []; 11; 10; 16; [12,12]; 1.0
......
...@@ -10,8 +10,8 @@ Berths ...@@ -10,8 +10,8 @@ Berths
19; Терминал2 19; Терминал2
Storages Storages
20; Хранилище1; 22; 100.0 20; Хранилище1; [(22, 100.0)]
21; Хранилище2; 22; 100.0 21; Хранилище2; [(22, 100.0)]
Vessel Types Vessel Types
1001; Тип судна1 1001; Тип судна1
...@@ -22,15 +22,15 @@ Bunker Types ...@@ -22,15 +22,15 @@ Bunker Types
Bunkers Bunkers
Tows Tows
27; Буксир1; 1000000; 1002 27; Буксир1; []; 1002
Loading Equipment Types Loading Equipment Types
Loading Equipments Loading Equipments
Transport Ships Transport Ships
24; Судно1; 100000.0; 1001 24; Судно1; [(22, 100000.0)]; 1001
25; Судно2; 100000.0; 1001 25; Судно2; [(22, 100000.0)]; 1001
Templates Templates
4010; mov; []; 1001; 19; 18; [1002]; 1.0 4010; mov; []; 1001; 19; 18; [1002]; 1.0
......
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