From ba46bb65e1257bb588d51454e79ec7a0e3e35ac2 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: Fri, 1 Feb 2019 16:44:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=B8?= =?UTF-8?q?=20toString()=20=D0=B4=D0=BB=D1=8F=20=D0=BD=D0=BE=D0=B2=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inport/LoadingEquipment.java | 15 +- src/inport/LoadingTemplate.java | 46 +++- src/inport/Main.java | 13 ++ src/inport/MooringTemplate.java | 29 ++- src/inport/MovingObject.java | 21 +- src/inport/MovingTemplate.java | 29 ++- src/inport/TaskCase.java | 372 ++++++++++++++++++++----------- src/inport/Tow.java | 14 +- src/inport/TowUsingTemplate.java | 14 +- src/inport/TransportShip.java | 13 +- 10 files changed, 407 insertions(+), 159 deletions(-) diff --git a/src/inport/LoadingEquipment.java b/src/inport/LoadingEquipment.java index be591e8..ac69354 100644 --- a/src/inport/LoadingEquipment.java +++ b/src/inport/LoadingEquipment.java @@ -4,12 +4,13 @@ */ package inport; +import java.util.OptionalInt; + /** * * @author topazh_ag */ public class LoadingEquipment extends MovingObject{ - public LoadingEquipment() { super(); @@ -21,11 +22,19 @@ public class LoadingEquipment extends MovingObject{ @Override public String toString() { - return getId() + ";" + getName(); + String res = getId() + ";" + getName(); + if (getType().isPresent()) { + res += ";" + getType().getAsInt(); + } + return res; } public LoadingEquipment(String s) { - super(s); + super(s); + String[] tokens = s.split(";"); + if (tokens.length >= 4) { + setType(OptionalInt.of(Integer.parseInt(tokens[3].trim()))); + } } } diff --git a/src/inport/LoadingTemplate.java b/src/inport/LoadingTemplate.java index 6878aae..e62914e 100644 --- a/src/inport/LoadingTemplate.java +++ b/src/inport/LoadingTemplate.java @@ -6,6 +6,7 @@ package inport; import java.util.ArrayList; import java.util.List; +import java.util.OptionalInt; /** * @@ -14,12 +15,21 @@ import java.util.List; public class LoadingTemplate extends OperationTemplate { private TransportShip loader; + private OptionalInt loaderType = OptionalInt.empty(); private Storage storage; private List resources; + private List resourcesTypes; private double intensity; private boolean withMooring; private Cargo cargo; + public OptionalInt getLoaderType() { + return loaderType; + } + public void setLoaderType(OptionalInt loaderType) { + this.loaderType = loaderType; + } + /** * Get the value of resources * @@ -37,7 +47,14 @@ public class LoadingTemplate extends OperationTemplate { public void setResources(List resources) { this.resources = resources; } - + + public List getResourcesTypes() { + return resourcesTypes; + } + public void setResourcesTypes(List resourcesTypes) { + this.resourcesTypes = resourcesTypes; + } + public TransportShip getLoader() { return loader; } @@ -83,32 +100,47 @@ public class LoadingTemplate extends OperationTemplate { this.loader = loader; this.storage = storage; this.resources = new ArrayList<>(); + this.resourcesTypes = new ArrayList<>(); this.intensity = intensity; } public LoadingTemplate() { this.resources = new ArrayList<>(); + this.resourcesTypes = new ArrayList<>(); } @Override public String toString() { String res = ""; boolean first = true; - for(LoadingEquipment eq : resources) - { + for(LoadingEquipment eq : resources) { if (!first) res += "," + eq.getId(); else res += eq.getId(); first = false; } - int source = loader.getId(); + for (Integer t : getResourcesTypes()) { + if (!first) + res += "," + t; + else + res += t; + first = false; + } + int startId; + if (loaderType.isPresent()) { + startId = loaderType.getAsInt(); + } else { + startId = loader.getId(); + } + + int source = startId; if (intensity>0) source = storage.getId(); - int target = loader.getId(); + int target = startId; if (intensity<=0) target = storage.getId(); - return getId() + ";" + "loa;" + twtoString() + ";" + source + ";" + cargo.getId() + ";" + target + ";" - + getStartLocation().getId() + ";[" + res +"];" + Math.abs(intensity) + ";" + (withMooring ? "M" : "U"); + return getId() + "; " + "loa; " + twtoString() + "; " + source + "; " + cargo.getId() + "; " + target + "; " + + getStartLocation().getId() + "; [" + res +"]; " + Math.abs(intensity) + "; " + (withMooring ? "M" : "U"); } } diff --git a/src/inport/Main.java b/src/inport/Main.java index d25127a..915d413 100644 --- a/src/inport/Main.java +++ b/src/inport/Main.java @@ -118,6 +118,19 @@ public class Main { } break; } + case "debug" : { + String fileName = args[1]; + String output = args[2]; + + TaskCase task = new TaskCase(); + try { + task.deserialize(fileName); + task.serialize(output); + } catch (IOException e) { + System.out.println(e.getMessage()); + } + break; + } default: System.out.println("Unknown type \"" + type + "\""); } diff --git a/src/inport/MooringTemplate.java b/src/inport/MooringTemplate.java index a496339..b23ca85 100644 --- a/src/inport/MooringTemplate.java +++ b/src/inport/MooringTemplate.java @@ -4,6 +4,8 @@ */ package inport; +import java.util.OptionalInt; + /** * * @author topazh_ag @@ -11,8 +13,16 @@ package inport; public class MooringTemplate extends TowUsingTemplate { private TransportShip moorer; + private OptionalInt moorerType = OptionalInt.empty(); private boolean direct; + public OptionalInt getMoorerType() { + return moorerType; + } + public void setMoorerType(OptionalInt moorerType) { + this.moorerType = moorerType; + } + /** * Get the value of direction * @@ -63,18 +73,31 @@ public class MooringTemplate extends TowUsingTemplate { public String toString() { String res = ""; boolean first = true; - for(Tow eq : getResources()) - { + for(Tow eq : getResources()) { if (!first) res += "," + eq.getId(); else res += eq.getId(); first = false; } + for (Integer t : getResourcesTypes()) { + if (!first) + res += "," + t; + else + res += t; + first = false; + } String code = "mrn"; if (!direct) code = "unm"; - return getId() + ";" + code + ";" + twtoString() + ";" + moorer.getId() + ";" + getStartLocation().getId() + ";[" + res +"];"+getDuration(); + + String result = getId() + "; " + code + "; " + twtoString() + "; "; + if (moorerType.isPresent()) { + result += moorerType.getAsInt(); + } else { + result += moorer.getId(); + } + return result + "; " + getStartLocation().getId() + "; [" + res +"]; "+getDuration(); } } diff --git a/src/inport/MovingObject.java b/src/inport/MovingObject.java index a0adedc..e925b16 100644 --- a/src/inport/MovingObject.java +++ b/src/inport/MovingObject.java @@ -4,6 +4,8 @@ */ package inport; +import java.util.OptionalInt; + /** * * @author topazh_ag @@ -12,6 +14,7 @@ public class MovingObject { private int id; private String name; + private OptionalInt type; /** * Get the value of name @@ -49,18 +52,34 @@ public class MovingObject { this.id = id; } + public OptionalInt getType() { + return type; + } + public void setType(OptionalInt type) { + this.type = type; + } + public MovingObject(int id, String name) { this.id = id; this.name = name; + this.type = OptionalInt.empty(); + } + + public MovingObject(int id, String name, int typeId) { + this.id = id; + this.name = name; + this.type = OptionalInt.of(typeId); } public MovingObject() { + type = OptionalInt.empty(); } public MovingObject(String s) { String[] tokens = s.split(";"); id = Integer.parseInt(tokens[0].trim()); - name = tokens[1].trim(); + name = tokens[1].trim(); + type = OptionalInt.empty(); } } diff --git a/src/inport/MovingTemplate.java b/src/inport/MovingTemplate.java index 80063e6..434d5fe 100644 --- a/src/inport/MovingTemplate.java +++ b/src/inport/MovingTemplate.java @@ -4,6 +4,8 @@ */ package inport; +import java.util.OptionalInt; + /** * * @author topazh_ag @@ -11,6 +13,7 @@ package inport; public class MovingTemplate extends TowUsingTemplate { private MovingObject mover; + private OptionalInt moverType; private Berth destination; @@ -50,6 +53,13 @@ public class MovingTemplate extends TowUsingTemplate { this.mover = mover; } + public OptionalInt getMoverType() { + return moverType; + } + public void setMoverType(OptionalInt moverType) { + this.moverType = moverType; + } + public MovingTemplate(MovingObject mover, Berth source, Berth destination, double duration, int id) { super(duration, id, source); this.mover = mover; @@ -64,15 +74,28 @@ public class MovingTemplate extends TowUsingTemplate { public String toString() { String res = ""; boolean first = true; - for(Tow eq : getResources()) - { + for(Tow eq : getResources()) { if (!first) res += "," + eq.getId(); else res += eq.getId(); first = false; } - return getId() + ";" + "mov;" + twtoString() + ";" + mover.getId() + ";" + getStartLocation().getId() + ";" + destination.getId() + ";[" + res +"];"+getDuration(); + for (Integer t : getResourcesTypes()) { + if (!first) + res += "," + t; + else + res += t; + first = false; + } + + String result = getId() + "; " + "mov; " + twtoString() + "; "; + if (getMoverType().isPresent()) { + result += getMoverType().getAsInt(); + } else { + result += mover.getId(); + } + return result + "; " + getStartLocation().getId() + "; " + destination.getId() + "; [" + res +"]; "+getDuration(); } diff --git a/src/inport/TaskCase.java b/src/inport/TaskCase.java index 0da26c7..fd05e8f 100644 --- a/src/inport/TaskCase.java +++ b/src/inport/TaskCase.java @@ -11,11 +11,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; +import java.util.function.BiFunction; import java.util.logging.Level; import java.util.logging.Logger; @@ -24,18 +21,26 @@ import java.util.logging.Logger; * @author topazh_ag */ public class TaskCase { - + // С типизацией ли + private boolean typified = false; + // Статическая структура порта - private List cargoes; + private List cargoes; private List berths; - private List storages; + private List storages; private List bunkers; private List tows; private List equipments; - + // Обслуживаемые суда private List ships; - + + // Типы обслуживаемых судов + private Map vesselTypes; + + // Типы обслуживаемого оборудования. + private Map equipmentTypes; + // Шаблоны операций private List templates; @@ -349,15 +354,40 @@ public class TaskCase { this.berths = berths; } + public void setVesselTypes(Map vesselTypes) { + this.vesselTypes = vesselTypes; + } + public Map getVesselTypes() { + return vesselTypes; + } + + public void setEquipmentTypes(Map equipmentTypes) { + this.equipmentTypes = equipmentTypes; + } + public Map getEquipmentsTypes() { + return equipmentTypes; + } + + public boolean isTypified() { + return typified; + } + public void setTypification(boolean typefied) { + this.typified = typefied; + } + public TaskCase() { cargoes = new ArrayList<>(); berths = new ArrayList<>(); storages = new ArrayList<>(); bunkers = new ArrayList<>(); + tows = new ArrayList<>(); equipments = new ArrayList<>(); ships = new ArrayList<>(); - + + vesselTypes = new TreeMap<>(); + equipmentTypes = new TreeMap<>(); + templates = new ArrayList<>(); cargoFlows = new ArrayList<>(); @@ -369,7 +399,6 @@ public class TaskCase { storageEndState = new ArrayList<>(); solution = new ArrayList<>(); - } private MovingObjectState fromString(String s, Map m_berth, Map m_vessel) @@ -383,14 +412,49 @@ public class TaskCase { st.setLocation(m_berth.get(key)); return st; } - + + private enum Tag { + Undefined (""), + Typified ("Typified"), + Cargoes ("Cargoes"), + Berths ("Berths"), + Storages ("Storages"), + Loading_Equipment_Types("Loading Equipment Types"), + Vessel_Types ("Vessel Types"), + Bunkers ("Bunkers"), + Tows ("Tows"), + Loading_Equipments ("Loading Equipments"), + Transport_Ships ("Transport Ships"), + Templates ("Templates"), + Time_Windows ("Time Windows"), + Cargo_Flows ("Cargo Flows"), + Initial_Vessel_State ("Initial Vessel State"), + Initial_Storage_State ("Initial Storage State"), + Final_Vessel_State ("Final Vessel State"), + Final_Storage_State ("Final Storage State"), + Task_Properties ("Task Properties"), + Solution ("Solution"); + + private final String text; + Tag(String text) { + this.text = text; + } + public static Tag fromString(String text) { + for (Tag t : Tag.values()) { + if (t.text.equalsIgnoreCase(text)) { + return t; + } + } + return Undefined; + } + } + public void deserialize(String fileName) throws IOException { cargoes.clear(); berths.clear(); storages.clear(); bunkers.clear(); tows.clear(); equipments.clear(); ships.clear(); templates.clear(); cargoFlows.clear(); vesselInitialState.clear(); storageInitialState.clear(); vesselEndState.clear(); storageEndState.clear(); solution.clear(); - - String[] tags = {"Cargoes", "Berths", "Storages", "Bunkers", "Tows", "Loading Equipments", "Transport Ships", "Templates", "Time Windows", "Cargo Flows", "Initial Vessel State", "Initial Storage State", "Final Vessel State", "Final Storage State", "Task Properties", "Solution"}; + // Open the file FileInputStream fstream; try @@ -398,64 +462,81 @@ public class TaskCase { fstream = new FileInputStream(fileName); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; - int index = 0; + Tag tag = Tag.Undefined; Map m_cargo = new HashMap<>(); Map m_berth = new HashMap<>(); Map m_storage = new HashMap<>(); Map m_vessel = new HashMap<>(); - Map m_equiopment = new HashMap<>(); + Map m_equipment = new HashMap<>(); Map m_template = new HashMap<>(); //Read File Line By Line - int numInside = 0; + int numInside = 0; while ((strLine = br.readLine()) != null) { numInside ++; boolean serviceString = false; - for (int i = 0; i0) - { + if (crs.length()>0) { key = Integer.parseInt(crs.trim()); - mt.getResources().add((Tow)m_vessel.get(key)); + if (isTypified()) { + mt.getResourcesTypes().add(key); + } else { + mt.getResources().add((Tow) m_vessel.get(key)); + } } mt.setDuration(Double.parseDouble(tokens[7].trim())); templates.add(mt); @@ -470,19 +551,26 @@ public class TaskCase { mt.setDirect(false); mt.setTimeWindow(tokens[2].trim()); int key = Integer.parseInt(tokens[3].trim()); - mt.setMoorer((TransportShip)m_vessel.get(key)); + if (isTypified()) { + mt.setMoorerType(OptionalInt.of(key)); + } else { + mt.setMoorer((TransportShip) m_vessel.get(key)); + } key = Integer.parseInt(tokens[4].trim()); mt.setStartLocation(m_berth.get(key)); String[] rs = tokens[5].trim().replace("[", "").replace("]", "").split(","); for (String crs : rs) - if (crs.length()>0) - { + if (crs.length()>0) { key = Integer.parseInt(crs.trim()); - mt.getResources().add((Tow)m_vessel.get(key)); + if (isTypified()) { + mt.getResourcesTypes().add(key); + } else { + mt.getResources().add((Tow) m_vessel.get(key)); + } } - mt.setDuration(Double.parseDouble(tokens[6].trim())); - templates.add(mt); - m_template.put(mt.getId(), mt); + mt.setDuration(Double.parseDouble(tokens[6].trim())); + templates.add(mt); + m_template.put(mt.getId(), mt); } if (tokens[1].trim().equals("loa")) { @@ -490,18 +578,27 @@ public class TaskCase { mt.setId(Integer.parseInt(tokens[0].trim())); mt.setTimeWindow(tokens[2].trim()); int direct = 1; + + BiFunction addLoaderOrStorage = (Integer key, Integer loaderDirection) -> { + int dir = 1; + if (vesselTypes.containsKey(key)) { + mt.setLoaderType(OptionalInt.of(key)); + dir = loaderDirection; + } else + if (m_vessel.containsKey(key)) { + mt.setLoader((TransportShip)m_vessel.get(key)); + dir = loaderDirection; + } + if (m_storage.containsKey(key)) { + mt.setStorage((Storage)m_storage.get(key)); + dir = -loaderDirection; + } + return dir; + }; + // Источник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом - int key = Integer.parseInt(tokens[3].trim()); - if (m_vessel.containsKey(key)) - { - mt.setLoader((TransportShip)m_vessel.get(key)); - direct = -1; - } - if (m_storage.containsKey(key)) - { - mt.setStorage((Storage)m_storage.get(key)); - direct = 1; - } + int key = Integer.parseInt(tokens[3].trim()); + direct = addLoaderOrStorage.apply(key, -1); // Груз. key = Integer.parseInt(tokens[4].trim());; for (Cargo cargo : cargoes) { @@ -511,24 +608,18 @@ public class TaskCase { } // Приемник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом key = Integer.parseInt(tokens[5].trim()); - if (m_vessel.containsKey(key)) - { - mt.setLoader((TransportShip)m_vessel.get(key)); - direct = 1; - } - if (m_storage.containsKey(key)) - { - mt.setStorage((Storage)m_storage.get(key)); - direct = - 1; - } + direct = addLoaderOrStorage.apply(key, 1); key = Integer.parseInt(tokens[6].trim()); mt.setStartLocation(m_berth.get(key)); String[] rs = tokens[7].trim().replace("[", "").replace("]", "").split(","); for (String crs : rs) - if (crs.length()>0) - { + if (crs.length()>0) { key = Integer.parseInt(crs.trim()); - mt.getResources().add(m_equiopment.get(key)); + if (isTypified()) { + mt.getResourcesTypes().add(key); + } else { + mt.getResources().add(m_equipment.get(key)); + } } mt.setIntensity(direct*Double.parseDouble(tokens[8].trim())); mt.setWithMooring(tokens[9].trim().equals("M")); @@ -537,26 +628,26 @@ public class TaskCase { m_template.put(mt.getId(), mt); } break; - case 9: + case Time_Windows: break; - case 10: cargoFlows.add(new CargoFlow(strLine, m_storage, m_cargo)); + case Cargo_Flows: cargoFlows.add(new CargoFlow(strLine, m_storage, m_cargo)); break; - case 11: vesselInitialState.add(fromString(strLine, m_berth, m_vessel)); + case Initial_Vessel_State: vesselInitialState.add(fromString(strLine, m_berth, m_vessel)); break; - case 12: storageInitialState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo)); + case Initial_Storage_State: storageInitialState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo)); break; - case 13: vesselEndState.add(fromString(strLine, m_berth, m_vessel)); + case Final_Vessel_State: vesselEndState.add(fromString(strLine, m_berth, m_vessel)); break; - case 14: storageEndState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo)); + case Final_Storage_State: storageEndState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo)); break; - case 15: + case Task_Properties: { String[] rs = strLine.split(";"); planningInterval = Double.parseDouble(rs[0].trim()); criterionType = Integer.parseInt(rs[1].trim()); } break; - case 16: // Тут чтение операций если надо. Потом подумаем + case Solution: // Тут чтение операций если надо. Потом подумаем break; default: break; @@ -573,62 +664,77 @@ public class TaskCase { { try(FileWriter writer = new FileWriter(fileName, false)) { - // запись всего - writer.write("Cargoes"+"\n"); - for (Cargo c : cargoes) - writer.write(c.toString()+"\n"); - writer.write("Berths"+"\n"); - for (Berth c : berths) - writer.write(c.toString()+"\n"); - writer.write("Storages"+"\n"); - for (Storage c : storages) - writer.write(c.toString()+"\n"); - writer.write("Bunkers"+"\n"); - for (Bunker c : bunkers) - writer.write(c.toString()+"\n"); - writer.write("Tows"+"\n"); - for (Tow c : tows) - writer.write(c.toString()+"\n"); - writer.write("Loading Equipments"+"\n"); - for (LoadingEquipment c : equipments) - writer.write(c.toString()+"\n"); - writer.write("Transport Ships"+"\n"); - for (TransportShip c : ships) - writer.write(c.toString()+"\n"); - writer.write("\n"); - writer.write("Templates"+"\n"); - for (OperationTemplate c : templates) - writer.write(c.toString()+"\n"); - writer.write("\n"); - writer.write("Cargo Flows"+"\n"); - for (CargoFlow c : cargoFlows) - writer.write(c.toString()+"\n"); - writer.write("Initial Vessel State"+"\n"); - for (MovingObjectState c : vesselInitialState) - writer.write(c.toString()+"\n"); - writer.write("Initial Storage State"+"\n"); - for (StorageState c : storageInitialState) - writer.write(c.toString()+"\n"); - writer.write("Final Vessel State"+"\n"); - for (MovingObjectState c : vesselEndState) - writer.write(c.toString()+"\n"); - writer.write("Final Storage State"+"\n"); - for (StorageState c : storageEndState) - writer.write(c.toString()+"\n"); - writer.write("\n"); - writer.write("Task Properties"+"\n"); - writer.write(planningInterval+";"+criterionType+"\n"); - writer.write("\n"); - writer.write("Solution"+"\n"); - writer.write(solution_result+"\n"); - for (Operation c : solution) - writer.write(c.toString()+"\n"); - writer.flush(); + // запись всего + writer.write(Tag.Typified.text + "\n" + (isTypified()? "1" : "0") + "\n"); + + writer.write("Cargoes"+"\n"); + for (Cargo c : cargoes) + writer.write(c.toString()+"\n"); + writer.write("Berths"+"\n"); + for (Berth c : berths) + writer.write(c.toString()+"\n"); + writer.write("Storages"+"\n"); + for (Storage c : storages) { + writer.write(c.toString() + "\n"); + } + if (isTypified()) { + writer.write(Tag.Vessel_Types.text + "\n"); + for (Map.Entry e : vesselTypes.entrySet()) { + writer.write(e.getKey() + "; " + e.getValue() + "\n"); + } + } + writer.write("Bunkers"+"\n"); + for (Bunker c : bunkers) + writer.write(c.toString()+"\n"); + writer.write("Tows"+"\n"); + for (Tow c : tows) { + writer.write(c.toString() + "\n"); + } + if (isTypified()) { + writer.write(Tag.Loading_Equipment_Types.text + "\n"); + for (Map.Entry e : equipmentTypes.entrySet()) { + writer.write(e.getKey() + "; " + e.getValue() + "\n"); + } + } + writer.write("Loading Equipments"+"\n"); + for (LoadingEquipment c : equipments) + writer.write(c.toString()+"\n"); + writer.write("Transport Ships"+"\n"); + for (TransportShip c : ships) + writer.write(c.toString()+"\n"); + writer.write("\n"); + writer.write("Templates"+"\n"); + for (OperationTemplate c : templates) + writer.write(c.toString()+"\n"); + writer.write("\n"); + writer.write("Cargo Flows"+"\n"); + for (CargoFlow c : cargoFlows) + writer.write(c.toString()+"\n"); + writer.write("Initial Vessel State"+"\n"); + for (MovingObjectState c : vesselInitialState) + writer.write(c.toString()+"\n"); + writer.write("Initial Storage State"+"\n"); + for (StorageState c : storageInitialState) + writer.write(c.toString()+"\n"); + writer.write("Final Vessel State"+"\n"); + for (MovingObjectState c : vesselEndState) + writer.write(c.toString()+"\n"); + writer.write("Final Storage State"+"\n"); + for (StorageState c : storageEndState) + writer.write(c.toString()+"\n"); + writer.write("\n"); + writer.write("Task Properties"+"\n"); + writer.write(planningInterval+";"+criterionType+"\n"); + writer.write("\n"); + writer.write("Solution"+"\n"); + writer.write(solution_result+"\n"); + for (Operation c : solution) + writer.write(c.toString()+"\n"); + writer.flush(); } - catch(IOException ex){ - + catch(IOException ex) { System.out.println(ex.getMessage()); - } + } } public void formSolutionFromPB(int res[]) diff --git a/src/inport/Tow.java b/src/inport/Tow.java index bbcf746..f7498da 100644 --- a/src/inport/Tow.java +++ b/src/inport/Tow.java @@ -4,6 +4,8 @@ */ package inport; +import java.util.OptionalInt; + /** * * @author topazh_ag @@ -19,12 +21,18 @@ public class Tow extends MovingObject { @Override public String toString() { - return getId() + ";" + getName() + ";1000000"; + String res = getId() + ";" + getName() + ";1000000"; + if (getType().isPresent()) { + res += ";" + getType().getAsInt(); + } + return res; } public Tow(String s) { super(s); + String[] tokens = s.split(";"); + if (tokens.length >= 4) { + setType(OptionalInt.of(Integer.parseInt(tokens[3].trim()))); + } } - - } diff --git a/src/inport/TowUsingTemplate.java b/src/inport/TowUsingTemplate.java index f79ea36..235cf4f 100644 --- a/src/inport/TowUsingTemplate.java +++ b/src/inport/TowUsingTemplate.java @@ -12,11 +12,10 @@ import java.util.List; * @author topazh_ag */ public abstract class TowUsingTemplate extends OperationTemplate { - private List resources; + private List resourcesTypes; private double duration; - /** * Get the value of resources @@ -36,6 +35,13 @@ public abstract class TowUsingTemplate extends OperationTemplate { this.resources = resources; } + public List getResourcesTypes() { + return resourcesTypes; + } + public void setResourcesTypes(List resourcesTypes) { + this.resourcesTypes = resourcesTypes; + } + /** * Get the value of duration * @@ -59,11 +65,13 @@ public abstract class TowUsingTemplate extends OperationTemplate { public TowUsingTemplate(double duration, int id, Berth startLocation) { super(id, startLocation); this.resources = new ArrayList<>(); + this.resourcesTypes = new ArrayList<>(); this.duration = duration; } public TowUsingTemplate() { this.resources = new ArrayList<>(); + this.resourcesTypes = new ArrayList<>(); } @Override @@ -80,6 +88,4 @@ public abstract class TowUsingTemplate extends OperationTemplate { } return getId() + ";" + "tut" + ";" + ";[" + res +"];"+duration; } - - } diff --git a/src/inport/TransportShip.java b/src/inport/TransportShip.java index 9c64925..4f395aa 100644 --- a/src/inport/TransportShip.java +++ b/src/inport/TransportShip.java @@ -4,6 +4,8 @@ */ package inport; +import java.util.OptionalInt; + /** * * @author topazh_ag @@ -30,13 +32,20 @@ public class TransportShip extends MovingObject { @Override public String toString() { - return getId() + ";" + getName() + ";" + cargoMax; + String res = getId() + ";" + getName() + ";" + cargoMax; + if (getType().isPresent()) { + res += ";" + getType().getAsInt(); + } + return res; } public TransportShip(String s) { super(s); String[] tokens = s.split(";"); - cargoMax = Double.parseDouble(tokens[2].trim()); + cargoMax = Double.parseDouble(tokens[2].trim()); + if (tokens.length >= 4) { + setType(OptionalInt.of(Integer.parseInt(tokens[3].trim()))); + } } } -- GitLab