From 800d72eefb7de0aff01ef990be8877b7bc2ea08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=81=D0=B5=D0=BB=D1=91=D0=B2=20=D0=92=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2?= Date: Mon, 12 Nov 2018 23:50:40 +0300 Subject: [PATCH] Cleanup --- .gitignore | 4 + src/Berth.java | 81 -- src/Bunker.java | 33 - src/Cargo.java | 91 -- src/CargoFlow.java | 142 --- src/InPort.java | 1585 -------------------------------- src/LoadingEquipment.java | 31 - src/LoadingTemplate.java | 97 -- src/MooringTemplate.java | 80 -- src/MovingObject.java | 66 -- src/MovingObjectState.java | 71 -- src/MovingTemplate.java | 79 -- src/Operation.java | 82 -- src/OperationTemplate.java | 91 -- src/SerializationHelper.java | 79 -- src/Storage.java | 115 --- src/StorageState.java | 97 -- src/TaskCase.java | 1644 ---------------------------------- src/Tow.java | 30 - src/TowUsingTemplate.java | 85 -- src/TransportShip.java | 42 - 21 files changed, 4 insertions(+), 4621 deletions(-) create mode 100644 .gitignore delete mode 100644 src/Berth.java delete mode 100644 src/Bunker.java delete mode 100644 src/Cargo.java delete mode 100644 src/CargoFlow.java delete mode 100644 src/InPort.java delete mode 100644 src/LoadingEquipment.java delete mode 100644 src/LoadingTemplate.java delete mode 100644 src/MooringTemplate.java delete mode 100644 src/MovingObject.java delete mode 100644 src/MovingObjectState.java delete mode 100644 src/MovingTemplate.java delete mode 100644 src/Operation.java delete mode 100644 src/OperationTemplate.java delete mode 100644 src/SerializationHelper.java delete mode 100644 src/Storage.java delete mode 100644 src/StorageState.java delete mode 100644 src/TaskCase.java delete mode 100644 src/Tow.java delete mode 100644 src/TowUsingTemplate.java delete mode 100644 src/TransportShip.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..10916f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/* +out/* +Conversion.iml +.idea/dictionaries/Vlad_kv.xml diff --git a/src/Berth.java b/src/Berth.java deleted file mode 100644 index 2e56e49..0000000 --- a/src/Berth.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class Berth { - - private int id; - private String name; - private boolean isRaid; - - /** - * Get the value of name - * - * @return the value of name - */ - public String getName() { - return name; - } - - /** - * Set the value of name - * - * @param name new value of name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Get the value of id - * - * @return the value of id - */ - public int getId() { - return id; - } - - /** - * Set the value of id - * - * @param id new value of id - */ - public void setId(int id) { - this.id = id; - } - - public boolean getIsRaid() { - return isRaid; - } - - public void setIsRaid(boolean isRaid) { - this.isRaid = isRaid; - } - - public Berth(int id, String name, boolean isRaid) { - this.id = id; - this.name = name; - this.isRaid = isRaid; - } - - public Berth() { - } - - @Override - public String toString() { - return id + ";" + name; - } - - public Berth(String s) { - String[] tokens = s.split(";"); - id = Integer.parseInt(tokens[0].trim()); - name = tokens[1].trim(); - } - -} diff --git a/src/Bunker.java b/src/Bunker.java deleted file mode 100644 index 3be1104..0000000 --- a/src/Bunker.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class Bunker extends MovingObject { - - public Bunker(int id, String name) { - super(id, name); - } - - public Bunker() { - super( ); - } - - - @Override - public String toString() { - return getId() + ";" + getName(); - } - - public Bunker(String s) { - super(s); - } - - - -} diff --git a/src/Cargo.java b/src/Cargo.java deleted file mode 100644 index 3b8b563..0000000 --- a/src/Cargo.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class Cargo { - - private double cost; - private int id; - private String name; - - /** - * Get the value of cost - * - * @return the value of cost - */ - public double getCost() { - return cost; - } - - /** - * Set the value of cost - * - * @param cost new value of cost - */ - public void setCost(double cost) { - this.cost = cost; - } - - /** - * Get the value of name - * - * @return the value of name - */ - public String getName() { - return name; - } - - /** - * Set the value of name - * - * @param name new value of name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Get the value of id - * - * @return the value of id - */ - public int getId() { - return id; - } - - /** - * Set the value of id - * - * @param id new value of id - */ - public void setId(int id) { - this.id = id; - } - - public Cargo(double cost, int id, String name) { - this.cost = cost; - this.id = id; - this.name = name; - } - - public Cargo() { - } - - @Override - public String toString() { - return id + ";" + name + ";" + cost; - } - - public Cargo(String s) { - String[] tokens = s.split(";"); - id = Integer.parseInt(tokens[0].trim()); - name = tokens[1].trim(); - cost = 0; //Double.parseDouble(tokens[2]); - } -} diff --git a/src/CargoFlow.java b/src/CargoFlow.java deleted file mode 100644 index cdc5459..0000000 --- a/src/CargoFlow.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * - * @author topazh_ag - */ -public class CargoFlow { - - private Storage storage; - private Cargo cargo; - Map flow; - - public Map getFlow() { - return flow; - } - - public void setFlow(Map flow) { - this.flow = flow; - } - - /** - * Get the value of storage - * - * @return the value of storage - */ - public Storage getStorage() { - return storage; - } - - /** - * Set the value of storage - * - * @param storage new value of storage - */ - public void setStorage(Storage storage) { - this.storage = storage; - } - - public Cargo getCargo() { - return cargo; - } - - public void setCargo(Cargo cargo) { - this.cargo = cargo; - } - - public CargoFlow() { - this.flow = new HashMap<>(); - } - - public CargoFlow(Storage storage, Cargo cargo) { - this.storage = storage; - this.cargo = cargo; - this.flow = new HashMap<>(); - } - - public double getCurrentValue(double forTime) - { - double res = 0.0; - boolean isFound = false; - Set keyTimes = flow.keySet(); - double prevKey = -1.0; - for (Double keyTime : keyTimes) - { - if (forTime>prevKey && forTimeprevKey) - res = flow.get(prevKey); - return res; - } - - public double getTotalValue(double forTime) - { - double res = 0.0; - boolean isFound = false; - Set keyTimes = flow.keySet(); - double prevKey = -1.0; - for (Double keyTime : keyTimes) - { - if (forTime>prevKey && forTimeprevKey) - res += flow.get(prevKey)*(forTime-prevKey); - return res; - } - - @Override - public String toString() { - String res = ""; - boolean first = true; - for(Double s : flow.keySet()) - { - if (!first) - res += "," + s+ ":" + flow.get(s); - else - res += s + ":" + flow.get(s); - first = false; - } - return storage.getId() + ";[" + res +"]"; - } - - public CargoFlow(String s, Map mp, Map cp) { - this.flow = new HashMap<>(); - String[] tokens = s.split(";"); - int key = Integer.parseInt(tokens[0].trim()); - storage = mp.get(key); - key = Integer.parseInt(tokens[1].trim()); - cargo = cp.get(key); - String[] rs = tokens[2].trim().replace("[", "").replace("]", "").split(","); - for (String crs : rs) - if (crs.length()>0) - { - String[] kv = crs.split(":"); - Double key1 = Double.parseDouble(kv[0].trim()); - Double value1 = Double.parseDouble(kv[1].trim()); - flow.put(key1, value1); - } - } -} diff --git a/src/InPort.java b/src/InPort.java deleted file mode 100644 index 774fecf..0000000 --- a/src/InPort.java +++ /dev/null @@ -1,1585 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -//import com.google.gson.Gson; - -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.math.BigInteger; -import java.util.Date; - -import org.sat4j.core.Vec; -import org.sat4j.core.VecInt; -import org.sat4j.minisat.SolverFactory; -import org.sat4j.pb.IPBSolver; -import org.sat4j.pb.OPBStringSolver; -import org.sat4j.pb.ObjectiveFunction; -import org.sat4j.pb.reader.OPBEclipseReader2007; -import org.sat4j.reader.DimacsReader; -import org.sat4j.reader.ParseFormatException; -import org.sat4j.reader.Reader; -import org.sat4j.specs.ContradictionException; -import org.sat4j.specs.IProblem; -import org.sat4j.specs.ISolver; -import org.sat4j.specs.IVec; -import org.sat4j.specs.IVecInt; -// import pbsugar.pb.PBParser; - -//import java.beans.XMLEncoder; -//import java.io.BufferedOutputStream; -//import java.io.FileNotFoundException; -//import java.io.FileOutputStream; -//import java.io.FileWriter; -//import java.io.IOException; - -/** - * - * @author topazh_ag - */ -public class InPort { - - /** - * @param args the command line arguments - */ - public static void main(String[] args) throws Exception { - - globalTest(); - - /* - // Создаем новую задачу - TaskCase task = new TaskCase(); - - // Читаем ее из файла первого аргумента - task.deserialize(args[0]); - - // Подготвливаем для солвера и решаем - String fName = "task.opb"; - int nOperations = task.pb_formalize(fName); - int[] res = pbSolverDemo(fName); - - // Запись во все назначения - int nTimes = (int) (task.getPlanningInterval() + 1.0 - 1e-7); - if (res.length>1) - { - formResult(fName, res, nOperations, nTimes); - task.formSolutionFromPB(res); - task.serialize(args[0]); - } - */ - - } - - private static void globalTest() throws Exception - { - // Создаем новую задачу - TaskCase task = new TaskCase(); - - // Заполняем вручную - // fillByHandT(task); - // fillByHandT(task); - // fillByHand2(task); - // fillByHandE0(task); - - // Пишем - // task.serialize("Task.txt"); - - // Читаем обратно - task.deserialize("ippStart.ipp"); - - // И пишем в другой файл для сравнения - task.serialize("TaskCopy.txt"); - - - // Подготвливаем для солвера - String fName = "task.opb"; - // int nOperations = task.pb_formalize(fName); - int nOperations = 17; - /* - pbsugar.PBSugar solver = new pbsugar.PBSugar(); - solver.pbFileName = fName; - int variables = solver.encode(); - Set pbSolution = solver.solve(variables); - */ - - - int[] res = pbSolverDemo(fName); - - // Запись в - int nTimes = (int) (task.getPlanningInterval() + 1.0 - 1e-7); - if (res.length>1) - { - formResult(fName, res, nOperations, nTimes); - task.formSolutionFromPB(res); - task.serialize("TaskResult.txt"); - } - } - - private static void formResult(String fileName, int[] res, int nOperations, int nTimes) throws IOException - { - // Решение - в конец файла задания - FileWriter writer = new FileWriter(fileName, true); - // Решение - в отдельный файл - // FileWriter writer = new FileWriter("D:\\KSRC\\GMT_Logistics\\Planning\\results.txt", false); - writer.write("\n"); - writer.write("* Results: \n"); - writer.write("\n"); - int cVar = 0; - do - { - String clause = "Operation "+(cVar+1) + ": "; - int nSpaces = 6 - (int)(Math.log10(cVar+1)); - for (int j=0; j0) - clause += "X"; - else - clause += "-"; - } - writer.write(clause+"\n"); - cVar++; - } while (cVar7->1->6->1) - public static void fillByHandT(TaskCase task) - { - // Статические элементы - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - - // Причалы - Berth berth0 = new Berth(1, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(2, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(3, "Pier 2", false); - task.getBerths().add(berth2); - - - // Хранилища - Storage storage1 = new Storage(4, "Storage 1", 10000.0, cargo0); - task.getStorages().add(storage1); - - // Суда - TransportShip ship1 = new TransportShip(5, "Ship 1", 2000); - task.getShips().add(ship1); - TransportShip ship2 = new TransportShip(6, "Ship 2", 2000); - task.getShips().add(ship2); - - - // Шаблоны операций - - // Перемещения - //1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move101); - //2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move110); - //3 - MovingTemplate move102 = new MovingTemplate(ship1,berth0,berth2,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move102); - //4 - MovingTemplate move120 = new MovingTemplate(ship1,berth2,berth0,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move120); - //5 - MovingTemplate move112 = new MovingTemplate(ship1,berth1,berth2,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move112); - //6 - MovingTemplate move121 = new MovingTemplate(ship1,berth2,berth1,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move121); - - //7 - MovingTemplate move201 = new MovingTemplate(ship2,berth0,berth1,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move201); - //8 - MovingTemplate move210 = new MovingTemplate(ship2,berth1,berth0,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move210); - //9 - MovingTemplate move202 = new MovingTemplate(ship2,berth0,berth2,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move202); - //10 - MovingTemplate move220 = new MovingTemplate(ship2,berth2,berth0,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move220); - //11 - MovingTemplate move212 = new MovingTemplate(ship2,berth1,berth2,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move212); - //12 - MovingTemplate move221 = new MovingTemplate(ship2,berth2,berth1,1.0,7+task.getTemplates().size()); - task.getTemplates().add(move221); - - - // Погрузки - //13 - LoadingTemplate load11 = new LoadingTemplate(ship1,berth1,storage1,100.0,7+task.getTemplates().size()); - task.getTemplates().add(load11); - //14 - LoadingTemplate load12 = new LoadingTemplate(ship1,berth2,storage1,50.0,7+task.getTemplates().size()); - task.getTemplates().add(load12); - //15 - LoadingTemplate load21 = new LoadingTemplate(ship2,berth1,storage1,100.0,7+task.getTemplates().size()); - task.getTemplates().add(load21); - //16 - LoadingTemplate load22 = new LoadingTemplate(ship2,berth2,storage1,50.0,7+task.getTemplates().size()); - task.getTemplates().add(load22); - - // Начальное состояние - MovingObjectState sini1 = new MovingObjectState(ship1, berth0); - task.getVesselInitialState().add(sini1); - StorageState stini1 = new StorageState(ship1,cargo0, 0.0); - task.getStorageInitialState().add(stini1); - - MovingObjectState sini2 = new MovingObjectState(ship2, berth0); - task.getVesselInitialState().add(sini2); - StorageState stini2 = new StorageState(ship2,cargo0, 0.0); - task.getStorageInitialState().add(stini2); - - StorageState tini1 = new StorageState(storage1, cargo0, 10000.0); - task.getStorageInitialState().add(tini1); - - - // Конечное состояние - MovingObjectState send1 = new MovingObjectState(ship1, berth0); - task.getVesselEndState().add(send1); - StorageState stend1 = new StorageState(ship1,cargo0, 1000.0); - task.getStorageEndState().add(stend1); - - MovingObjectState send2 = new MovingObjectState(ship2, berth0); - task.getVesselEndState().add(send2); - StorageState stend2 = new StorageState(ship2, cargo0, 1000.0); - task.getStorageEndState().add(stend2); - - // Горизонт планирования - task.setPlanningInterval(24.0); - } - - /* - // Кейс имени Топажа с нетривиальным решением (1->7->1->6->1) и окном непогоды - public static void fillByHandTTW(TaskCase task) - { - // Статические элементы - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - - // Причалы - Berth berth0 = new Berth(0, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(1, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(2, "Pier 2", false); - task.getBerths().add(berth2); - - - // Хранилища - Storage storage1 = new Storage(1, "Storage 1", 10000.0, cargo0); - task.getStorages().add(storage1); - - // Суда - TransportShip ship1 = new TransportShip(2, "Ship 1", 2000); - task.getShips().add(ship1); - TransportShip ship2 = new TransportShip(3, "Ship 2", 2000); - task.getShips().add(ship2); - - - // Шаблоны операций - - // Перемещения - //1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(move101); - //2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move110); - //3 - MovingTemplate move102 = new MovingTemplate(ship1,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(move102); - //4 - MovingTemplate move120 = new MovingTemplate(ship1,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move120); - //5 - MovingTemplate move112 = new MovingTemplate(ship1,berth1,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(move112); - //6 - MovingTemplate move121 = new MovingTemplate(ship1,berth2,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(move121); - - //7 - MovingTemplate move201 = new MovingTemplate(ship2,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(move201); - //8 - MovingTemplate move210 = new MovingTemplate(ship2,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move210); - //9 - MovingTemplate move202 = new MovingTemplate(ship2,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(move202); - //10 - MovingTemplate move220 = new MovingTemplate(ship2,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move220); - //11 - MovingTemplate move212 = new MovingTemplate(ship2,berth1,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(move212); - //12 - MovingTemplate move221 = new MovingTemplate(ship2,berth2,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(move221); - - - // Погрузки - //13 - LoadingTemplate load11 = new LoadingTemplate(ship1,berth1,storage1,100.0,task.getTemplates().size()); - task.getTemplates().add(load11); - //14 - LoadingTemplate load12 = new LoadingTemplate(ship1,berth2,storage1,50.0,task.getTemplates().size()); - task.getTemplates().add(load12); - //15 - LoadingTemplate load21 = new LoadingTemplate(ship2,berth1,storage1,100.0,task.getTemplates().size()); - task.getTemplates().add(load21); - //16 - LoadingTemplate load22 = new LoadingTemplate(ship2,berth2,storage1,50.0,task.getTemplates().size()); - task.getTemplates().add(load22); - - TimeWindow tw = new TimeWindow(load11); - tw.getBanWindows().put(2.0,2.0); - task.getTimeWindowConstraints().add(tw); - - tw = new TimeWindow(load21); - tw.getBanWindows().put(2.0,2.0); - task.getTimeWindowConstraints().add(tw); - - tw = new TimeWindow(load12); - tw.getBanWindows().put(3.0,2.0); - task.getTimeWindowConstraints().add(tw); - - tw = new TimeWindow(load22); - tw.getBanWindows().put(3.0,2.0); - task.getTimeWindowConstraints().add(tw); - - - - // Начальное состояние - TransportShipState sini1 = new TransportShipState(0.0, ship1, berth0, false); sini1.getCargoState().put(cargo0, 0.0); - task.getVesselInitialState().add(sini1); - TransportShipState sini2 = new TransportShipState(0.0, ship2, berth0, false); sini2.getCargoState().put(cargo0, 0.0); - task.getVesselInitialState().add(sini2); - - StorageState tini1 = new StorageState(storage1, 10000.0); - task.getStorageInitialState().add(tini1); - - - // Конечное состояние - TransportShipState send1 = new TransportShipState(0.0, ship1, berth0, false); send1.getCargoState().put(cargo0, 1000.0); - task.getVesselEndState().add(send1); - TransportShipState send2 = new TransportShipState(0.0, ship2, berth0, false); send2.getCargoState().put(cargo0, 1000.0); - task.getVesselEndState().add(send2); - - // Горизонт планирования - task.setPlanningInterval(24.0); - } - */ - - /* - // Первый реальный кейс с не полностью тривиальным решением (ездят с буксиром, швартуются сами) - public static void fillByHand1(TaskCase task) - { - // Статические элементы - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - Cargo cargo1 = new Cargo(1.0, 1, "Excrement"); - task.getCargoes().add(cargo1); - - - // Причалы - Berth berth0 = new Berth(0, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(1, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(2, "Pier 2", false); - task.getBerths().add(berth2); - - - // Хранилища - Storage storage1 = new Storage(1, "Storage 1", 1000.0, cargo1); - task.getStorages().add(storage1); - Storage storage2 = new Storage(2, "Storage 2", 1000.0, cargo1); - task.getStorages().add(storage2); - - - // Буксиры - Tow tow1 = new Tow(1, "Tow 1"); - task.getTows().add(tow1); - - - // Бункеровщики - - - // Суда - TransportShip ship1 = new TransportShip(2, "Ship 1", 2000); - task.getShips().add(ship1); - TransportShip ship2 = new TransportShip(3, "Ship 2", 2000); - task.getShips().add(ship2); - - - // Шаблоны операций - - // Перемещения - // 1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,8.0,task.getTemplates().size()); - task.getTemplates().add(move101); - // 2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move110); - // 3 - MovingTemplate move101b = new MovingTemplate(ship1,berth0,berth1,1.0,task.getTemplates().size()); move101b.getResources().add(tow1); - task.getTemplates().add(move101b); - // 4 - MovingTemplate move110b = new MovingTemplate(ship1,berth1,berth0,1.0,task.getTemplates().size()); move110b.getResources().add(tow1); - task.getTemplates().add(move110b); - // 5 - MovingTemplate move102 = new MovingTemplate(ship1,berth0,berth2,8.0,task.getTemplates().size()); - task.getTemplates().add(move102); - // 6 - MovingTemplate move120 = new MovingTemplate(ship1,berth2,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move120); - // 7 - MovingTemplate move102b = new MovingTemplate(ship1,berth0,berth2,1.0,task.getTemplates().size()); move102b.getResources().add(tow1); - task.getTemplates().add(move102b); - // 8 - MovingTemplate move120b = new MovingTemplate(ship1,berth2,berth0,1.0,task.getTemplates().size()); move120b.getResources().add(tow1); - task.getTemplates().add(move120b); - // 9 - MovingTemplate move112b = new MovingTemplate(ship1,berth1,berth2,1.0,task.getTemplates().size()); move112b.getResources().add(tow1); - task.getTemplates().add(move112b); - // 10 - MovingTemplate move121b = new MovingTemplate(ship1,berth2,berth1,1.0,task.getTemplates().size()); move121b.getResources().add(tow1); - task.getTemplates().add(move121b); - - // 11 - MovingTemplate move201 = new MovingTemplate(ship2,berth0,berth1,8.0,task.getTemplates().size()); - task.getTemplates().add(move201); - // 12 - MovingTemplate move210 = new MovingTemplate(ship2,berth1,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move210); - // 13 - MovingTemplate move201b = new MovingTemplate(ship2,berth0,berth1,1.0,task.getTemplates().size()); move201b.getResources().add(tow1); - task.getTemplates().add(move201b); - // 14 - MovingTemplate move210b = new MovingTemplate(ship2,berth1,berth0,1.0,task.getTemplates().size()); move210b.getResources().add(tow1); - task.getTemplates().add(move210b); - // 15 - MovingTemplate move202 = new MovingTemplate(ship2,berth0,berth2,8.0,task.getTemplates().size()); - task.getTemplates().add(move202); - // 16 - MovingTemplate move220 = new MovingTemplate(ship2,berth2,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move220); - // 17 - MovingTemplate move202b = new MovingTemplate(ship2,berth0,berth2,1.0,task.getTemplates().size()); move202b.getResources().add(tow1); - task.getTemplates().add(move202b); - // 18 - MovingTemplate move220b = new MovingTemplate(ship2,berth2,berth0,1.0,task.getTemplates().size()); move220b.getResources().add(tow1); - task.getTemplates().add(move220b); - // 19 - MovingTemplate move212b = new MovingTemplate(ship2,berth1,berth2,1.0,task.getTemplates().size()); move212b.getResources().add(tow1); - task.getTemplates().add(move212b); - // 20 - MovingTemplate move221b = new MovingTemplate(ship2,berth2,berth1,1.0,task.getTemplates().size()); move221b.getResources().add(tow1); - task.getTemplates().add(move221b); - - // 21 - MovingTemplate moveb01 = new MovingTemplate(tow1,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb01); - // 22 - MovingTemplate moveb10 = new MovingTemplate(tow1,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb10); - // 23 - MovingTemplate moveb02 = new MovingTemplate(tow1,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb02); - // 24 - MovingTemplate moveb20 = new MovingTemplate(tow1,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb20); - // 25 - MovingTemplate moveb12b = new MovingTemplate(tow1,berth1,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb12b); - // 26 - MovingTemplate moveb21b = new MovingTemplate(tow1,berth2,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb21b); - - // Швартовки - // 27 - MooringTemplate moore11p = new MooringTemplate(ship1,berth1,1.0,true,task.getTemplates().size()); - task.getTemplates().add(moore11p); - // 28 - MooringTemplate moore11m = new MooringTemplate(ship1,berth1,1.0,false,task.getTemplates().size()); - task.getTemplates().add(moore11m); - // 29 - MooringTemplate moore12p = new MooringTemplate(ship1,berth2,1.0,true,task.getTemplates().size()); - task.getTemplates().add(moore12p); - // 30 - MooringTemplate moore12m = new MooringTemplate(ship1,berth2,1.0,false,task.getTemplates().size()); - task.getTemplates().add(moore12m); - - // 31 - MooringTemplate moore21p = new MooringTemplate(ship2,berth1,1.0,true,task.getTemplates().size()); - task.getTemplates().add(moore21p); - // 32 - MooringTemplate moore21m = new MooringTemplate(ship2,berth1,1.0,false,task.getTemplates().size()); - task.getTemplates().add(moore21m); - // 33 - MooringTemplate moore22p = new MooringTemplate(ship2,berth2,1.0,true,task.getTemplates().size()); - task.getTemplates().add(moore22p); - // 34 - MooringTemplate moore22m = new MooringTemplate(ship2,berth2,1.0,false,task.getTemplates().size()); - task.getTemplates().add(moore22m); - - // Погрузки - // 35 - LoadingTemplate load11p = new LoadingTemplate(ship1,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load11p); - // 36 - LoadingTemplate load11m = new LoadingTemplate(ship1,berth1,storage1,-200.0,task.getTemplates().size()); - task.getTemplates().add(load11m); - // 37 - LoadingTemplate load12p = new LoadingTemplate(ship1,berth2,storage2,200.0,task.getTemplates().size()); - task.getTemplates().add(load12p); - // 38 - LoadingTemplate load12m = new LoadingTemplate(ship1,berth2,storage2,-200.0,task.getTemplates().size()); - task.getTemplates().add(load12m); - // 39 - LoadingTemplate load21p = new LoadingTemplate(ship2,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load21p); - // 40 - LoadingTemplate load21m = new LoadingTemplate(ship2,berth1,storage1,-200.0,task.getTemplates().size()); - task.getTemplates().add(load21m); - // 41 - LoadingTemplate load22p = new LoadingTemplate(ship2,berth2,storage2,200.0,task.getTemplates().size()); - task.getTemplates().add(load22p); - // 42 - LoadingTemplate load22m = new LoadingTemplate(ship2,berth2,storage2,-200.0,task.getTemplates().size()); - task.getTemplates().add(load22m); - - // Начальное состояние - TransportShipState sini1 = new TransportShipState(0.0, ship1, berth0, false); sini1.getCargoState().put(cargo1, 1000.0); - task.getVesselInitialState().add(sini1); - TransportShipState sini2 = new TransportShipState(0.0, ship2, berth0, false); sini2.getCargoState().put(cargo1, 0.0); - task.getVesselInitialState().add(sini2); - MovingObjectState sini3 = new MovingObjectState(tow1,berth0); - task.getVesselInitialState().add(sini3); - StorageState tini1 = new StorageState(storage1, 200.0); - task.getStorageInitialState().add(tini1); - StorageState tini2 = new StorageState(storage2, 800.0); - task.getStorageInitialState().add(tini2); - - // Конечное состояние - TransportShipState send1 = new TransportShipState(0.0, ship1, berth0, false); send1.getCargoState().put(cargo1, 0.0); - task.getVesselEndState().add(send1); - TransportShipState send2 = new TransportShipState(0.0, ship2, berth0, false); send2.getCargoState().put(cargo1, 1000.0); - task.getVesselEndState().add(send2); - - // Горизонт планирования - task.setPlanningInterval(18.0); - } - */ - - /* - // Второй реальный кейс с не полностью тривиальным решением (ездят с буксиром, швартуются с буксиром) - public static void fillByHand1a(TaskCase task) - { - // Статические элементы - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - Cargo cargo1 = new Cargo(1.0, 1, "Excrement"); - task.getCargoes().add(cargo1); - - - // Причалы - Berth berth0 = new Berth(0, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(1, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(2, "Pier 2", false); - task.getBerths().add(berth2); - - - // Хранилища - Storage storage1 = new Storage(1, "Storage 1", 1000.0, cargo1); - task.getStorages().add(storage1); - Storage storage2 = new Storage(2, "Storage 2", 1000.0, cargo1); - task.getStorages().add(storage2); - - - // Буксиры - Tow tow1 = new Tow(1, "Tow 1"); - task.getTows().add(tow1); - - - // Бункеровщики - - - // Суда - TransportShip ship1 = new TransportShip(2, "Ship 1", 2000); - task.getShips().add(ship1); - TransportShip ship2 = new TransportShip(3, "Ship 2", 2000); - task.getShips().add(ship2); - - - // Шаблоны операций - - // Перемещения - // 1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,8.0,task.getTemplates().size()); - task.getTemplates().add(move101); - // 2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move110); - // 3 - MovingTemplate move101b = new MovingTemplate(ship1,berth0,berth1,1.0,task.getTemplates().size()); move101b.getResources().add(tow1); - task.getTemplates().add(move101b); - // 4 - MovingTemplate move110b = new MovingTemplate(ship1,berth1,berth0,1.0,task.getTemplates().size()); move110b.getResources().add(tow1); - task.getTemplates().add(move110b); - // 5 - MovingTemplate move102 = new MovingTemplate(ship1,berth0,berth2,8.0,task.getTemplates().size()); - task.getTemplates().add(move102); - // 6 - MovingTemplate move120 = new MovingTemplate(ship1,berth2,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move120); - // 7 - MovingTemplate move102b = new MovingTemplate(ship1,berth0,berth2,1.0,task.getTemplates().size()); move102b.getResources().add(tow1); - task.getTemplates().add(move102b); - // 8 - MovingTemplate move120b = new MovingTemplate(ship1,berth2,berth0,1.0,task.getTemplates().size()); move120b.getResources().add(tow1); - task.getTemplates().add(move120b); - // 9 - MovingTemplate move112b = new MovingTemplate(ship1,berth1,berth2,1.0,task.getTemplates().size()); move112b.getResources().add(tow1); - task.getTemplates().add(move112b); - // 10 - MovingTemplate move121b = new MovingTemplate(ship1,berth2,berth1,1.0,task.getTemplates().size()); move121b.getResources().add(tow1); - task.getTemplates().add(move121b); - - // 11 - MovingTemplate move201 = new MovingTemplate(ship2,berth0,berth1,8.0,task.getTemplates().size()); - task.getTemplates().add(move201); - // 12 - MovingTemplate move210 = new MovingTemplate(ship2,berth1,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move210); - // 13 - MovingTemplate move201b = new MovingTemplate(ship2,berth0,berth1,1.0,task.getTemplates().size()); move201b.getResources().add(tow1); - task.getTemplates().add(move201b); - // 14 - MovingTemplate move210b = new MovingTemplate(ship2,berth1,berth0,1.0,task.getTemplates().size()); move210b.getResources().add(tow1); - task.getTemplates().add(move210b); - // 15 - MovingTemplate move202 = new MovingTemplate(ship2,berth0,berth2,8.0,task.getTemplates().size()); - task.getTemplates().add(move202); - // 16 - MovingTemplate move220 = new MovingTemplate(ship2,berth2,berth0,8.0,task.getTemplates().size()); - task.getTemplates().add(move220); - // 17 - MovingTemplate move202b = new MovingTemplate(ship2,berth0,berth2,1.0,task.getTemplates().size()); move202b.getResources().add(tow1); - task.getTemplates().add(move202b); - // 18 - MovingTemplate move220b = new MovingTemplate(ship2,berth2,berth0,1.0,task.getTemplates().size()); move220b.getResources().add(tow1); - task.getTemplates().add(move220b); - // 19 - MovingTemplate move212b = new MovingTemplate(ship2,berth1,berth2,1.0,task.getTemplates().size()); move212b.getResources().add(tow1); - task.getTemplates().add(move212b); - // 20 - MovingTemplate move221b = new MovingTemplate(ship2,berth2,berth1,1.0,task.getTemplates().size()); move221b.getResources().add(tow1); - task.getTemplates().add(move221b); - - // 21 - MovingTemplate moveb01 = new MovingTemplate(tow1,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb01); - // 22 - MovingTemplate moveb10 = new MovingTemplate(tow1,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb10); - // 23 - MovingTemplate moveb02 = new MovingTemplate(tow1,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb02); - // 24 - MovingTemplate moveb20 = new MovingTemplate(tow1,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb20); - // 25 - MovingTemplate moveb12b = new MovingTemplate(tow1,berth1,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb12b); - // 26 - MovingTemplate moveb21b = new MovingTemplate(tow1,berth2,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb21b); - - // Швартовки - // 27 - MooringTemplate moore11p = new MooringTemplate(ship1,berth1,1.0,true,task.getTemplates().size()); moore11p.getResources().add(tow1); - task.getTemplates().add(moore11p); - // 28 - MooringTemplate moore11m = new MooringTemplate(ship1,berth1,1.0,false,task.getTemplates().size()); moore11m.getResources().add(tow1); - task.getTemplates().add(moore11m); - // 29 - MooringTemplate moore12p = new MooringTemplate(ship1,berth2,1.0,true,task.getTemplates().size()); moore12p.getResources().add(tow1); - task.getTemplates().add(moore12p); - // 30 - MooringTemplate moore12m = new MooringTemplate(ship1,berth2,1.0,false,task.getTemplates().size()); moore12m.getResources().add(tow1); - task.getTemplates().add(moore12m); - - // 31 - MooringTemplate moore21p = new MooringTemplate(ship2,berth1,1.0,true,task.getTemplates().size()); moore21p.getResources().add(tow1); - task.getTemplates().add(moore21p); - // 32 - MooringTemplate moore21m = new MooringTemplate(ship2,berth1,1.0,false,task.getTemplates().size()); moore21m.getResources().add(tow1); - task.getTemplates().add(moore21m); - // 33 - MooringTemplate moore22p = new MooringTemplate(ship2,berth2,1.0,true,task.getTemplates().size()); moore22p.getResources().add(tow1); - task.getTemplates().add(moore22p); - // 34 - MooringTemplate moore22m = new MooringTemplate(ship2,berth2,1.0,false,task.getTemplates().size()); moore22m.getResources().add(tow1); - task.getTemplates().add(moore22m); - - // Погрузки - // 35 - LoadingTemplate load11p = new LoadingTemplate(ship1,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load11p); - // 36 - LoadingTemplate load11m = new LoadingTemplate(ship1,berth1,storage1,-200.0,task.getTemplates().size()); - task.getTemplates().add(load11m); - // 37 - LoadingTemplate load12p = new LoadingTemplate(ship1,berth2,storage2,200.0,task.getTemplates().size()); - task.getTemplates().add(load12p); - // 38 - LoadingTemplate load12m = new LoadingTemplate(ship1,berth2,storage2,-200.0,task.getTemplates().size()); - task.getTemplates().add(load12m); - // 39 - LoadingTemplate load21p = new LoadingTemplate(ship2,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load21p); - // 40 - LoadingTemplate load21m = new LoadingTemplate(ship2,berth1,storage1,-200.0,task.getTemplates().size()); - task.getTemplates().add(load21m); - // 41 - LoadingTemplate load22p = new LoadingTemplate(ship2,berth2,storage2,200.0,task.getTemplates().size()); - task.getTemplates().add(load22p); - // 42 - LoadingTemplate load22m = new LoadingTemplate(ship2,berth2,storage2,-200.0,task.getTemplates().size()); - task.getTemplates().add(load22m); - - // Начальное состояние - TransportShipState sini1 = new TransportShipState(0.0, ship1, berth0, false); sini1.getCargoState().put(cargo1, 1000.0); - task.getVesselInitialState().add(sini1); - TransportShipState sini2 = new TransportShipState(0.0, ship2, berth0, false); sini2.getCargoState().put(cargo1, 0.0); - task.getVesselInitialState().add(sini2); - MovingObjectState sini3 = new MovingObjectState(tow1,berth0); - task.getVesselInitialState().add(sini3); - StorageState tini1 = new StorageState(storage1, 200.0); - task.getStorageInitialState().add(tini1); - StorageState tini2 = new StorageState(storage2, 800.0); - task.getStorageInitialState().add(tini2); - - // Конечное состояние - TransportShipState send1 = new TransportShipState(0.0, ship1, berth0, false); send1.getCargoState().put(cargo1, 0.0); - task.getVesselEndState().add(send1); - TransportShipState send2 = new TransportShipState(0.0, ship2, berth0, false); send2.getCargoState().put(cargo1, 1000.0); - task.getVesselEndState().add(send2); - - // Горизонт планирования - task.setPlanningInterval(20.0); - } - */ - - /* - // Третий реальный кейс с не полностью тривиальным решением (ездят сами, швартуются с буксиром) - public static void fillByHand1b(TaskCase task) - { - // Статические элементы - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - Cargo cargo1 = new Cargo(1.0, 1, "Excrement"); - task.getCargoes().add(cargo1); - - - // Причалы - Berth berth0 = new Berth(0, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(1, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(2, "Pier 2", false); - task.getBerths().add(berth2); - - - // Хранилища - Storage storage1 = new Storage(1, "Storage 1", 1000.0, cargo1); - task.getStorages().add(storage1); - Storage storage2 = new Storage(2, "Storage 2", 1000.0, cargo1); - task.getStorages().add(storage2); - - - // Буксиры - Tow tow1 = new Tow(1, "Tow 1"); - task.getTows().add(tow1); - - - // Бункеровщики - - - // Суда - TransportShip ship1 = new TransportShip(2, "Ship 1", 2000); - task.getShips().add(ship1); - TransportShip ship2 = new TransportShip(3, "Ship 2", 2000); - task.getShips().add(ship2); - - - // Шаблоны операций - - // Перемещения - // 1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(move101); - // 2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move110); - // 3 - MovingTemplate move101b = new MovingTemplate(ship1,berth0,berth1,8.0,task.getTemplates().size()); move101b.getResources().add(tow1); - task.getTemplates().add(move101b); - // 4 - MovingTemplate move110b = new MovingTemplate(ship1,berth1,berth0,8.0,task.getTemplates().size()); move110b.getResources().add(tow1); - task.getTemplates().add(move110b); - // 5 - MovingTemplate move102 = new MovingTemplate(ship1,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(move102); - // 6 - MovingTemplate move120 = new MovingTemplate(ship1,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move120); - // 7 - MovingTemplate move102b = new MovingTemplate(ship1,berth0,berth2,8.0,task.getTemplates().size()); move102b.getResources().add(tow1); - task.getTemplates().add(move102b); - // 8 - MovingTemplate move120b = new MovingTemplate(ship1,berth2,berth0,8.0,task.getTemplates().size()); move120b.getResources().add(tow1); - task.getTemplates().add(move120b); - // 9 - MovingTemplate move112b = new MovingTemplate(ship1,berth1,berth2,8.0,task.getTemplates().size()); move112b.getResources().add(tow1); - task.getTemplates().add(move112b); - // 10 - MovingTemplate move121b = new MovingTemplate(ship1,berth2,berth1,8.0,task.getTemplates().size()); move121b.getResources().add(tow1); - task.getTemplates().add(move121b); - - // 11 - MovingTemplate move201 = new MovingTemplate(ship2,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(move201); - // 12 - MovingTemplate move210 = new MovingTemplate(ship2,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move210); - // 13 - MovingTemplate move201b = new MovingTemplate(ship2,berth0,berth1,8.0,task.getTemplates().size()); move201b.getResources().add(tow1); - task.getTemplates().add(move201b); - // 14 - MovingTemplate move210b = new MovingTemplate(ship2,berth1,berth0,8.0,task.getTemplates().size()); move210b.getResources().add(tow1); - task.getTemplates().add(move210b); - // 15 - MovingTemplate move202 = new MovingTemplate(ship2,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(move202); - // 16 - MovingTemplate move220 = new MovingTemplate(ship2,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(move220); - // 17 - MovingTemplate move202b = new MovingTemplate(ship2,berth0,berth2,8.0,task.getTemplates().size()); move202b.getResources().add(tow1); - task.getTemplates().add(move202b); - // 18 - MovingTemplate move220b = new MovingTemplate(ship2,berth2,berth0,8.0,task.getTemplates().size()); move220b.getResources().add(tow1); - task.getTemplates().add(move220b); - // 19 - MovingTemplate move212b = new MovingTemplate(ship2,berth1,berth2,8.0,task.getTemplates().size()); move212b.getResources().add(tow1); - task.getTemplates().add(move212b); - // 20 - MovingTemplate move221b = new MovingTemplate(ship2,berth2,berth1,8.0,task.getTemplates().size()); move221b.getResources().add(tow1); - task.getTemplates().add(move221b); - - // 21 - MovingTemplate moveb01 = new MovingTemplate(tow1,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb01); - // 22 - MovingTemplate moveb10 = new MovingTemplate(tow1,berth1,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb10); - // 23 - MovingTemplate moveb02 = new MovingTemplate(tow1,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb02); - // 24 - MovingTemplate moveb20 = new MovingTemplate(tow1,berth2,berth0,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb20); - // 25 - MovingTemplate moveb12b = new MovingTemplate(tow1,berth1,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb12b); - // 26 - MovingTemplate moveb21b = new MovingTemplate(tow1,berth2,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb21b); - - // Швартовки - // 27 - MooringTemplate moore11p = new MooringTemplate(ship1,berth1,1.0,true,task.getTemplates().size()); moore11p.getResources().add(tow1); - task.getTemplates().add(moore11p); - // 28 - MooringTemplate moore11m = new MooringTemplate(ship1,berth1,1.0,false,task.getTemplates().size()); moore11m.getResources().add(tow1); - task.getTemplates().add(moore11m); - // 29 - MooringTemplate moore12p = new MooringTemplate(ship1,berth2,1.0,true,task.getTemplates().size()); moore12p.getResources().add(tow1); - task.getTemplates().add(moore12p); - // 30 - MooringTemplate moore12m = new MooringTemplate(ship1,berth2,1.0,false,task.getTemplates().size()); moore12m.getResources().add(tow1); - task.getTemplates().add(moore12m); - - // 31 - MooringTemplate moore21p = new MooringTemplate(ship2,berth1,1.0,true,task.getTemplates().size()); moore21p.getResources().add(tow1); - task.getTemplates().add(moore21p); - // 32 - MooringTemplate moore21m = new MooringTemplate(ship2,berth1,1.0,false,task.getTemplates().size()); moore21m.getResources().add(tow1); - task.getTemplates().add(moore21m); - // 33 - MooringTemplate moore22p = new MooringTemplate(ship2,berth2,1.0,true,task.getTemplates().size()); moore22p.getResources().add(tow1); - task.getTemplates().add(moore22p); - // 34 - MooringTemplate moore22m = new MooringTemplate(ship2,berth2,1.0,false,task.getTemplates().size()); moore22m.getResources().add(tow1); - task.getTemplates().add(moore22m); - - // Погрузки - // 35 - LoadingTemplate load11p = new LoadingTemplate(ship1,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load11p); - // 36 - LoadingTemplate load11m = new LoadingTemplate(ship1,berth1,storage1,-200.0,task.getTemplates().size()); - task.getTemplates().add(load11m); - // 37 - LoadingTemplate load12p = new LoadingTemplate(ship1,berth2,storage2,200.0,task.getTemplates().size()); - task.getTemplates().add(load12p); - // 38 - LoadingTemplate load12m = new LoadingTemplate(ship1,berth2,storage2,-200.0,task.getTemplates().size()); - task.getTemplates().add(load12m); - // 39 - LoadingTemplate load21p = new LoadingTemplate(ship2,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load21p); - // 40 - LoadingTemplate load21m = new LoadingTemplate(ship2,berth1,storage1,-200.0,task.getTemplates().size()); - task.getTemplates().add(load21m); - // 41 - LoadingTemplate load22p = new LoadingTemplate(ship2,berth2,storage2,200.0,task.getTemplates().size()); - task.getTemplates().add(load22p); - // 42 - LoadingTemplate load22m = new LoadingTemplate(ship2,berth2,storage2,-200.0,task.getTemplates().size()); - task.getTemplates().add(load22m); - - // Начальное состояние - TransportShipState sini1 = new TransportShipState(0.0, ship1, berth0, false); sini1.getCargoState().put(cargo1, 1000.0); - task.getVesselInitialState().add(sini1); - TransportShipState sini2 = new TransportShipState(0.0, ship2, berth0, false); sini2.getCargoState().put(cargo1, 0.0); - task.getVesselInitialState().add(sini2); - MovingObjectState sini3 = new MovingObjectState(tow1,berth0); - task.getVesselInitialState().add(sini3); - StorageState tini1 = new StorageState(storage1, 200.0); - task.getStorageInitialState().add(tini1); - StorageState tini2 = new StorageState(storage2, 800.0); - task.getStorageInitialState().add(tini2); - - // Конечное состояние - TransportShipState send1 = new TransportShipState(0.0, ship1, berth0, false); send1.getCargoState().put(cargo1, 0.0); - task.getVesselEndState().add(send1); - TransportShipState send2 = new TransportShipState(0.0, ship2, berth0, false); send2.getCargoState().put(cargo1, 1000.0); - task.getVesselEndState().add(send2); - - // Горизонт планирования - task.setPlanningInterval(18.0); - } - */ - - /* - // Тестовый вариант на заполнение всех полей - public static void fillByHand2(TaskCase task) - { - // Статические элементы - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - Cargo cargo1 = new Cargo(1.0, 1, "Excrement"); - task.getCargoes().add(cargo1); - Cargo cargo2 = new Cargo(1.0, 2, "Peaches"); - task.getCargoes().add(cargo2); - - - // Причалы - Berth berth0 = new Berth(0, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(1, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(2, "Pier 2", false); - task.getBerths().add(berth2); - - - // Хранилища - Storage storage1 = new Storage(1, "Storage 1", 1000.0, cargo1); - task.getStorages().add(storage1); - Storage storage2 = new Storage(2, "Storage 2", 1000.0, cargo2); - task.getStorages().add(storage2); - Storage storage3 = new Storage(3, "Storage 3", 1000.0, cargo0); - task.getStorages().add(storage3); - - // Оборудование - LoadingEquipment eq1 = new LoadingEquipment(1, "PeachPump 1"); - task.getEquipments().add(eq1); - LoadingEquipment eq2 = new LoadingEquipment(2, "PeachPump 2"); - task.getEquipments().add(eq2); - - - // Буксиры - Tow tow1 = new Tow(1, "Tow 1"); - task.getTows().add(tow1); - Tow tow2 = new Tow(2, "Tow 2"); - task.getTows().add(tow2); - - - // Бункеровщики - Bunker bunker1 = new Bunker(3, "Bunker 1"); - task.getBunkers().add(bunker1); - - - // Суда - TransportShip ship1 = new TransportShip(4, "Ship 1", 2000); - task.getShips().add(ship1); - TransportShip ship2 = new TransportShip(5, "Ship 2", 2000); - task.getShips().add(ship2); - - - // Шаблоны операций - - // Перемещения - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,5.0,task.getTemplates().size()); - task.getTemplates().add(move101); - MovingTemplate move201b1 = new MovingTemplate(ship2,berth0,berth2,2.0,task.getTemplates().size()); move201b1.getResources().add(tow1); - task.getTemplates().add(move201b1); - MovingTemplate move201b12 = new MovingTemplate(ship2,berth2,berth1,2.0,task.getTemplates().size()); move201b12.getResources().add(tow1); move201b12.getResources().add(tow2); - task.getTemplates().add(move201b12); - - - MovingTemplate moveb01 = new MovingTemplate(tow1,berth0,berth1,1.0,task.getTemplates().size()); - task.getTemplates().add(moveb01); - MovingTemplate movebk1 = new MovingTemplate(bunker1,berth0,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(movebk1); - - - // Швартовки - MooringTemplate moore11p = new MooringTemplate(ship1,berth1,0.2,true,task.getTemplates().size()); - task.getTemplates().add(moore11p); - MooringTemplate moore11p1b = new MooringTemplate(ship1,berth1,0.2,true,task.getTemplates().size()); moore11p1b.getResources().add(tow2); - task.getTemplates().add(moore11p1b); - - MooringTemplate moore21p = new MooringTemplate(ship2,berth2,0.5,true,task.getTemplates().size()); - task.getTemplates().add(moore21p); - MooringTemplate moore21p2b = new MooringTemplate(ship2,berth2,0.5,true,task.getTemplates().size()); moore21p2b.getResources().add(tow1); moore21p2b.getResources().add(tow2); - task.getTemplates().add(moore21p2b); - - // Погрузки - LoadingTemplate load11p = new LoadingTemplate(ship1,berth1,storage1,200.0,task.getTemplates().size()); - task.getTemplates().add(load11p); - LoadingTemplate load11m1r = new LoadingTemplate(ship1,berth1,storage1,-200.0,task.getTemplates().size()); load11m1r.getResources().add(eq1); - task.getTemplates().add(load11m1r); - LoadingTemplate load12p2r = new LoadingTemplate(ship1,berth2,storage2,10.0,task.getTemplates().size()); load12p2r.getResources().add(eq1); load11m1r.getResources().add(eq2); - task.getTemplates().add(load12p2r); - - // Бункеровки - BunkeringTemplate bunk1 = new BunkeringTemplate(ship1,berth0,null,bunker1,300.0,task.getTemplates().size()); - task.getTemplates().add(bunk1); - BunkeringTemplate bunk21 = new BunkeringTemplate(ship2,berth1,storage3,null,200.0,task.getTemplates().size()); - task.getTemplates().add(bunk21); - BunkeringTemplate bunk22 = new BunkeringTemplate(ship2,berth1,storage3,null,200.0,task.getTemplates().size()); bunk22.getResources().add(eq1); bunk22.getResources().add(eq2); - task.getTemplates().add(bunk22); - - // Внешние грузопотоки - CargoFlow cf1 = new CargoFlow(storage1); cf1.getFlow().put(0.0, -100.0); cf1.getFlow().put(1.0, -150.0); cf1.getFlow().put(2.0, 20.0); cf1.getFlow().put(3.0, 400.0); - task.getCargoFlows().add(cf1); - CargoFlow cf2 = new CargoFlow(storage2); cf2.getFlow().put(0.0, 100.0); - task.getCargoFlows().add(cf2); - - // Окна непогоды - TimeWindow tw1 = new TimeWindow(load11m1r); tw1.getBanWindows().put(5.2, 2.0); tw1.getBanWindows().put(12.6, 3.0); - task.getTimeWindowConstraints().add(tw1); - TimeWindow tw2 = new TimeWindow(moore21p2b); tw2.getBanWindows().put(3.2, 2.0); tw2.getBanWindows().put(8.3, 0.123); - task.getTimeWindowConstraints().add(tw2); - - - // Начальное состояние - TransportShipState sini1 = new TransportShipState(0.0, ship1, berth0, false); sini1.getCargoState().put(cargo1, 1000.0); - task.getVesselInitialState().add(sini1); - TransportShipState sini2 = new TransportShipState(0.0, ship2, berth0, false); sini2.getCargoState().put(cargo1, 0.0); sini2.getCargoState().put(cargo0, 130.0); - task.getVesselInitialState().add(sini2); - MovingObjectState sini3 = new MovingObjectState(tow1,berth0); - task.getVesselInitialState().add(sini3); - - StorageState tini1 = new StorageState(storage1, 200.0); - task.getStorageInitialState().add(tini1); - StorageState tini2 = new StorageState(storage2, 800.0); - task.getStorageInitialState().add(tini2); - StorageState tini3 = new StorageState(storage3, 500.0); - task.getStorageInitialState().add(tini3); - - // Конечное состояние - TransportShipState send1 = new TransportShipState(0.0, ship1, berth0, false); send1.getCargoState().put(cargo1, 0.0); send1.getCargoState().put(cargo2, 400.0); - task.getVesselEndState().add(send1); - TransportShipState send2 = new TransportShipState(0.0, ship2, berth0, false); send2.getCargoState().put(cargo1, 1000.0); send2.getCargoState().put(cargo0, 700.0); - task.getVesselEndState().add(send2); - - // Горизонт планирования - task.setPlanningInterval(520.0); - } - */ - - /// - /// Тест мобилизации средств грузообработки - /// - /// - public static void fillByHandBK(TaskCase task) - { - //Объекты - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - - - // Причалы - Berth berth0 = new Berth(1, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(2, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(3, "Pier 2", false); - task.getBerths().add(berth2); - - // Хранилища - Storage storage1 = new Storage(4, "Storage 1", 270.0, cargo0); - task.getStorages().add(storage1); - - - // Оборудование - LoadingEquipment floatingCrane = new LoadingEquipment(5, "Плавучий кран"); - task.getEquipments().add(floatingCrane); - - - // Буксиры - Tow tow1 = new Tow(6, "Tow 1"); - task.getTows().add(tow1); - - // Суда - TransportShip ship1 = new TransportShip(7, "Ship 1", 2000); - task.getShips().add(ship1); - - // Перемещения - // 1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,2.0,8+task.getTemplates().size()); move101.getResources().add(tow1); - task.getTemplates().add(move101); - // 2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,2.0,8+task.getTemplates().size()); move110.getResources().add(tow1); - task.getTemplates().add(move110); - // 3 - MovingTemplate movet20 = new MovingTemplate(tow1,berth2,berth0,2.0,8+task.getTemplates().size()); - task.getTemplates().add(movet20); - // 4 - MovingTemplate movet10 = new MovingTemplate(tow1,berth1,berth0,2.0,8+task.getTemplates().size()); - task.getTemplates().add(movet10); - // 5 - MovingTemplate movet12 = new MovingTemplate(tow1,berth1,berth2,1.0,8+task.getTemplates().size()); - task.getTemplates().add(movet12); - // 6 - MovingTemplate movek21 = new MovingTemplate(floatingCrane,berth2,berth1,2.0,8+task.getTemplates().size()); movek21.getResources().add(tow1); - task.getTemplates().add(movek21); - // 7 - LoadingTemplate lt = new LoadingTemplate(ship1,berth1,storage1,-20.0,8+task.getTemplates().size()); lt.getResources().add(floatingCrane); - task.getTemplates().add(lt); - - StorageState tini1 = new StorageState(storage1, cargo0, 0.0); - task.getStorageInitialState().add(tini1); - - // Начальное состояние - MovingObjectState sini1 = new MovingObjectState(ship1, berth0); - task.getVesselInitialState().add(sini1); - StorageState stini1 = new StorageState(ship1,cargo0, 100.0); - task.getStorageInitialState().add(stini1); - - MovingObjectState sini2 = new MovingObjectState(tow1, berth1); - task.getVesselInitialState().add(sini2); - MovingObjectState sini3 = new MovingObjectState(floatingCrane, berth2); - task.getVesselInitialState().add(sini3); - - MovingObjectState send1 = new MovingObjectState(ship1, berth0); - task.getVesselEndState().add(send1); - StorageState stend1 = new StorageState(ship1,cargo0, 0.0); - task.getStorageEndState().add(stend1); - - task.setPlanningInterval(18); - } - - /* - /// - /// Тест мобилизации средств грузообработки - /// - /// - public static void fillByHandTest(TaskCase task) - { - //Объекты - // Грузы - Cargo cargo0 = new Cargo(1.0, 0, "LNG"); - task.getCargoes().add(cargo0); - - - // Причалы - Berth berth0 = new Berth(0, "Raid", true); - task.getBerths().add(berth0); - Berth berth1 = new Berth(1, "Pier 1", false); - task.getBerths().add(berth1); - Berth berth2 = new Berth(2, "Pier 2", false); - task.getBerths().add(berth2); - - // Хранилища - Storage storage1 = new Storage(1, "Storage 1", 270.0, cargo0); - task.getStorages().add(storage1); - - - // Оборудование - LoadingEquipment floatingCrane = new LoadingEquipment(2, "Плавучий кран"); - task.getEquipments().add(floatingCrane); - - - // Буксиры - Tow tow1 = new Tow(1, "Tow 1"); - task.getTows().add(tow1); - - // Суда - TransportShip ship1 = new TransportShip(4, "Ship 1", 2000); - task.getShips().add(ship1); - - // Перемещения - // 1 - MovingTemplate move101 = new MovingTemplate(ship1,berth0,berth1,2.0,task.getTemplates().size()); move101.getResources().add(tow1); - task.getTemplates().add(move101); - // 2 - MovingTemplate move110 = new MovingTemplate(ship1,berth1,berth0,1.0,task.getTemplates().size()); move110.getResources().add(tow1); - task.getTemplates().add(move110); - // 3 - MovingTemplate movet20 = new MovingTemplate(tow1,berth2,berth0,2.0,task.getTemplates().size()); - task.getTemplates().add(movet20); - // 4 - MovingTemplate movet10 = new MovingTemplate(tow1,berth1,berth0,2.0,task.getTemplates().size()); - task.getTemplates().add(movet10); - // 5 - MovingTemplate movet12 = new MovingTemplate(tow1,berth1,berth2,1.0,task.getTemplates().size()); - task.getTemplates().add(movet12); - // 6 - MovingTemplate movek21 = new MovingTemplate(floatingCrane,berth2,berth1,2.0,task.getTemplates().size()); movek21.getResources().add(tow1); - task.getTemplates().add(movek21); - - // 7 - LoadingTemplate lt = new LoadingTemplate(ship1,berth1,storage1,100.0,task.getTemplates().size()); lt.getResources().add(floatingCrane); - task.getTemplates().add(lt); - - StorageState tini1 = new StorageState(storage1, 200.0); - task.getStorageInitialState().add(tini1); - - // Начальное состояние - TransportShipState sini1 = new TransportShipState(0.0, ship1, berth0, false); sini1.getCargoState().put(cargo0, 0.0); - task.getVesselInitialState().add(sini1); - - MovingObjectState sini2 = new MovingObjectState(tow1, berth1); - task.getVesselInitialState().add(sini2); - - MovingObjectState sini3 = new MovingObjectState(floatingCrane, berth2); - task.getVesselInitialState().add(sini3); - - TransportShipState send1 = new TransportShipState(0.0, ship1, berth0, false); send1.getCargoState().put(cargo0, 200.0); - task.getVesselEndState().add(send1); - - task.setPlanningInterval(12); - } - */ - -} diff --git a/src/LoadingEquipment.java b/src/LoadingEquipment.java deleted file mode 100644 index be591e8..0000000 --- a/src/LoadingEquipment.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class LoadingEquipment extends MovingObject{ - - - public LoadingEquipment() { - super(); - } - - public LoadingEquipment(int id, String name) { - super(id, name); - } - - @Override - public String toString() { - return getId() + ";" + getName(); - } - - public LoadingEquipment(String s) { - super(s); - } - -} diff --git a/src/LoadingTemplate.java b/src/LoadingTemplate.java deleted file mode 100644 index add3278..0000000 --- a/src/LoadingTemplate.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -import java.util.ArrayList; -import java.util.List; - -/** - * - * @author topazh_ag - */ -public class LoadingTemplate extends OperationTemplate { - - private TransportShip loader; - private Storage storage; - private List resources; - private double intensity; - - - /** - * Get the value of resources - * - * @return the value of resources - */ - public List getResources() { - return resources; - } - - /** - * Set the value of resources - * - * @param resources new value of resources - */ - public void setResources(List resources) { - this.resources = resources; - } - - public TransportShip getLoader() { - return loader; - } - - public void setLoader(TransportShip loader) { - this.loader = loader; - } - - public double getIntensity() { - return intensity; - } - - public void setIntensity(double intensity) { - this.intensity = intensity; - } - - public Storage getStorage() { - return storage; - } - - public void setStorage(Storage storage) { - this.storage = storage; - } - - public LoadingTemplate(TransportShip loader, Berth berth, Storage storage, double intensity, int id) { - super(id, berth); - this.loader = loader; - this.storage = storage; - this.resources = new ArrayList<>(); - this.intensity = intensity; - } - - public LoadingTemplate() { - this.resources = new ArrayList<>(); - } - - @Override - public String toString() { - String res = ""; - boolean first = true; - for(LoadingEquipment eq : resources) - { - if (!first) - res += "," + eq.getId(); - else - res += eq.getId(); - first = false; - } - int source = loader.getId(); - if (intensity>0) - source = storage.getId(); - int target = loader.getId(); - if (intensity<=0) - target = storage.getId(); - int cargos = storage.getCargo().getId(); - return getId() + ";" + "loa;" + twtoString() + ";" + source + ";" + cargos + ";" + target + ";" + getStartLocation().getId() + ";[" + res +"];"+Math.abs(intensity); - } -} diff --git a/src/MooringTemplate.java b/src/MooringTemplate.java deleted file mode 100644 index a496339..0000000 --- a/src/MooringTemplate.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class MooringTemplate extends TowUsingTemplate { - - private TransportShip moorer; - private boolean direct; - - /** - * Get the value of direction - * - * @return the value of direction - */ - public boolean isDirect() { - return direct; - } - - /** - * Set the value of direction - * - * @param direction new value of direction - */ - public void setDirect(boolean direct) { - this.direct = direct; - } - - /** - * Get the value of moorer - * - * @return the value of moorer - */ - public MovingObject getMoorer() { - return moorer; - } - - /** - * Set the value of moorer - * - * @param mover new value of moorer - */ - public void setMoorer(TransportShip moorer) { - this.moorer = moorer; - } - - public MooringTemplate(TransportShip moorer, Berth berth, double duration, boolean direct, int id) { - super(duration, id, berth); - this.moorer = moorer; - this.direct = direct; - } - - public MooringTemplate() { - super(); - } - - @Override - public String toString() { - String res = ""; - boolean first = true; - for(Tow eq : getResources()) - { - if (!first) - res += "," + eq.getId(); - else - res += eq.getId(); - first = false; - } - String code = "mrn"; - if (!direct) - code = "unm"; - return getId() + ";" + code + ";" + twtoString() + ";" + moorer.getId() + ";" + getStartLocation().getId() + ";[" + res +"];"+getDuration(); - } - -} diff --git a/src/MovingObject.java b/src/MovingObject.java deleted file mode 100644 index a0adedc..0000000 --- a/src/MovingObject.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class MovingObject { - - private int id; - private String name; - - /** - * Get the value of name - * - * @return the value of name - */ - public String getName() { - return name; - } - - /** - * Set the value of name - * - * @param name new value of name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Get the value of id - * - * @return the value of id - */ - public int getId() { - return id; - } - - /** - * Set the value of id - * - * @param id new value of id - */ - public void setId(int id) { - this.id = id; - } - - public MovingObject(int id, String name) { - this.id = id; - this.name = name; - } - - public MovingObject() { - } - - public MovingObject(String s) { - String[] tokens = s.split(";"); - id = Integer.parseInt(tokens[0].trim()); - name = tokens[1].trim(); - } - -} diff --git a/src/MovingObjectState.java b/src/MovingObjectState.java deleted file mode 100644 index ebaeb3b..0000000 --- a/src/MovingObjectState.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class MovingObjectState { - - private MovingObject vessel; - private Berth location; - - /** - * Get the value of location - * - * @return the value of location - */ - public Berth getLocation() { - return location; - } - - /** - * Set the value of location - * - * @param location new value of location - */ - public void setLocation(Berth location) { - this.location = location; - } - - /** - * Get the value of vessel - * - * @return the value of vessel - */ - public MovingObject getVessel() { - return vessel; - } - - /** - * Set the value of vessel - * - * @param vessel new value of vessel - */ - public void setVessel(MovingObject vessel) { - this.vessel = vessel; - } - - /** - * - * @param vessel - * @param location - */ - public MovingObjectState(MovingObject vessel, Berth location) { - this.vessel = vessel; - this.location = location; - } - - public MovingObjectState() { - } - - @Override - public String toString() { - return getVessel().getId() + ";" + getLocation().getId(); - } - - -} diff --git a/src/MovingTemplate.java b/src/MovingTemplate.java deleted file mode 100644 index 80063e6..0000000 --- a/src/MovingTemplate.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class MovingTemplate extends TowUsingTemplate { - - private MovingObject mover; - private Berth destination; - - - /** - * Get the value of destination - * - * @return the value of destination - */ - public Berth getDestination() { - return destination; - } - - /** - * Set the value of destination - * - * @param destination new value of destination - */ - public void setDestination(Berth destination) { - this.destination = destination; - } - - /** - * Get the value of mover - * - * @return the value of mover - */ - public MovingObject getMover() { - return mover; - } - - /** - * Set the value of mover - * - * @param mover new value of mover - */ - public void setMover(MovingObject mover) { - this.mover = mover; - } - - public MovingTemplate(MovingObject mover, Berth source, Berth destination, double duration, int id) { - super(duration, id, source); - this.mover = mover; - this.destination = destination; - } - - public MovingTemplate() { - super(); - } - - @Override - public String toString() { - String res = ""; - boolean first = true; - 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(); - } - - -} diff --git a/src/Operation.java b/src/Operation.java deleted file mode 100644 index e97d0b8..0000000 --- a/src/Operation.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class Operation { - - private OperationTemplate template; - private double start; - private double duration; - - /** - * Get the value of duration - * - * @return the value of duration - */ - public double getDuration() { - return duration; - } - - /** - * Set the value of duration - * - * @param duration new value of duration - */ - public void setDuration(double duration) { - this.duration = duration; - } - - - /** - * Get the value of start - * - * @return the value of start - */ - public double getStart() { - return start; - } - - /** - * Set the value of start - * - * @param start new value of start - */ - public void setStart(double start) { - this.start = start; - } - - - /** - * Get the value of template - * - * @return the value of template - */ - public OperationTemplate getTemplate() { - return template; - } - - /** - * Set the value of template - * - * @param template new value of template - */ - public void setTemplate(OperationTemplate template) { - this.template = template; - } - - public Operation() { - } - - @Override - public String toString() { - return template.getId() + "; R; " + start + "; " + duration; - } - - -} diff --git a/src/OperationTemplate.java b/src/OperationTemplate.java deleted file mode 100644 index a2d6003..0000000 --- a/src/OperationTemplate.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author topazh_ag - */ -public abstract class OperationTemplate { - - private int id; - private Berth startLocation; - Map timeWindows; - - /** - * Get the value of id - * - * @return the value of id - */ - public int getId() { - return id; - } - - /** - * Set the value of id - * - * @param id new value of id - */ - public void setId(int id) { - this.id = id; - } - - public Berth getStartLocation() { - return startLocation; - } - - public void setStartLocation(Berth startLocation) { - this.startLocation = startLocation; - } - - public Map getTimeWindows() { - return timeWindows; - } - - public void setBanWindows(Map timeWindows) { - this.timeWindows = timeWindows; - } - - protected String twtoString() { - String res = ""; - boolean first = true; - for(Double s : timeWindows.keySet()) - { - if (!first) - res += "," + s + ":" + timeWindows.get(s); - else - res += s + ":" + timeWindows.get(s); - first = false; - } - return "[" + res +"]"; - } - - public OperationTemplate(int id, Berth startLocation) { - this.id = id; - this.startLocation = startLocation; - this.timeWindows = new HashMap<>(); - } - - public OperationTemplate() { - this.timeWindows = new HashMap<>(); - } - - public void setTimeWindow(String s) { - this.timeWindows = new HashMap<>(); - String[] rs = s.replace("[", "").replace("]", "").split(","); - for (String crs : rs) - if (crs.length()>0) - { - String[] kv = crs.split(":"); - Double key1 = Double.parseDouble(kv[0]); - Double value1 = Double.parseDouble(kv[1]); - timeWindows.put(key1, value1); - } - } - -} diff --git a/src/SerializationHelper.java b/src/SerializationHelper.java deleted file mode 100644 index 889202f..0000000 --- a/src/SerializationHelper.java +++ /dev/null @@ -1,79 +0,0 @@ -package inport; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.StringWriter; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBElement; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.stream.util.StreamReaderDelegate; -import javax.xml.transform.stream.StreamResult; - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * - * @author topazh_ag - */ -public class SerializationHelper { - - public String serialize(Object object) throws Exception{ - StringWriter resultWriter = new StringWriter(); - StreamResult result = new StreamResult( resultWriter ); - XMLStreamWriter xmlStreamWriter = - XMLOutputFactory.newInstance().createXMLStreamWriter(result); - - JAXBContext context = JAXBContext.newInstance(object.getClass()); - Marshaller marshaller = context.createMarshaller(); - marshaller.marshal(new JAXBElement(new QName(object.getClass().getSimpleName()), object.getClass(), object), xmlStreamWriter); - - String res = resultWriter.toString(); - return res; - } - - public Object deserialize(String str, Class klass) throws Exception{ - - InputStream is = new ByteArrayInputStream(str.getBytes("UTF-8")); - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(is); - reader = new CamelCaseTransfomingReaderDelegate(reader, klass); - - JAXBContext context = JAXBContext.newInstance(klass); - Unmarshaller unmarshaller = context.createUnmarshaller(); - - JAXBElement elem = unmarshaller.unmarshal(reader, klass); - Object object = elem.getValue(); - - return object; - } - - //adapts to Java property naming style - private static class CamelCaseTransfomingReaderDelegate extends StreamReaderDelegate { - - Class klass = null; - - public CamelCaseTransfomingReaderDelegate(XMLStreamReader xsr, Class klass) { - super(xsr); - this.klass = klass; - } - - @Override - public String getLocalName() { - String nodeName = super.getLocalName(); - if (!nodeName.equals(klass.getSimpleName())) - { - nodeName = nodeName.substring(0, 1).toLowerCase() + - nodeName.substring(1, nodeName.length()); - } - return nodeName.intern(); //NOTE: intern very important!.. - } - } -} \ No newline at end of file diff --git a/src/Storage.java b/src/Storage.java deleted file mode 100644 index 0ceed25..0000000 --- a/src/Storage.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -import java.util.Map; - -/** - * - * @author topazh_ag - */ -public class Storage { - private int id; - private String name; - private double volume; - 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; - } - - - /** - * Get the value of volume - * - * @return the value of volume - */ - public double getVolume() { - return volume; - } - - /** - * Set the value of volume - * - * @param volume new value of volume - */ - public void setVolume(double volume) { - this.volume = volume; - } - - /** - * Get the value of name - * - * @return the value of name - */ - public String getName() { - return name; - } - - /** - * Set the value of name - * - * @param name new value of name - */ - public void setName(String name) { - this.name = name; - } - - /** - * Get the value of id - * - * @return the value of id - */ - public int getId() { - return id; - } - - /** - * Set the value of id - * - * @param id new value of id - */ - public void setId(int id) { - this.id = id; - } - - public Storage(int id, String name, double volume, Cargo cargo) { - this.id = id; - this.name = name; - this.volume = volume; - this.cargo = cargo; - } - - public Storage() { - } - - @Override - public String toString() { - return id + ";" + name + ";" + cargo.getId() + ";" +volume; - } - - public Storage(String s, Map cargoes) { - String[] tokens = s.split(";"); - id = Integer.parseInt(tokens[0].trim()); - name = tokens[1].trim(); - volume = Double.parseDouble(tokens[3].trim()); - int key = Integer.parseInt(tokens[2].trim()); - cargo = cargoes.get(key); - } -} diff --git a/src/StorageState.java b/src/StorageState.java deleted file mode 100644 index d2f9650..0000000 --- a/src/StorageState.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -import java.util.Map; - -/** - * - * @author topazh_ag - */ -public class StorageState { - - private Object storage; - private Cargo cargo; - private double cargoState; - - /** - * Get the value of storage - * - * @return the value of storage - */ - public Object getStorage() { - return storage; - } - - /** - * Set the value of storage - * - * @param storage new value of storage - */ - public void setStorage(Object storage) { - this.storage = storage; - } - - public Cargo getCargo() { - return cargo; - } - - public void setCargo(Cargo cargo) { - this.cargo = cargo; - } - - /** - * Get the value of cargoState - * - * @return the value of cargoState - */ - public double getCargoState() { - return cargoState; - } - - /** - * Set the value of cargoState - * - * @param cargoState new value of cargoState - */ - public void setCargoState(double cargoState) { - this.cargoState = cargoState; - } - - /** - * - * @param storage - */ - public StorageState(Object storage, Cargo cargo, double cargoState) { - this.storage = storage; - this.cargo = cargo; - this.cargoState = cargoState; - } - - public StorageState() { - } - - @Override - public String toString() { - if (storage instanceof Storage) - return cargo.getId() + ";" + ((Storage)storage).getId() + ";" + cargoState; - if (storage instanceof TransportShip) - return cargo.getId() + ";" + ((TransportShip)storage).getId() + ";" + cargoState; - return ""; - } - - public StorageState(String s, Map mp, Map vp, Map cp) { - String[] tokens = s.split(";"); - int key = Integer.parseInt(tokens[0].trim()); - cargo = cp.get(key); - key = Integer.parseInt(tokens[1].trim()); - if (mp.containsKey(key)) - storage = mp.get(key); - if (vp.containsKey(key)) - storage = vp.get(key); - cargoState = Double.parseDouble(tokens[2].trim()); - } - -} diff --git a/src/TaskCase.java b/src/TaskCase.java deleted file mode 100644 index 5366df3..0000000 --- a/src/TaskCase.java +++ /dev/null @@ -1,1644 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -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.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author topazh_ag - */ -public class TaskCase { - - // Статическая структура порта - private List cargoes; - private List berths; - private List storages; - private List bunkers; - private List tows; - private List equipments; - - // Обслуживаемые суда - private List ships; - - // Шаблоны операций - private List templates; - - // Внешние грузопотоки - private List cargoFlows; - - // Начальное состояние - private List vesselInitialState; - private List storageInitialState; - - // Конечное состояние - private List vesselEndState; - private List storageEndState; - - // Горизонт планирования - private double planningInterval; - - // Тип критерия оптимизации - private int criterionType; - - // План - критерий - private double solution_result; - - // План - решение - private List solution; - - /** - * Get the value of solution - * - * @return the value of solution - */ - public List getSolution() { - return solution; - } - - /** - * Set the value of solution - * - * @param solution new value of solution - */ - public void setSolution(List solution) { - this.solution = solution; - } - - /** - * Get the value of planningInterval - * - * @return the value of planningInterval - */ - public double getPlanningInterval() { - return planningInterval; - } - - /** - * Set the value of planningInterval - * - * @param planningInterval new value of planningInterval - */ - public void setPlanningInterval(double planningInterval) { - this.planningInterval = planningInterval; - } - - public int getCriterionType() { - return criterionType; - } - - public void setCriterionType(int criterionType) { - this.criterionType = criterionType; - } - - public double getSolution_result() { - return solution_result; - } - - public void setSolution_result(double solution_result) { - this.solution_result = solution_result; - } - - /** - * Get the value of cargoFlows - * - * @return the value of cargoFlows - */ - public List getCargoFlows() { - return cargoFlows; - } - - /** - * Set the value of cargoFlows - * - * @param cargoFlows new value of cargoFlows - */ - public void setCargoFlows(List cargoFlows) { - this.cargoFlows = cargoFlows; - } - - /** - * Get the value of vesselEndState - * - * @return the value of vesselEndState - */ - public List getVesselEndState() { - return vesselEndState; - } - - /** - * Set the value of vesselEndState - * - * @param vesselEndState new value of vesselEndState - */ - public void setVesselEndState(List vesselEndState) { - this.vesselEndState = vesselEndState; - } - - public List getStorageEndState() { - return storageEndState; - } - - public void setStorageEndState(List storageEndState) { - this.storageEndState = storageEndState; - } - - - /** - * Get the value of storageInitialState - * - * @return the value of storageInitialState - */ - public List getStorageInitialState() { - return storageInitialState; - } - - /** - * Set the value of storageInitialState - * - * @param storageInitialState new value of storageInitialState - */ - public void setStorageInitialState(List storageInitialState) { - this.storageInitialState = storageInitialState; - } - - - /** - * Get the value of vesselInitialState - * - * @return the value of vesselInitialState - */ - public List getVesselInitialState() { - return vesselInitialState; - } - - /** - * Set the value of vesselInitialState - * - * @param vesselInitialState new value of vesselInitialState - */ - public void setVesselInitialState(List vesselInitialState) { - this.vesselInitialState = vesselInitialState; - } - - - - /** - * Get the value of templates - * - * @return the value of templates - */ - public List getTemplates() { - return templates; - } - - /** - * Set the value of templates - * - * @param templates new value of templates - */ - public void setTemplates(List templates) { - this.templates = templates; - } - - - - /** - * Get the value of ships - * - * @return the value of ships - */ - public List getShips() { - return ships; - } - - /** - * Set the value of ships - * - * @param ships new value of ships - */ - public void setShips(List ships) { - this.ships = ships; - } - - - - /** - * Get the value of equipments - * - * @return the value of equipments - */ - public List getEquipments() { - return equipments; - } - - /** - * Set the value of equipments - * - * @param equipments new value of equipments - */ - public void setEquipments(List equipments) { - this.equipments = equipments; - } - - - - /** - * Get the value of tows - * - * @return the value of tows - */ - public List getTows() { - return tows; - } - - /** - * Set the value of tows - * - * @param tows new value of tows - */ - public void setTows(List tows) { - this.tows = tows; - } - - - /** - * Get the value of bunkers - * - * @return the value of bunkers - */ - public List getBunkers() { - return bunkers; - } - - /** - * Set the value of bunkers - * - * @param bunkers new value of bunkers - */ - public void setBunkers(List bunkers) { - this.bunkers = bunkers; - } - - /** - * Get the value of storages - * - * @return the value of storages - */ - public List getStorages() { - return storages; - } - - /** - * Set the value of storages - * - * @param storages new value of storages - */ - public void setStorages(List storages) { - this.storages = storages; - } - - /** - * Get the value of cargoes - * - * @return the value of cargoes - */ - public List getCargoes() { - return cargoes; - } - - /** - * Set the value of cargoes - * - * @param cargoes new value of cargoes - */ - public void setCargoes(List cargoes) { - this.cargoes = cargoes; - } - - /** - * Get the value of berths - * - * @return the value of berths - */ - public List getBerths() { - return berths; - } - - /** - * Set the value of berths - * - * @param berths new value of berths - */ - public void setBerths(List berths) { - this.berths = berths; - } - - public TaskCase() { - cargoes = new ArrayList<>(); - berths = new ArrayList<>(); - storages = new ArrayList<>(); - bunkers = new ArrayList<>(); - tows = new ArrayList<>(); - equipments = new ArrayList<>(); - ships = new ArrayList<>(); - - templates = new ArrayList<>(); - - cargoFlows = new ArrayList<>(); - - vesselInitialState = new ArrayList<>(); - storageInitialState = new ArrayList<>() ; - - vesselEndState = new ArrayList<>(); - storageEndState = new ArrayList<>(); - - solution = new ArrayList<>(); - - } - - private MovingObjectState fromString(String s, Map m_berth, Map m_vessel) - { - String[] tkns1 = s.split(";"); - MovingObjectState st = new MovingObjectState(); - int key = Integer.parseInt(tkns1[0].trim()); - MovingObject vs = m_vessel.get(key); - st.setVessel(vs); - key = Integer.parseInt(tkns1[1].trim()); - st.setLocation(m_berth.get(key)); - return st; - } - - 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 - { - fstream = new FileInputStream(fileName); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine; - int index = 0; - 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_template = new HashMap<>(); - //Read File Line By Line - int numInside = 0; - while ((strLine = br.readLine()) != null) - { - numInside ++; - boolean serviceString = false; - for (int i = 0; i0) - { - key = Integer.parseInt(crs.trim()); - mt.getResources().add((Tow)m_vessel.get(key)); - } - mt.setDuration(Double.parseDouble(tokens[7].trim())); - templates.add(mt); - m_template.put(mt.getId(), mt); - } - if (tokens[1].trim().equals("mrn") || tokens[1].trim().equals("unm")) - { - MooringTemplate mt = new MooringTemplate(); - mt.setId(Integer.parseInt(tokens[0].trim())); - mt.setDirect(true); - if (tokens[1].trim().equals("unm")) - mt.setDirect(false); - mt.setTimeWindow(tokens[2].trim()); - int key = Integer.parseInt(tokens[3].trim()); - 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) - { - key = Integer.parseInt(crs.trim()); - mt.getResources().add((Tow)m_vessel.get(key)); - } - mt.setDuration(Double.parseDouble(tokens[6].trim())); - templates.add(mt); - m_template.put(mt.getId(), mt); - } - if (tokens[1].trim().equals("loa")) - { - LoadingTemplate mt = new LoadingTemplate(); - mt.setId(Integer.parseInt(tokens[0].trim())); - mt.setTimeWindow(tokens[2].trim()); - int direct = 1; - // Источник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом - 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; - } - // Груз. Пока не нужен - // Приемник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом - 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; - } - 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) - { - key = Integer.parseInt(crs.trim()); - mt.getResources().add(m_equiopment.get(key)); - } - mt.setIntensity(direct*Double.parseDouble(tokens[8].trim())); - templates.add(mt); - m_template.put(mt.getId(), mt); - } - break; - case 9: - break; - case 10: cargoFlows.add(new CargoFlow(strLine, m_storage, m_cargo)); - break; - case 11: vesselInitialState.add(fromString(strLine, m_berth, m_vessel)); - break; - case 12: storageInitialState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo)); - break; - case 13: vesselEndState.add(fromString(strLine, m_berth, m_vessel)); - break; - case 14: storageEndState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo)); - break; - case 15: - { - String[] rs = strLine.split(";"); - planningInterval = Double.parseDouble(rs[0].trim()); - criterionType = Integer.parseInt(rs[1].trim()); - } - break; - case 16: // Тут чтение операций если надо. Потом подумаем - break; - default: - break; - } - } - //Close the input stream - br.close(); - } catch (FileNotFoundException ex) { - Logger.getLogger(TaskCase.class.getName()).log(Level.SEVERE, null, ex); - } - } - - public void serialize(String fileName) - { - 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(); - } - catch(IOException ex){ - - System.out.println(ex.getMessage()); - } - } - - public void formSolutionFromPB(int res[]) - { - int nTimes = (int) (planningInterval + 1.0 - 1e-7); - int rLength = res.length; - solution_result = 0.0; - for (int k=1; k<=nTimes; k++) - if (res[rLength-k]>0) - { - solution_result = nTimes - k + 1; - break; - } - int cIndex = -1; - - for (OperationTemplate template : templates) - { - boolean inBlock = false; - int duration = 0; - Operation operation = null; - for (int i=0; i0) - { - if (inBlock) - duration++; - else - { - // Это начало блока - operation = new Operation(); - operation.setTemplate(template); - operation.setStart(i+1); - inBlock = true; - } - } else - { - if (inBlock) - { - // Это окончание блока - operation.setDuration(duration+1.0); - duration = 0; - solution.add(operation); - inBlock = false; - } - - } - } - if (inBlock) - { - // Это окончание блока - operation.setDuration(duration+1.0); - solution.add(operation); - } - } - } - - private boolean isCompatible(OperationTemplate t1, OperationTemplate t2) - { - MovingObject doer1 = getDoer(t1); - Berth place1 = t1.getStartLocation(); - List resources1 = getResources(t1); - MovingObject doer2 = getDoer(t2); - Berth place2 = t2.getStartLocation(); - List resources2 = getResources(t2); - // Пересекаемость ресурсов - for (Object res2 : resources2) - if (resources1.contains(res2)) - return false; - // Выполнитель = ресурс - if (resources1.contains(doer2)) - return false; - // Ресурс = выполнитель - if (resources2.contains(doer1)) - return false; - - // Выполнитель = выполнитель - if (doer1.equals(doer2)) - { - // Это не погрузка - if (!(t1 instanceof LoadingTemplate) || (!(t2 instanceof LoadingTemplate))) - return false; - // Разные причалы - if (!place1.equals(place2)) - return false; - Storage s1 = ((LoadingTemplate)t1).getStorage(); - Storage s2 = ((LoadingTemplate)t2).getStorage(); - // В одно хранилище - if (s1.equals(s2)) - return false; - } - else - // На одном причале и это не перемещения - if (place1.equals(place2) && (!(t1 instanceof MovingTemplate)) && (!(t2 instanceof MovingTemplate))) - return false; - - return true; - } - - MovingObject getDoer(OperationTemplate t) - { - if (t instanceof LoadingTemplate) - return ((LoadingTemplate)t).getLoader(); - if (t instanceof MooringTemplate) - return ((MooringTemplate)t).getMoorer(); - if (t instanceof MovingTemplate) - return ((MovingTemplate)t).getMover(); - return null; - } - - List getResources(OperationTemplate t) - { - List res = new ArrayList<>(); - if (t instanceof LoadingTemplate) - res.addAll(((LoadingTemplate)t).getResources()); - if (t instanceof MooringTemplate) - res.addAll(((MooringTemplate)t).getResources()); - if (t instanceof MovingTemplate) - res.addAll(((MovingTemplate)t).getResources()); - return res; - } - - private String xij(int i, int j, int nJ, boolean plus) - { - int number = i*nJ + j + 1; - String prefix = ""; - if (!plus) - prefix ="~"; - return prefix+"x"+number; - } - - private String wrbj(int r, int b, int j, int nB, int nJ, int nIni, boolean isMooring, boolean moored, boolean plus) - { - int number = nIni + r*nJ*nB + b*nJ + j + 1; - if (isMooring) - { - if (moored) - number = nIni + r*nJ*nB*2 + b*nJ*2 + nJ + j + 1; - else - number = nIni + r*nJ*nB*2 + b*nJ*2 + j + 1; - } - String prefix = ""; - if (!plus) - prefix ="~"; - return prefix+"x"+number; - } - - private String sum1(List iks, int j, int nJ, int weight) - { - String res = ""; - for (Integer ik : iks) - res += " +" + weight + " "+xij(ik, j, nJ, true); - return res; - } - - private String fj(int j, int nBefore, boolean plus) - { - int number = nBefore + j + 1; - String prefix = ""; - if (!plus) - prefix ="~"; - return prefix+"x"+number; - } - - - - public int pb_formalize(String fileName/*, int indent*/) throws IOException - { - - - FileWriter writer = new FileWriter("temp", false); - int nCons = 0; - - List vss = new ArrayList(); - vss.addAll(ships); - vss.addAll(bunkers); - vss.addAll(tows); - vss.addAll(equipments); - - // Выяснение вопроса с наличием швартовки - boolean isMooring = false; - for (OperationTemplate tp : templates) - if (tp instanceof MooringTemplate) - { - isMooring = true; - break; - } - - - - - int nTimes = (int) (planningInterval + 1.0 - 1e-7); - int nOperations = templates.size(); - int nVars = nTimes*nOperations; - int nBerths = berths.size(); - int nVessels = vss.size(); - int mult =1; - if (isMooring) - mult = 2; - int nSuppVars = nVessels*nBerths*mult*nTimes; - int nBefore = nVars + nSuppVars; - int nAfter = nTimes; - - // String s1 = wrbj(0, 1, 17, 6, 18, 756, true, true, true); - // String s2 = wrbj(0, 2, 0, 6, 18, 756, true, false, true); - // String s23 = s1+s2; - - // Критерий оптимизации старый - /* - nAfter = 0; - String crit = ""; - int degree = 1; - for (int j=nTimes - indent; j starts = tp.timeWindows.keySet(); - for (Double start : starts) - { - // Определяем стартовый индекс - int jstart = (int)(start.doubleValue()); - Double duration = tp.timeWindows.get(start); - int jend = (int)(start.doubleValue()+duration.doubleValue()); - for (int j=jstart; j<=jend; j++) - { - writer.write(" +1 "+xij(i,j,nTimes,true)+" = 0 ;\n"); - nCons++; - } - } - } - - //!!!! Неразделимость ресурсов для операций. - writer.write("* Resource Unsharedness \n"); - // Новая байда - for (int i1 = 0; i1 excluders = new ArrayList(); - for (int i2 = i1+1; i20) - { - for (int j=0; j= 1 ;\n"); - nCons++; - } - } - } - - /* - // Старая байда - - // Буксиры - writer.write("* For Tows \n"); - for (Tow tow : tows) - { - List iks = new ArrayList(); - for (OperationTemplate tpl : templates) - { - int ik = templates.indexOf(tpl); - if (tpl instanceof MovingTemplate) - { - MovingTemplate mt = (MovingTemplate)tpl; - if (mt.getMover().equals(tow)) - iks.add(ik); - if (mt.getResources().contains(tow)) - iks.add(ik); - } - if (tpl instanceof MooringTemplate) - { - MooringTemplate mt = (MooringTemplate)tpl; - if (mt.getResources().contains(tow)) - iks.add(ik); - } - } - - if (!iks.isEmpty()) - for (int j=0; j iks = new ArrayList(); - for (OperationTemplate tpl : templates) - { - int ik = templates.indexOf(tpl); - if (tpl instanceof LoadingTemplate) - { - LoadingTemplate mt = (LoadingTemplate)tpl; - if (mt.getResources().contains(le)) - iks.add(ik); - } - if (tpl instanceof BunkeringTemplate) - { - BunkeringTemplate bt = (BunkeringTemplate)tpl; - if (bt.getResources().contains(le)) - iks.add(ik); - } - } - if (!iks.isEmpty()) - for (int j=0; j iks = new ArrayList(); - for (OperationTemplate tpl : templates) - { - int ik = templates.indexOf(tpl); - if (tpl instanceof BunkeringTemplate) - { - BunkeringTemplate bt = (BunkeringTemplate)tpl; - if (bt.getBunker().equals(bk)) - iks.add(ik); - } - } - if (!iks.isEmpty()) - for (int j=0; j mrks = new ArrayList(); - List> opbs = new ArrayList>(); - for (TransportShip ship : ships) - opbs.add(new ArrayList()); - boolean filled = false; - for (OperationTemplate tpl : templates) - { - int ik = templates.indexOf(tpl); - - if (tpl instanceof MooringTemplate) - { - MooringTemplate mt = (MooringTemplate)tpl; - if (mt.getBerth().equals(bt)) - { - mrks.add(ik); - int ind = ships.indexOf(mt.getMoorer()); - if (ind>=0) - { - opbs.get(ind).add(ik); - filled = true; - } - } - } - if (tpl instanceof LoadingTemplate) - { - LoadingTemplate lt = (LoadingTemplate)tpl; - if (lt.getBerth().equals(bt)) - { - int ind = ships.indexOf(lt.getLoader()); - if (ind>=0) - { - opbs.get(ind).add(ik); - filled = true; - } - } - } - if (tpl instanceof BunkeringTemplate) - { - BunkeringTemplate bkt = (BunkeringTemplate)tpl; - if (bkt.getBerth().equals(bt)) - { - int ind = ships.indexOf(bkt.getLoader()); - if (ind>=0) - { - opbs.get(ind).add(ik); - filled = true; - } - } - } - - - } - // На причале одновременно выполняется только одна операция швартовки - if (!mrks.isEmpty()) - for (int j=0; j vsops : opbs) - { - if (!vsops.isEmpty()) - { - nVess ++; - String vsop = " +1 "; - for (Integer i : vsops) - vsop += xij(i,j,nTimes,false) + " "; - clause += vsop; - } - } - writer.write(clause + " >= " + (nVess-1) + " ; \n"); - nCons++; - } - - } - - // Суда - writer.write("* For Vessels \n"); - for (MovingObject vs : vss) - { - List mvks = new ArrayList(); - List loks = new ArrayList(); - List mrks = new ArrayList(); - - for (OperationTemplate tpl : templates) - { - int ik = templates.indexOf(tpl); - - // Перемещения - if (tpl instanceof MovingTemplate) - { - MovingTemplate mt = (MovingTemplate)tpl; - if (mt.getMover().equals(vs)) - mvks.add(ik); - } - // Погрузка - if (tpl instanceof LoadingTemplate) - { - LoadingTemplate lt = (LoadingTemplate)tpl; - if (lt.getLoader().equals(vs)) - loks.add(ik); - } - // Швартовка - if (tpl instanceof MooringTemplate) - { - MooringTemplate rt = (MooringTemplate)tpl; - if (rt.getMoorer().equals(vs)) - mrks.add(ik); - } - // Бункеровка - if (tpl instanceof BunkeringTemplate) - { - BunkeringTemplate bt = (BunkeringTemplate)tpl; - if (bt.getLoader().equals(vs)) - loks.add(ik); - } - } - // Судно только в одном перемещении и при этом не может быть ни под погрузкой, ни под швартовкой - - if (!mvks.isEmpty()) - { - int nLM = loks.size()+mrks.size()+1; - for (int j=0; j0) - { - String res = "+1 " + xij(ik,0,nTimes,false) + " +1 "+xij(ik,0,nTimes,true); - for (int k=0; k= 1 ;\n"); - nCons++; - for (int j=1; j= 0 ;\n"); - nCons++; - } - } - - } - - // Ограничения на объем хранилищ. Проверить!!! - writer.write("* Current Storage Volume Constraints \n"); - for (Storage st : storages) - { - int V = (int)st.getVolume(); - double V0 = 0; - for (StorageState sst : storageInitialState) - if (sst.getStorage().equals(st)) - { - V0 = (int)sst.getCargoState(); - break; - } - CargoFlow ccf = null; - for (CargoFlow cf : cargoFlows) - if (cf.getStorage().equals(st)) - { - ccf = cf; - break; - } - List lts = new ArrayList(); - for (OperationTemplate tpl : templates) - { - if (tpl instanceof LoadingTemplate) - { - LoadingTemplate lt = (LoadingTemplate)tpl; - if (lt.getStorage().equals(st)) - lts.add(lt); - } - } - if (lts.size()>0) - { - for (int j=0; j= " + (int)(-sumV) + " ;\n"; - writer.write(cl1); - nCons++; - String cl2 = clause + " <= " + (int)(V-sumV) + " ;\n"; - writer.write(cl2); - nCons++; - } - } - - } - - // Определение локационных переменных - writer.write("* Location Variables \n"); - for (MovingObject v : vss) - { - // Нахождение начального состояния для судна. Потом читать из незавершенных операций - MovingObjectState iniState = null; - int iniTime = 0; - boolean iniMoored = false; - for (MovingObjectState state : vesselInitialState) - if (state.getVessel().equals(v)) - { - iniState = state; - break; - } - - int r = vss.indexOf(v); - for (Berth berth : berths) - { - int b = berths.indexOf(berth); - // Сперва ограничения на начальное состояние - if (iniState!=null && iniState.getLocation().equals(berth)) - { - // До прибытия - for(int j=0; j rb_plus = new ArrayList(); - List rb_minus = new ArrayList(); - List rm_plus = new ArrayList(); - List rm_minus = new ArrayList(); - for (OperationTemplate tp : templates) - { - if (tp instanceof MovingTemplate) - { - int idx = templates.indexOf(tp); - MovingTemplate mtp = (MovingTemplate)tp; - // Перемещение основного судна - if (mtp.getMover().equals(v)) - { - if (mtp.getDestination().equals(berth)) - rb_plus.add(idx); - if (mtp.getStartLocation().equals(berth)) - rb_minus.add(idx); - } - // Перемещение его помоганцев - for (Tow tow : mtp.getResources()) - if (tow.equals(v)) - { - if (mtp.getDestination().equals(berth)) - rb_plus.add(idx); - if (mtp.getStartLocation().equals(berth)) - rb_minus.add(idx); - } - } - // TODO: отработка швартовки - if (tp instanceof MooringTemplate) - { - int idx = templates.indexOf(tp); - MooringTemplate mtp = (MooringTemplate)tp; - // Перемещение основного судна - if (mtp.getMoorer().equals(v)) - { - if (mtp.getStartLocation().equals(berth) && mtp.isDirect()) // Пришвартовка - { - rm_plus.add(idx); - rb_minus.add(idx); - } - if (mtp.getStartLocation().equals(berth) && (!mtp.isDirect())) // Отшвартовка - { - rm_minus.add(idx); - rb_plus.add(idx); - } - } - } - } - - if (true) //(rb_plus.size()>0 && rb_minus.size()>0) - { - for (int j=1; j0 && rm_minus.size()>0) - { - for (int j=1; j resources_f = new ArrayList(); // Свободные - List resources_m = new ArrayList(); // Пришвартованные - Berth b = tp.getStartLocation(); - boolean isAlways = true; - if (tp instanceof LoadingTemplate) - { - int idx = vss.indexOf(((LoadingTemplate)tp).getLoader()); - if (b.getIsRaid() || (!isMooring)) - resources_f.add(idx); - else - resources_m.add(idx); - for (MovingObject mo : ((LoadingTemplate)tp).getResources()) - resources_f.add(vss.indexOf(mo)); - } - if (tp instanceof MooringTemplate) - { - int idx = vss.indexOf(((MooringTemplate)tp).getMoorer()); - if (((MooringTemplate)tp).isDirect()) - resources_f.add(idx); - else - resources_m.add(idx); - for (Tow tow : ((MooringTemplate)tp).getResources()) - resources_f.add(vss.indexOf(tow)); - isAlways = false; - } - if (tp instanceof MovingTemplate) - { - int idx = vss.indexOf(((MovingTemplate)tp).getMover()); - resources_f.add(idx); - for (Tow tow : ((MovingTemplate)tp).getResources()) - resources_f.add(vss.indexOf(tow)); - isAlways = false; - } - int bi = berths.indexOf(b); - for (int j=0; j0) - clause = "-1 " + xij(i, j, nTimes, true) + " " + xij(i, j-1, nTimes, false) + " +1 " + xij(i, j, nTimes, true) +" " + xij(i, j-1, nTimes, false); - String clause_f = clause; - String clause_m = clause; - if (resources_f.size()>0) - { - for (Integer r : resources_f) - clause_f += " " + wrbj(r, bi, j, nBerths, nTimes, nVars, isMooring, false, true); - if (isAlways || j==0) - writer.write(clause_f + " >= 1 ;\n"); - else - writer.write(clause_f + " >= 0 ;\n"); - nCons++; - } - if (resources_m.size()>0) - { - for (Integer r : resources_m) - clause_m += " " + wrbj(r, bi, j, nBerths, nTimes, nVars, isMooring, true, true); - if (isAlways || j==0) - writer.write(clause_m + " >= 1 ;\n"); - else - writer.write(clause_m + " >= 0 ;\n"); - nCons++; - } - } - } - - // Состояние загрузки судов - writer.write("* Ship Loading States \n"); - // Тут пок огшраничение только на местонахождение транспортных судов - for (TransportShip s : ships) - { - StorageState state1 = null; - StorageState state2 = null; - MovingObjectState eState = null; - for (StorageState state : storageInitialState) - if (state.getStorage().equals(s)) - { - state1 = (StorageState)state; - break; - } - for (StorageState state : storageEndState) - if (state.getStorage().equals(s)) - { - state2 = (StorageState)state; - break; - } - for (MovingObjectState state : vesselEndState) - if (state.getVessel().equals(s)) - { - eState = (MovingObjectState)state; - break; - } - for (Cargo c : cargoes) - { - int start = 0; - int finish = 0; - if (state1!=null && state1.getCargo().equals(c)) - start = (int)state1.getCargoState(); - if (state2!=null && state2.getCargo().equals(c)) - finish = (int)state2.getCargoState(); - List vc = new ArrayList(); - List intens = new ArrayList(); - for (OperationTemplate tp : templates) - if (tp instanceof LoadingTemplate) - { - int i = templates.indexOf(tp); - LoadingTemplate ltp = (LoadingTemplate)tp; - if (ltp.getLoader().equals(s) && ltp.getStorage().getCargo().equals(c)) - { - vc.add(i); - intens.add((int)ltp.getIntensity()); - } - } - for (int j=0; j0) - clause += " +" + intens.get(counter) + " " +xij(vci, k, nTimes, true); - if (intens.get(counter)<0) - clause += " " + intens.get(counter) + " " +xij(vci, k, nTimes, true); - counter++; - } - } - if (clause.length()>0) - { - if (j= -" + start + " ;\n"); - nCons++; - } - // Ограничение на грузоподъемность судна - int maxLoad = (int)(s.getCargoMax()+1.0); - if (sumplus > (maxLoad - start)) - { - writer.write(clause + " <= " + (maxLoad - start) + " ;\n"); - nCons++; - } - } - else - { - // Конечное состояние судна - writer.write(clause + " = " + (finish - start) + " ;\n"); - nCons++; - } - } - } - } - - // Нахождение всех судов в конечный момент в нужном состоянии - writer.write("* Final Ship Locations \n"); - if (eState!=null) - { - int vi = vss.indexOf(s); - for (Berth berth : berths) - { - int bi = berths.indexOf(berth); - String clause = " +1 "+wrbj(vi, bi, nTimes-1, nBerths, nTimes, nVars, isMooring, false, true) + " = "; - if (eState.getLocation().equals(berth)) - { - writer.write(clause + "1 ;\n"); - nCons++; - } - else - { - writer.write(clause + "0 ;\n"); - nCons++; - } - } - } - - } - - // Невозможность одновременного нахождения двух пришвартованных судов у одного причала - writer.write("* No more than 1 vessel moored to berth \n"); - if (isMooring) - { - for (Berth b : berths) - { - if (b.getIsRaid()) - continue; - int bdx = berths.indexOf(b); - for (int j=1; j resources; - private double duration; - - - /** - * Get the value of resources - * - * @return the value of resources - */ - public List getResources() { - return resources; - } - - /** - * Set the value of resources - * - * @param resources new value of resources - */ - public void setResources(List resources) { - this.resources = resources; - } - - /** - * Get the value of duration - * - * @return the value of duration - */ - public double getDuration() { - return duration; - } - - /** - * Set the value of duration - * - * @param duration new value of duration - */ - public void setDuration(double duration) { - this.duration = duration; - } - - - - public TowUsingTemplate(double duration, int id, Berth startLocation) { - super(id, startLocation); - this.resources = new ArrayList<>(); - this.duration = duration; - } - - public TowUsingTemplate() { - this.resources = new ArrayList<>(); - } - - @Override - public String toString() { - String res = ""; - boolean first = true; - for(Tow eq : resources) - { - if (!first) - res += "," + eq.getId(); - else - res += eq.getId(); - first = false; - } - return getId() + ";" + "tut" + ";" + ";[" + res +"];"+duration; - } - - -} diff --git a/src/TransportShip.java b/src/TransportShip.java deleted file mode 100644 index 9c64925..0000000 --- a/src/TransportShip.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package inport; - -/** - * - * @author topazh_ag - */ -public class TransportShip extends MovingObject { - - private double cargoMax; - - public double getCargoMax() { - return cargoMax; - } - - public void setCargoMax(double cargoMax) { - this.cargoMax = cargoMax; - } - - public TransportShip(int id, String name, double cargoMax) { - super(id, name); - this.cargoMax = cargoMax; - } - - public TransportShip() { - } - - @Override - public String toString() { - return getId() + ";" + getName() + ";" + cargoMax; - } - - public TransportShip(String s) { - super(s); - String[] tokens = s.split(";"); - cargoMax = Double.parseDouble(tokens[2].trim()); - } - -} -- GitLab