Commit ba46bb65 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Парсер и toString() для нового формата.

parent cace9b38
......@@ -4,12 +4,13 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
*/
public class LoadingEquipment extends MovingObject{
public LoadingEquipment() {
super();
......@@ -21,11 +22,19 @@ public class LoadingEquipment extends MovingObject{
@Override
public String toString() {
return getId() + ";" + getName();
String res = getId() + ";" + getName();
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
}
public LoadingEquipment(String s) {
super(s);
super(s);
String[] tokens = s.split(";");
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
}
}
......@@ -6,6 +6,7 @@ package inport;
import java.util.ArrayList;
import java.util.List;
import java.util.OptionalInt;
/**
*
......@@ -14,12 +15,21 @@ import java.util.List;
public class LoadingTemplate extends OperationTemplate {
private TransportShip loader;
private OptionalInt loaderType = OptionalInt.empty();
private Storage storage;
private List<LoadingEquipment> resources;
private List<Integer> resourcesTypes;
private double intensity;
private boolean withMooring;
private Cargo cargo;
public OptionalInt getLoaderType() {
return loaderType;
}
public void setLoaderType(OptionalInt loaderType) {
this.loaderType = loaderType;
}
/**
* Get the value of resources
*
......@@ -37,7 +47,14 @@ public class LoadingTemplate extends OperationTemplate {
public void setResources(List<LoadingEquipment> resources) {
this.resources = resources;
}
public List<Integer> getResourcesTypes() {
return resourcesTypes;
}
public void setResourcesTypes(List<Integer> resourcesTypes) {
this.resourcesTypes = resourcesTypes;
}
public TransportShip getLoader() {
return loader;
}
......@@ -83,32 +100,47 @@ public class LoadingTemplate extends OperationTemplate {
this.loader = loader;
this.storage = storage;
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
this.intensity = intensity;
}
public LoadingTemplate() {
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
}
@Override
public String toString() {
String res = "";
boolean first = true;
for(LoadingEquipment eq : resources)
{
for(LoadingEquipment eq : resources) {
if (!first)
res += "," + eq.getId();
else
res += eq.getId();
first = false;
}
int source = loader.getId();
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
int startId;
if (loaderType.isPresent()) {
startId = loaderType.getAsInt();
} else {
startId = loader.getId();
}
int source = startId;
if (intensity>0)
source = storage.getId();
int target = loader.getId();
int target = startId;
if (intensity<=0)
target = storage.getId();
return getId() + ";" + "loa;" + twtoString() + ";" + source + ";" + cargo.getId() + ";" + target + ";"
+ getStartLocation().getId() + ";[" + res +"];" + Math.abs(intensity) + ";" + (withMooring ? "M" : "U");
return getId() + "; " + "loa; " + twtoString() + "; " + source + "; " + cargo.getId() + "; " + target + "; "
+ getStartLocation().getId() + "; [" + res +"]; " + Math.abs(intensity) + "; " + (withMooring ? "M" : "U");
}
}
......@@ -118,6 +118,19 @@ public class Main {
}
break;
}
case "debug" : {
String fileName = args[1];
String output = args[2];
TaskCase task = new TaskCase();
try {
task.deserialize(fileName);
task.serialize(output);
} catch (IOException e) {
System.out.println(e.getMessage());
}
break;
}
default:
System.out.println("Unknown type \"" + type + "\"");
}
......
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -11,8 +13,16 @@ package inport;
public class MooringTemplate extends TowUsingTemplate {
private TransportShip moorer;
private OptionalInt moorerType = OptionalInt.empty();
private boolean direct;
public OptionalInt getMoorerType() {
return moorerType;
}
public void setMoorerType(OptionalInt moorerType) {
this.moorerType = moorerType;
}
/**
* Get the value of direction
*
......@@ -63,18 +73,31 @@ public class MooringTemplate extends TowUsingTemplate {
public String toString() {
String res = "";
boolean first = true;
for(Tow eq : getResources())
{
for(Tow eq : getResources()) {
if (!first)
res += "," + eq.getId();
else
res += eq.getId();
first = false;
}
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
String code = "mrn";
if (!direct)
code = "unm";
return getId() + ";" + code + ";" + twtoString() + ";" + moorer.getId() + ";" + getStartLocation().getId() + ";[" + res +"];"+getDuration();
String result = getId() + "; " + code + "; " + twtoString() + "; ";
if (moorerType.isPresent()) {
result += moorerType.getAsInt();
} else {
result += moorer.getId();
}
return result + "; " + getStartLocation().getId() + "; [" + res +"]; "+getDuration();
}
}
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -12,6 +14,7 @@ public class MovingObject {
private int id;
private String name;
private OptionalInt type;
/**
* Get the value of name
......@@ -49,18 +52,34 @@ public class MovingObject {
this.id = id;
}
public OptionalInt getType() {
return type;
}
public void setType(OptionalInt type) {
this.type = type;
}
public MovingObject(int id, String name) {
this.id = id;
this.name = name;
this.type = OptionalInt.empty();
}
public MovingObject(int id, String name, int typeId) {
this.id = id;
this.name = name;
this.type = OptionalInt.of(typeId);
}
public MovingObject() {
type = OptionalInt.empty();
}
public MovingObject(String s) {
String[] tokens = s.split(";");
id = Integer.parseInt(tokens[0].trim());
name = tokens[1].trim();
name = tokens[1].trim();
type = OptionalInt.empty();
}
}
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -11,6 +13,7 @@ package inport;
public class MovingTemplate extends TowUsingTemplate {
private MovingObject mover;
private OptionalInt moverType;
private Berth destination;
......@@ -50,6 +53,13 @@ public class MovingTemplate extends TowUsingTemplate {
this.mover = mover;
}
public OptionalInt getMoverType() {
return moverType;
}
public void setMoverType(OptionalInt moverType) {
this.moverType = moverType;
}
public MovingTemplate(MovingObject mover, Berth source, Berth destination, double duration, int id) {
super(duration, id, source);
this.mover = mover;
......@@ -64,15 +74,28 @@ public class MovingTemplate extends TowUsingTemplate {
public String toString() {
String res = "";
boolean first = true;
for(Tow eq : getResources())
{
for(Tow eq : getResources()) {
if (!first)
res += "," + eq.getId();
else
res += eq.getId();
first = false;
}
return getId() + ";" + "mov;" + twtoString() + ";" + mover.getId() + ";" + getStartLocation().getId() + ";" + destination.getId() + ";[" + res +"];"+getDuration();
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
String result = getId() + "; " + "mov; " + twtoString() + "; ";
if (getMoverType().isPresent()) {
result += getMoverType().getAsInt();
} else {
result += mover.getId();
}
return result + "; " + getStartLocation().getId() + "; " + destination.getId() + "; [" + res +"]; "+getDuration();
}
......
......@@ -11,11 +11,8 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.function.BiFunction;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -24,18 +21,26 @@ import java.util.logging.Logger;
* @author topazh_ag
*/
public class TaskCase {
// С типизацией ли
private boolean typified = false;
// Статическая структура порта
private List<Cargo> cargoes;
private List<Cargo> cargoes;
private List<Berth> berths;
private List<Storage> storages;
private List<Storage> storages;
private List<Bunker> bunkers;
private List<Tow> tows;
private List<LoadingEquipment> equipments;
// Обслуживаемые суда
private List<TransportShip> ships;
// Типы обслуживаемых судов
private Map<Integer, String> vesselTypes;
// Типы обслуживаемого оборудования.
private Map<Integer, String> equipmentTypes;
// Шаблоны операций
private List<OperationTemplate> templates;
......@@ -349,15 +354,40 @@ public class TaskCase {
this.berths = berths;
}
public void setVesselTypes(Map<Integer, String> vesselTypes) {
this.vesselTypes = vesselTypes;
}
public Map<Integer, String> getVesselTypes() {
return vesselTypes;
}
public void setEquipmentTypes(Map<Integer, String> equipmentTypes) {
this.equipmentTypes = equipmentTypes;
}
public Map<Integer, String> getEquipmentsTypes() {
return equipmentTypes;
}
public boolean isTypified() {
return typified;
}
public void setTypification(boolean typefied) {
this.typified = typefied;
}
public TaskCase() {
cargoes = new ArrayList<>();
berths = new ArrayList<>();
storages = new ArrayList<>();
bunkers = new ArrayList<>();
tows = new ArrayList<>();
equipments = new ArrayList<>();
ships = new ArrayList<>();
vesselTypes = new TreeMap<>();
equipmentTypes = new TreeMap<>();
templates = new ArrayList<>();
cargoFlows = new ArrayList<>();
......@@ -369,7 +399,6 @@ public class TaskCase {
storageEndState = new ArrayList<>();
solution = new ArrayList<>();
}
private MovingObjectState fromString(String s, Map<Integer, Berth> m_berth, Map<Integer, MovingObject> m_vessel)
......@@ -383,14 +412,49 @@ public class TaskCase {
st.setLocation(m_berth.get(key));
return st;
}
private enum Tag {
Undefined (""),
Typified ("Typified"),
Cargoes ("Cargoes"),
Berths ("Berths"),
Storages ("Storages"),
Loading_Equipment_Types("Loading Equipment Types"),
Vessel_Types ("Vessel Types"),
Bunkers ("Bunkers"),
Tows ("Tows"),
Loading_Equipments ("Loading Equipments"),
Transport_Ships ("Transport Ships"),
Templates ("Templates"),
Time_Windows ("Time Windows"),
Cargo_Flows ("Cargo Flows"),
Initial_Vessel_State ("Initial Vessel State"),
Initial_Storage_State ("Initial Storage State"),
Final_Vessel_State ("Final Vessel State"),
Final_Storage_State ("Final Storage State"),
Task_Properties ("Task Properties"),
Solution ("Solution");
private final String text;
Tag(String text) {
this.text = text;
}
public static Tag fromString(String text) {
for (Tag t : Tag.values()) {
if (t.text.equalsIgnoreCase(text)) {
return t;
}
}
return Undefined;
}
}
public void deserialize(String fileName) throws IOException
{
cargoes.clear(); berths.clear(); storages.clear(); bunkers.clear(); tows.clear(); equipments.clear(); ships.clear(); templates.clear();
cargoFlows.clear(); vesselInitialState.clear(); storageInitialState.clear(); vesselEndState.clear(); storageEndState.clear();
solution.clear();
String[] tags = {"Cargoes", "Berths", "Storages", "Bunkers", "Tows", "Loading Equipments", "Transport Ships", "Templates", "Time Windows", "Cargo Flows", "Initial Vessel State", "Initial Storage State", "Final Vessel State", "Final Storage State", "Task Properties", "Solution"};
// Open the file
FileInputStream fstream;
try
......@@ -398,64 +462,81 @@ public class TaskCase {
fstream = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
int index = 0;
Tag tag = Tag.Undefined;
Map<Integer, Cargo> m_cargo = new HashMap<>();
Map<Integer, Berth> m_berth = new HashMap<>();
Map<Integer, Storage> m_storage = new HashMap<>();
Map<Integer, MovingObject> m_vessel = new HashMap<>();
Map<Integer, LoadingEquipment> m_equiopment = new HashMap<>();
Map<Integer, LoadingEquipment> m_equipment = new HashMap<>();
Map<Integer, OperationTemplate> m_template = new HashMap<>();
//Read File Line By Line
int numInside = 0;
int numInside = 0;
while ((strLine = br.readLine()) != null)
{
numInside ++;
boolean serviceString = false;
for (int i = 0; i<tags.length; i++)
if (strLine.equals(tags[i]))
{
index = i+1;
serviceString = true;
break;
}
if (serviceString || strLine.length()<2 || index==0 || strLine.startsWith("/*"))
if (Tag.fromString(strLine) != Tag.Undefined) {
tag = Tag.fromString(strLine);
serviceString = true;
}
if (serviceString || strLine.trim().isEmpty() || tag==Tag.Undefined || strLine.startsWith("/*"))
{
numInside = 0;
continue;
}
switch (index) {
case 1: Cargo c = new Cargo(strLine); cargoes.add(c); m_cargo.put(c.getId(), c);
String[] tokens;
switch (tag) {
case Typified: typified = strLine.trim().equals("1");
break;
case Cargoes: Cargo c = new Cargo(strLine); cargoes.add(c); m_cargo.put(c.getId(), c);
break;
case Berths: Berth b = new Berth(strLine); berths.add(b); m_berth.put(b.getId(), b);
break;
case Storages: Storage s = new Storage(strLine, m_cargo); storages.add(s); m_storage.put(s.getId(), s);
break;
case 2: Berth b = new Berth(strLine); berths.add(b); m_berth.put(b.getId(), b);
case Vessel_Types:
tokens = strLine.split(";");
vesselTypes.put(Integer.parseInt(tokens[0].trim()), tokens[1].trim());
break;
case 3: Storage s = new Storage(strLine, m_cargo); storages.add(s); m_storage.put(s.getId(), s);
case Loading_Equipment_Types:
tokens = strLine.split(";");
equipmentTypes.put(Integer.parseInt(tokens[0].trim()), tokens[1].trim());
break;
case 4:
case Bunkers:
break;
case 5: Tow t = new Tow(strLine); tows.add(t); m_vessel.put(t.getId(), t);
case Tows: Tow t = new Tow(strLine); tows.add(t); m_vessel.put(t.getId(), t);
break;
case 6: LoadingEquipment l = new LoadingEquipment(strLine); equipments.add(l); m_equiopment.put(l.getId(), l); m_vessel.put(l.getId(), l);
break;
case 7: TransportShip ts = new TransportShip(strLine); ships.add(ts); m_vessel.put(ts.getId(), ts);
case Loading_Equipments: LoadingEquipment l = new LoadingEquipment(strLine); equipments.add(l); m_equipment.put(l.getId(), l); m_vessel.put(l.getId(), l);
break;
case 8: String[] tokens = strLine.split(";");
case Transport_Ships: TransportShip ts = new TransportShip(strLine); ships.add(ts); m_vessel.put(ts.getId(), ts);
break;
case Templates: tokens = strLine.split(";");
if (tokens[1].trim().equals("mov"))
{
MovingTemplate mt = new MovingTemplate();
mt.setId(Integer.parseInt(tokens[0].trim()));
mt.setTimeWindow(tokens[2].trim());
int key = Integer.parseInt(tokens[3].trim());
mt.setMover(m_vessel.get(key));
if (isTypified()) {
mt.setMoverType(OptionalInt.of(key));
} else {
mt.setMover(m_vessel.get(key));
}
key = Integer.parseInt(tokens[4].trim());
mt.setStartLocation(m_berth.get(key));
key = Integer.parseInt(tokens[5].trim());
mt.setDestination(m_berth.get(key));
String[] rs = tokens[6].trim().replace("[", "").replace("]", "").split(",");
for (String crs : rs)
if (crs.length()>0)
{
if (crs.length()>0) {
key = Integer.parseInt(crs.trim());
mt.getResources().add((Tow)m_vessel.get(key));
if (isTypified()) {
mt.getResourcesTypes().add(key);
} else {
mt.getResources().add((Tow) m_vessel.get(key));
}
}
mt.setDuration(Double.parseDouble(tokens[7].trim()));
templates.add(mt);
......@@ -470,19 +551,26 @@ public class TaskCase {
mt.setDirect(false);
mt.setTimeWindow(tokens[2].trim());
int key = Integer.parseInt(tokens[3].trim());
mt.setMoorer((TransportShip)m_vessel.get(key));
if (isTypified()) {
mt.setMoorerType(OptionalInt.of(key));
} else {
mt.setMoorer((TransportShip) m_vessel.get(key));
}
key = Integer.parseInt(tokens[4].trim());
mt.setStartLocation(m_berth.get(key));
String[] rs = tokens[5].trim().replace("[", "").replace("]", "").split(",");
for (String crs : rs)
if (crs.length()>0)
{
if (crs.length()>0) {
key = Integer.parseInt(crs.trim());
mt.getResources().add((Tow)m_vessel.get(key));
if (isTypified()) {
mt.getResourcesTypes().add(key);
} else {
mt.getResources().add((Tow) m_vessel.get(key));
}
}
mt.setDuration(Double.parseDouble(tokens[6].trim()));
templates.add(mt);
m_template.put(mt.getId(), mt);
mt.setDuration(Double.parseDouble(tokens[6].trim()));
templates.add(mt);
m_template.put(mt.getId(), mt);
}
if (tokens[1].trim().equals("loa"))
{
......@@ -490,18 +578,27 @@ public class TaskCase {
mt.setId(Integer.parseInt(tokens[0].trim()));
mt.setTimeWindow(tokens[2].trim());
int direct = 1;
BiFunction<Integer, Integer, Integer> addLoaderOrStorage = (Integer key, Integer loaderDirection) -> {
int dir = 1;
if (vesselTypes.containsKey(key)) {
mt.setLoaderType(OptionalInt.of(key));
dir = loaderDirection;
} else
if (m_vessel.containsKey(key)) {
mt.setLoader((TransportShip)m_vessel.get(key));
dir = loaderDirection;
}
if (m_storage.containsKey(key)) {
mt.setStorage((Storage)m_storage.get(key));
dir = -loaderDirection;
}
return dir;
};
// Источник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом
int key = Integer.parseInt(tokens[3].trim());
if (m_vessel.containsKey(key))
{
mt.setLoader((TransportShip)m_vessel.get(key));
direct = -1;
}
if (m_storage.containsKey(key))
{
mt.setStorage((Storage)m_storage.get(key));
direct = 1;
}
int key = Integer.parseInt(tokens[3].trim());
direct = addLoaderOrStorage.apply(key, -1);
// Груз.
key = Integer.parseInt(tokens[4].trim());;
for (Cargo cargo : cargoes) {
......@@ -511,24 +608,18 @@ public class TaskCase {
}
// Приемник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом
key = Integer.parseInt(tokens[5].trim());
if (m_vessel.containsKey(key))
{
mt.setLoader((TransportShip)m_vessel.get(key));
direct = 1;
}
if (m_storage.containsKey(key))
{
mt.setStorage((Storage)m_storage.get(key));
direct = - 1;
}
direct = addLoaderOrStorage.apply(key, 1);
key = Integer.parseInt(tokens[6].trim());
mt.setStartLocation(m_berth.get(key));
String[] rs = tokens[7].trim().replace("[", "").replace("]", "").split(",");
for (String crs : rs)
if (crs.length()>0)
{
if (crs.length()>0) {
key = Integer.parseInt(crs.trim());
mt.getResources().add(m_equiopment.get(key));
if (isTypified()) {
mt.getResourcesTypes().add(key);
} else {
mt.getResources().add(m_equipment.get(key));
}
}
mt.setIntensity(direct*Double.parseDouble(tokens[8].trim()));
mt.setWithMooring(tokens[9].trim().equals("M"));
......@@ -537,26 +628,26 @@ public class TaskCase {
m_template.put(mt.getId(), mt);
}
break;
case 9:
case Time_Windows:
break;
case 10: cargoFlows.add(new CargoFlow(strLine, m_storage, m_cargo));
case Cargo_Flows: cargoFlows.add(new CargoFlow(strLine, m_storage, m_cargo));
break;
case 11: vesselInitialState.add(fromString(strLine, m_berth, m_vessel));
case Initial_Vessel_State: vesselInitialState.add(fromString(strLine, m_berth, m_vessel));
break;
case 12: storageInitialState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo));
case Initial_Storage_State: storageInitialState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo));
break;
case 13: vesselEndState.add(fromString(strLine, m_berth, m_vessel));
case Final_Vessel_State: vesselEndState.add(fromString(strLine, m_berth, m_vessel));
break;
case 14: storageEndState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo));
case Final_Storage_State: storageEndState.add(new StorageState(strLine, m_storage, m_vessel, m_cargo));
break;
case 15:
case Task_Properties:
{
String[] rs = strLine.split(";");
planningInterval = Double.parseDouble(rs[0].trim());
criterionType = Integer.parseInt(rs[1].trim());
}
break;
case 16: // Тут чтение операций если надо. Потом подумаем
case Solution: // Тут чтение операций если надо. Потом подумаем
break;
default:
break;
......@@ -573,62 +664,77 @@ public class TaskCase {
{
try(FileWriter writer = new FileWriter(fileName, false))
{
// запись всего
writer.write("Cargoes"+"\n");
for (Cargo c : cargoes)
writer.write(c.toString()+"\n");
writer.write("Berths"+"\n");
for (Berth c : berths)
writer.write(c.toString()+"\n");
writer.write("Storages"+"\n");
for (Storage c : storages)
writer.write(c.toString()+"\n");
writer.write("Bunkers"+"\n");
for (Bunker c : bunkers)
writer.write(c.toString()+"\n");
writer.write("Tows"+"\n");
for (Tow c : tows)
writer.write(c.toString()+"\n");
writer.write("Loading Equipments"+"\n");
for (LoadingEquipment c : equipments)
writer.write(c.toString()+"\n");
writer.write("Transport Ships"+"\n");
for (TransportShip c : ships)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Templates"+"\n");
for (OperationTemplate c : templates)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Cargo Flows"+"\n");
for (CargoFlow c : cargoFlows)
writer.write(c.toString()+"\n");
writer.write("Initial Vessel State"+"\n");
for (MovingObjectState c : vesselInitialState)
writer.write(c.toString()+"\n");
writer.write("Initial Storage State"+"\n");
for (StorageState c : storageInitialState)
writer.write(c.toString()+"\n");
writer.write("Final Vessel State"+"\n");
for (MovingObjectState c : vesselEndState)
writer.write(c.toString()+"\n");
writer.write("Final Storage State"+"\n");
for (StorageState c : storageEndState)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Task Properties"+"\n");
writer.write(planningInterval+";"+criterionType+"\n");
writer.write("\n");
writer.write("Solution"+"\n");
writer.write(solution_result+"\n");
for (Operation c : solution)
writer.write(c.toString()+"\n");
writer.flush();
// запись всего
writer.write(Tag.Typified.text + "\n" + (isTypified()? "1" : "0") + "\n");
writer.write("Cargoes"+"\n");
for (Cargo c : cargoes)
writer.write(c.toString()+"\n");
writer.write("Berths"+"\n");
for (Berth c : berths)
writer.write(c.toString()+"\n");
writer.write("Storages"+"\n");
for (Storage c : storages) {
writer.write(c.toString() + "\n");
}
if (isTypified()) {
writer.write(Tag.Vessel_Types.text + "\n");
for (Map.Entry<Integer, String> e : vesselTypes.entrySet()) {
writer.write(e.getKey() + "; " + e.getValue() + "\n");
}
}
writer.write("Bunkers"+"\n");
for (Bunker c : bunkers)
writer.write(c.toString()+"\n");
writer.write("Tows"+"\n");
for (Tow c : tows) {
writer.write(c.toString() + "\n");
}
if (isTypified()) {
writer.write(Tag.Loading_Equipment_Types.text + "\n");
for (Map.Entry<Integer, String> e : equipmentTypes.entrySet()) {
writer.write(e.getKey() + "; " + e.getValue() + "\n");
}
}
writer.write("Loading Equipments"+"\n");
for (LoadingEquipment c : equipments)
writer.write(c.toString()+"\n");
writer.write("Transport Ships"+"\n");
for (TransportShip c : ships)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Templates"+"\n");
for (OperationTemplate c : templates)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Cargo Flows"+"\n");
for (CargoFlow c : cargoFlows)
writer.write(c.toString()+"\n");
writer.write("Initial Vessel State"+"\n");
for (MovingObjectState c : vesselInitialState)
writer.write(c.toString()+"\n");
writer.write("Initial Storage State"+"\n");
for (StorageState c : storageInitialState)
writer.write(c.toString()+"\n");
writer.write("Final Vessel State"+"\n");
for (MovingObjectState c : vesselEndState)
writer.write(c.toString()+"\n");
writer.write("Final Storage State"+"\n");
for (StorageState c : storageEndState)
writer.write(c.toString()+"\n");
writer.write("\n");
writer.write("Task Properties"+"\n");
writer.write(planningInterval+";"+criterionType+"\n");
writer.write("\n");
writer.write("Solution"+"\n");
writer.write(solution_result+"\n");
for (Operation c : solution)
writer.write(c.toString()+"\n");
writer.flush();
}
catch(IOException ex){
catch(IOException ex) {
System.out.println(ex.getMessage());
}
}
}
public void formSolutionFromPB(int res[])
......
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -19,12 +21,18 @@ public class Tow extends MovingObject {
@Override
public String toString() {
return getId() + ";" + getName() + ";1000000";
String res = getId() + ";" + getName() + ";1000000";
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
}
public Tow(String s) {
super(s);
String[] tokens = s.split(";");
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
}
}
......@@ -12,11 +12,10 @@ import java.util.List;
* @author topazh_ag
*/
public abstract class TowUsingTemplate extends OperationTemplate {
private List<Tow> resources;
private List<Integer> resourcesTypes;
private double duration;
/**
* Get the value of resources
......@@ -36,6 +35,13 @@ public abstract class TowUsingTemplate extends OperationTemplate {
this.resources = resources;
}
public List<Integer> getResourcesTypes() {
return resourcesTypes;
}
public void setResourcesTypes(List<Integer> resourcesTypes) {
this.resourcesTypes = resourcesTypes;
}
/**
* Get the value of duration
*
......@@ -59,11 +65,13 @@ public abstract class TowUsingTemplate extends OperationTemplate {
public TowUsingTemplate(double duration, int id, Berth startLocation) {
super(id, startLocation);
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
this.duration = duration;
}
public TowUsingTemplate() {
this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
}
@Override
......@@ -80,6 +88,4 @@ public abstract class TowUsingTemplate extends OperationTemplate {
}
return getId() + ";" + "tut" + ";" + ";[" + res +"];"+duration;
}
}
......@@ -4,6 +4,8 @@
*/
package inport;
import java.util.OptionalInt;
/**
*
* @author topazh_ag
......@@ -30,13 +32,20 @@ public class TransportShip extends MovingObject {
@Override
public String toString() {
return getId() + ";" + getName() + ";" + cargoMax;
String res = getId() + ";" + getName() + ";" + cargoMax;
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
}
public TransportShip(String s) {
super(s);
String[] tokens = s.split(";");
cargoMax = Double.parseDouble(tokens[2].trim());
cargoMax = Double.parseDouble(tokens[2].trim());
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment