Commit ba46bb65 authored by Vladislav Kiselev's avatar Vladislav Kiselev

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

parent cace9b38
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
*/ */
package inport; package inport;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
*/ */
public class LoadingEquipment extends MovingObject{ public class LoadingEquipment extends MovingObject{
public LoadingEquipment() { public LoadingEquipment() {
super(); super();
} }
...@@ -21,11 +22,19 @@ public class LoadingEquipment extends MovingObject{ ...@@ -21,11 +22,19 @@ public class LoadingEquipment extends MovingObject{
@Override @Override
public String toString() { public String toString() {
return getId() + ";" + getName(); String res = getId() + ";" + getName();
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
} }
public LoadingEquipment(String s) { 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; ...@@ -6,6 +6,7 @@ package inport;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.OptionalInt;
/** /**
* *
...@@ -14,12 +15,21 @@ import java.util.List; ...@@ -14,12 +15,21 @@ import java.util.List;
public class LoadingTemplate extends OperationTemplate { public class LoadingTemplate extends OperationTemplate {
private TransportShip loader; private TransportShip loader;
private OptionalInt loaderType = OptionalInt.empty();
private Storage storage; private Storage storage;
private List<LoadingEquipment> resources; private List<LoadingEquipment> resources;
private List<Integer> resourcesTypes;
private double intensity; private double intensity;
private boolean withMooring; private boolean withMooring;
private Cargo cargo; private Cargo cargo;
public OptionalInt getLoaderType() {
return loaderType;
}
public void setLoaderType(OptionalInt loaderType) {
this.loaderType = loaderType;
}
/** /**
* Get the value of resources * Get the value of resources
* *
...@@ -38,6 +48,13 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -38,6 +48,13 @@ public class LoadingTemplate extends OperationTemplate {
this.resources = resources; this.resources = resources;
} }
public List<Integer> getResourcesTypes() {
return resourcesTypes;
}
public void setResourcesTypes(List<Integer> resourcesTypes) {
this.resourcesTypes = resourcesTypes;
}
public TransportShip getLoader() { public TransportShip getLoader() {
return loader; return loader;
} }
...@@ -83,32 +100,47 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -83,32 +100,47 @@ public class LoadingTemplate extends OperationTemplate {
this.loader = loader; this.loader = loader;
this.storage = storage; this.storage = storage;
this.resources = new ArrayList<>(); this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
this.intensity = intensity; this.intensity = intensity;
} }
public LoadingTemplate() { public LoadingTemplate() {
this.resources = new ArrayList<>(); this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
} }
@Override @Override
public String toString() { public String toString() {
String res = ""; String res = "";
boolean first = true; boolean first = true;
for(LoadingEquipment eq : resources) for(LoadingEquipment eq : resources) {
{
if (!first) if (!first)
res += "," + eq.getId(); res += "," + eq.getId();
else else
res += eq.getId(); res += eq.getId();
first = false; 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) if (intensity>0)
source = storage.getId(); source = storage.getId();
int target = loader.getId(); int target = startId;
if (intensity<=0) if (intensity<=0)
target = storage.getId(); target = storage.getId();
return getId() + ";" + "loa;" + twtoString() + ";" + source + ";" + cargo.getId() + ";" + target + ";" return getId() + "; " + "loa; " + twtoString() + "; " + source + "; " + cargo.getId() + "; " + target + "; "
+ getStartLocation().getId() + ";[" + res +"];" + Math.abs(intensity) + ";" + (withMooring ? "M" : "U"); + getStartLocation().getId() + "; [" + res +"]; " + Math.abs(intensity) + "; " + (withMooring ? "M" : "U");
} }
} }
...@@ -118,6 +118,19 @@ public class Main { ...@@ -118,6 +118,19 @@ public class Main {
} }
break; 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: default:
System.out.println("Unknown type \"" + type + "\""); System.out.println("Unknown type \"" + type + "\"");
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
*/ */
package inport; package inport;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
...@@ -11,8 +13,16 @@ package inport; ...@@ -11,8 +13,16 @@ package inport;
public class MooringTemplate extends TowUsingTemplate { public class MooringTemplate extends TowUsingTemplate {
private TransportShip moorer; private TransportShip moorer;
private OptionalInt moorerType = OptionalInt.empty();
private boolean direct; private boolean direct;
public OptionalInt getMoorerType() {
return moorerType;
}
public void setMoorerType(OptionalInt moorerType) {
this.moorerType = moorerType;
}
/** /**
* Get the value of direction * Get the value of direction
* *
...@@ -63,18 +73,31 @@ public class MooringTemplate extends TowUsingTemplate { ...@@ -63,18 +73,31 @@ public class MooringTemplate extends TowUsingTemplate {
public String toString() { public String toString() {
String res = ""; String res = "";
boolean first = true; boolean first = true;
for(Tow eq : getResources()) for(Tow eq : getResources()) {
{
if (!first) if (!first)
res += "," + eq.getId(); res += "," + eq.getId();
else else
res += eq.getId(); res += eq.getId();
first = false; first = false;
} }
for (Integer t : getResourcesTypes()) {
if (!first)
res += "," + t;
else
res += t;
first = false;
}
String code = "mrn"; String code = "mrn";
if (!direct) if (!direct)
code = "unm"; 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 @@ ...@@ -4,6 +4,8 @@
*/ */
package inport; package inport;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
...@@ -12,6 +14,7 @@ public class MovingObject { ...@@ -12,6 +14,7 @@ public class MovingObject {
private int id; private int id;
private String name; private String name;
private OptionalInt type;
/** /**
* Get the value of name * Get the value of name
...@@ -49,18 +52,34 @@ public class MovingObject { ...@@ -49,18 +52,34 @@ public class MovingObject {
this.id = id; this.id = id;
} }
public OptionalInt getType() {
return type;
}
public void setType(OptionalInt type) {
this.type = type;
}
public MovingObject(int id, String name) { public MovingObject(int id, String name) {
this.id = id; this.id = id;
this.name = name; 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() { public MovingObject() {
type = OptionalInt.empty();
} }
public MovingObject(String s) { public MovingObject(String s) {
String[] tokens = s.split(";"); String[] tokens = s.split(";");
id = Integer.parseInt(tokens[0].trim()); id = Integer.parseInt(tokens[0].trim());
name = tokens[1].trim(); name = tokens[1].trim();
type = OptionalInt.empty();
} }
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
*/ */
package inport; package inport;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
...@@ -11,6 +13,7 @@ package inport; ...@@ -11,6 +13,7 @@ package inport;
public class MovingTemplate extends TowUsingTemplate { public class MovingTemplate extends TowUsingTemplate {
private MovingObject mover; private MovingObject mover;
private OptionalInt moverType;
private Berth destination; private Berth destination;
...@@ -50,6 +53,13 @@ public class MovingTemplate extends TowUsingTemplate { ...@@ -50,6 +53,13 @@ public class MovingTemplate extends TowUsingTemplate {
this.mover = mover; 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) { public MovingTemplate(MovingObject mover, Berth source, Berth destination, double duration, int id) {
super(duration, id, source); super(duration, id, source);
this.mover = mover; this.mover = mover;
...@@ -64,15 +74,28 @@ public class MovingTemplate extends TowUsingTemplate { ...@@ -64,15 +74,28 @@ public class MovingTemplate extends TowUsingTemplate {
public String toString() { public String toString() {
String res = ""; String res = "";
boolean first = true; boolean first = true;
for(Tow eq : getResources()) for(Tow eq : getResources()) {
{
if (!first) if (!first)
res += "," + eq.getId(); res += "," + eq.getId();
else else
res += eq.getId(); res += eq.getId();
first = false; 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; ...@@ -11,11 +11,8 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap; import java.util.function.BiFunction;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -24,6 +21,8 @@ import java.util.logging.Logger; ...@@ -24,6 +21,8 @@ import java.util.logging.Logger;
* @author topazh_ag * @author topazh_ag
*/ */
public class TaskCase { public class TaskCase {
// С типизацией ли
private boolean typified = false;
// Статическая структура порта // Статическая структура порта
private List<Cargo> cargoes; private List<Cargo> cargoes;
...@@ -36,6 +35,12 @@ public class TaskCase { ...@@ -36,6 +35,12 @@ public class TaskCase {
// Обслуживаемые суда // Обслуживаемые суда
private List<TransportShip> ships; private List<TransportShip> ships;
// Типы обслуживаемых судов
private Map<Integer, String> vesselTypes;
// Типы обслуживаемого оборудования.
private Map<Integer, String> equipmentTypes;
// Шаблоны операций // Шаблоны операций
private List<OperationTemplate> templates; private List<OperationTemplate> templates;
...@@ -349,15 +354,40 @@ public class TaskCase { ...@@ -349,15 +354,40 @@ public class TaskCase {
this.berths = berths; 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() { public TaskCase() {
cargoes = new ArrayList<>(); cargoes = new ArrayList<>();
berths = new ArrayList<>(); berths = new ArrayList<>();
storages = new ArrayList<>(); storages = new ArrayList<>();
bunkers = new ArrayList<>(); bunkers = new ArrayList<>();
tows = new ArrayList<>(); tows = new ArrayList<>();
equipments = new ArrayList<>(); equipments = new ArrayList<>();
ships = new ArrayList<>(); ships = new ArrayList<>();
vesselTypes = new TreeMap<>();
equipmentTypes = new TreeMap<>();
templates = new ArrayList<>(); templates = new ArrayList<>();
cargoFlows = new ArrayList<>(); cargoFlows = new ArrayList<>();
...@@ -369,7 +399,6 @@ public class TaskCase { ...@@ -369,7 +399,6 @@ public class TaskCase {
storageEndState = new ArrayList<>(); storageEndState = new ArrayList<>();
solution = new ArrayList<>(); solution = new ArrayList<>();
} }
private MovingObjectState fromString(String s, Map<Integer, Berth> m_berth, Map<Integer, MovingObject> m_vessel) private MovingObjectState fromString(String s, Map<Integer, Berth> m_berth, Map<Integer, MovingObject> m_vessel)
...@@ -384,13 +413,48 @@ public class TaskCase { ...@@ -384,13 +413,48 @@ public class TaskCase {
return st; 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 public void deserialize(String fileName) throws IOException
{ {
cargoes.clear(); berths.clear(); storages.clear(); bunkers.clear(); tows.clear(); equipments.clear(); ships.clear(); templates.clear(); 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(); cargoFlows.clear(); vesselInitialState.clear(); storageInitialState.clear(); vesselEndState.clear(); storageEndState.clear();
solution.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 // Open the file
FileInputStream fstream; FileInputStream fstream;
try try
...@@ -398,12 +462,12 @@ public class TaskCase { ...@@ -398,12 +462,12 @@ public class TaskCase {
fstream = new FileInputStream(fileName); fstream = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine; String strLine;
int index = 0; Tag tag = Tag.Undefined;
Map<Integer, Cargo> m_cargo = new HashMap<>(); Map<Integer, Cargo> m_cargo = new HashMap<>();
Map<Integer, Berth> m_berth = new HashMap<>(); Map<Integer, Berth> m_berth = new HashMap<>();
Map<Integer, Storage> m_storage = new HashMap<>(); Map<Integer, Storage> m_storage = new HashMap<>();
Map<Integer, MovingObject> m_vessel = 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<>(); Map<Integer, OperationTemplate> m_template = new HashMap<>();
//Read File Line By Line //Read File Line By Line
int numInside = 0; int numInside = 0;
...@@ -411,51 +475,68 @@ public class TaskCase { ...@@ -411,51 +475,68 @@ public class TaskCase {
{ {
numInside ++; numInside ++;
boolean serviceString = false; boolean serviceString = false;
for (int i = 0; i<tags.length; i++) if (Tag.fromString(strLine) != Tag.Undefined) {
if (strLine.equals(tags[i])) tag = Tag.fromString(strLine);
{
index = i+1;
serviceString = true; serviceString = true;
break;
} }
if (serviceString || strLine.length()<2 || index==0 || strLine.startsWith("/*"))
if (serviceString || strLine.trim().isEmpty() || tag==Tag.Undefined || strLine.startsWith("/*"))
{ {
numInside = 0; numInside = 0;
continue; continue;
} }
switch (index) { String[] tokens;
case 1: Cargo c = new Cargo(strLine); cargoes.add(c); m_cargo.put(c.getId(), c);
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; 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; 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; break;
case 4: case Bunkers:
break; 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; break;
case 6: LoadingEquipment l = new LoadingEquipment(strLine); equipments.add(l); m_equiopment.put(l.getId(), l); m_vessel.put(l.getId(), l); case Loading_Equipments: LoadingEquipment l = new LoadingEquipment(strLine); equipments.add(l); m_equipment.put(l.getId(), l); m_vessel.put(l.getId(), l);
break; break;
case 7: TransportShip ts = new TransportShip(strLine); ships.add(ts); m_vessel.put(ts.getId(), ts); case Transport_Ships: TransportShip ts = new TransportShip(strLine); ships.add(ts); m_vessel.put(ts.getId(), ts);
break; break;
case 8: String[] tokens = strLine.split(";"); case Templates: tokens = strLine.split(";");
if (tokens[1].trim().equals("mov")) if (tokens[1].trim().equals("mov"))
{ {
MovingTemplate mt = new MovingTemplate(); MovingTemplate mt = new MovingTemplate();
mt.setId(Integer.parseInt(tokens[0].trim())); mt.setId(Integer.parseInt(tokens[0].trim()));
mt.setTimeWindow(tokens[2].trim()); mt.setTimeWindow(tokens[2].trim());
int key = Integer.parseInt(tokens[3].trim()); int key = Integer.parseInt(tokens[3].trim());
if (isTypified()) {
mt.setMoverType(OptionalInt.of(key));
} else {
mt.setMover(m_vessel.get(key)); mt.setMover(m_vessel.get(key));
}
key = Integer.parseInt(tokens[4].trim()); key = Integer.parseInt(tokens[4].trim());
mt.setStartLocation(m_berth.get(key)); mt.setStartLocation(m_berth.get(key));
key = Integer.parseInt(tokens[5].trim()); key = Integer.parseInt(tokens[5].trim());
mt.setDestination(m_berth.get(key)); mt.setDestination(m_berth.get(key));
String[] rs = tokens[6].trim().replace("[", "").replace("]", "").split(","); String[] rs = tokens[6].trim().replace("[", "").replace("]", "").split(",");
for (String crs : rs) for (String crs : rs)
if (crs.length()>0) if (crs.length()>0) {
{
key = Integer.parseInt(crs.trim()); 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())); mt.setDuration(Double.parseDouble(tokens[7].trim()));
templates.add(mt); templates.add(mt);
...@@ -470,15 +551,22 @@ public class TaskCase { ...@@ -470,15 +551,22 @@ public class TaskCase {
mt.setDirect(false); mt.setDirect(false);
mt.setTimeWindow(tokens[2].trim()); mt.setTimeWindow(tokens[2].trim());
int key = Integer.parseInt(tokens[3].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()); key = Integer.parseInt(tokens[4].trim());
mt.setStartLocation(m_berth.get(key)); mt.setStartLocation(m_berth.get(key));
String[] rs = tokens[5].trim().replace("[", "").replace("]", "").split(","); String[] rs = tokens[5].trim().replace("[", "").replace("]", "").split(",");
for (String crs : rs) for (String crs : rs)
if (crs.length()>0) if (crs.length()>0) {
{
key = Integer.parseInt(crs.trim()); 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())); mt.setDuration(Double.parseDouble(tokens[6].trim()));
templates.add(mt); templates.add(mt);
...@@ -490,18 +578,27 @@ public class TaskCase { ...@@ -490,18 +578,27 @@ public class TaskCase {
mt.setId(Integer.parseInt(tokens[0].trim())); mt.setId(Integer.parseInt(tokens[0].trim()));
mt.setTimeWindow(tokens[2].trim()); mt.setTimeWindow(tokens[2].trim());
int direct = 1; int direct = 1;
// Источник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом
int key = Integer.parseInt(tokens[3].trim()); BiFunction<Integer, Integer, Integer> addLoaderOrStorage = (Integer key, Integer loaderDirection) -> {
if (m_vessel.containsKey(key)) 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)); mt.setLoader((TransportShip)m_vessel.get(key));
direct = -1; dir = loaderDirection;
} }
if (m_storage.containsKey(key)) if (m_storage.containsKey(key)) {
{
mt.setStorage((Storage)m_storage.get(key)); mt.setStorage((Storage)m_storage.get(key));
direct = 1; dir = -loaderDirection;
} }
return dir;
};
// Источник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом
int key = Integer.parseInt(tokens[3].trim());
direct = addLoaderOrStorage.apply(key, -1);
// Груз. // Груз.
key = Integer.parseInt(tokens[4].trim());; key = Integer.parseInt(tokens[4].trim());;
for (Cargo cargo : cargoes) { for (Cargo cargo : cargoes) {
...@@ -511,24 +608,18 @@ public class TaskCase { ...@@ -511,24 +608,18 @@ public class TaskCase {
} }
// Приемник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом // Приемник. Пока пара - это только хранилище-судно. С бункеровкой будем разбираться потом
key = Integer.parseInt(tokens[5].trim()); key = Integer.parseInt(tokens[5].trim());
if (m_vessel.containsKey(key)) direct = addLoaderOrStorage.apply(key, 1);
{
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()); key = Integer.parseInt(tokens[6].trim());
mt.setStartLocation(m_berth.get(key)); mt.setStartLocation(m_berth.get(key));
String[] rs = tokens[7].trim().replace("[", "").replace("]", "").split(","); String[] rs = tokens[7].trim().replace("[", "").replace("]", "").split(",");
for (String crs : rs) for (String crs : rs)
if (crs.length()>0) if (crs.length()>0) {
{
key = Integer.parseInt(crs.trim()); 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.setIntensity(direct*Double.parseDouble(tokens[8].trim()));
mt.setWithMooring(tokens[9].trim().equals("M")); mt.setWithMooring(tokens[9].trim().equals("M"));
...@@ -537,26 +628,26 @@ public class TaskCase { ...@@ -537,26 +628,26 @@ public class TaskCase {
m_template.put(mt.getId(), mt); m_template.put(mt.getId(), mt);
} }
break; break;
case 9: case Time_Windows:
break; 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; break;
case 11: vesselInitialState.add(fromString(strLine, m_berth, m_vessel)); case Initial_Vessel_State: vesselInitialState.add(fromString(strLine, m_berth, m_vessel));
break; 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; break;
case 13: vesselEndState.add(fromString(strLine, m_berth, m_vessel)); case Final_Vessel_State: vesselEndState.add(fromString(strLine, m_berth, m_vessel));
break; 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; break;
case 15: case Task_Properties:
{ {
String[] rs = strLine.split(";"); String[] rs = strLine.split(";");
planningInterval = Double.parseDouble(rs[0].trim()); planningInterval = Double.parseDouble(rs[0].trim());
criterionType = Integer.parseInt(rs[1].trim()); criterionType = Integer.parseInt(rs[1].trim());
} }
break; break;
case 16: // Тут чтение операций если надо. Потом подумаем case Solution: // Тут чтение операций если надо. Потом подумаем
break; break;
default: default:
break; break;
...@@ -574,6 +665,8 @@ public class TaskCase { ...@@ -574,6 +665,8 @@ public class TaskCase {
try(FileWriter writer = new FileWriter(fileName, false)) try(FileWriter writer = new FileWriter(fileName, false))
{ {
// запись всего // запись всего
writer.write(Tag.Typified.text + "\n" + (isTypified()? "1" : "0") + "\n");
writer.write("Cargoes"+"\n"); writer.write("Cargoes"+"\n");
for (Cargo c : cargoes) for (Cargo c : cargoes)
writer.write(c.toString()+"\n"); writer.write(c.toString()+"\n");
...@@ -581,14 +674,28 @@ public class TaskCase { ...@@ -581,14 +674,28 @@ public class TaskCase {
for (Berth c : berths) for (Berth c : berths)
writer.write(c.toString()+"\n"); writer.write(c.toString()+"\n");
writer.write("Storages"+"\n"); writer.write("Storages"+"\n");
for (Storage c : storages) for (Storage c : storages) {
writer.write(c.toString()+"\n"); 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"); writer.write("Bunkers"+"\n");
for (Bunker c : bunkers) for (Bunker c : bunkers)
writer.write(c.toString()+"\n"); writer.write(c.toString()+"\n");
writer.write("Tows"+"\n"); writer.write("Tows"+"\n");
for (Tow c : tows) for (Tow c : tows) {
writer.write(c.toString()+"\n"); 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"); writer.write("Loading Equipments"+"\n");
for (LoadingEquipment c : equipments) for (LoadingEquipment c : equipments)
writer.write(c.toString()+"\n"); writer.write(c.toString()+"\n");
...@@ -625,8 +732,7 @@ public class TaskCase { ...@@ -625,8 +732,7 @@ public class TaskCase {
writer.write(c.toString()+"\n"); writer.write(c.toString()+"\n");
writer.flush(); writer.flush();
} }
catch(IOException ex){ catch(IOException ex) {
System.out.println(ex.getMessage()); System.out.println(ex.getMessage());
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
*/ */
package inport; package inport;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
...@@ -19,12 +21,18 @@ public class Tow extends MovingObject { ...@@ -19,12 +21,18 @@ public class Tow extends MovingObject {
@Override @Override
public String toString() { public String toString() {
return getId() + ";" + getName() + ";1000000"; String res = getId() + ";" + getName() + ";1000000";
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
} }
public Tow(String s) { public Tow(String s) {
super(s); super(s);
String[] tokens = s.split(";");
if (tokens.length >= 4) {
setType(OptionalInt.of(Integer.parseInt(tokens[3].trim())));
}
} }
} }
...@@ -13,11 +13,10 @@ import java.util.List; ...@@ -13,11 +13,10 @@ import java.util.List;
*/ */
public abstract class TowUsingTemplate extends OperationTemplate { public abstract class TowUsingTemplate extends OperationTemplate {
private List<Tow> resources; private List<Tow> resources;
private List<Integer> resourcesTypes;
private double duration; private double duration;
/** /**
* Get the value of resources * Get the value of resources
* *
...@@ -36,6 +35,13 @@ public abstract class TowUsingTemplate extends OperationTemplate { ...@@ -36,6 +35,13 @@ public abstract class TowUsingTemplate extends OperationTemplate {
this.resources = resources; this.resources = resources;
} }
public List<Integer> getResourcesTypes() {
return resourcesTypes;
}
public void setResourcesTypes(List<Integer> resourcesTypes) {
this.resourcesTypes = resourcesTypes;
}
/** /**
* Get the value of duration * Get the value of duration
* *
...@@ -59,11 +65,13 @@ public abstract class TowUsingTemplate extends OperationTemplate { ...@@ -59,11 +65,13 @@ public abstract class TowUsingTemplate extends OperationTemplate {
public TowUsingTemplate(double duration, int id, Berth startLocation) { public TowUsingTemplate(double duration, int id, Berth startLocation) {
super(id, startLocation); super(id, startLocation);
this.resources = new ArrayList<>(); this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
this.duration = duration; this.duration = duration;
} }
public TowUsingTemplate() { public TowUsingTemplate() {
this.resources = new ArrayList<>(); this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>();
} }
@Override @Override
...@@ -80,6 +88,4 @@ public abstract class TowUsingTemplate extends OperationTemplate { ...@@ -80,6 +88,4 @@ public abstract class TowUsingTemplate extends OperationTemplate {
} }
return getId() + ";" + "tut" + ";" + ";[" + res +"];"+duration; return getId() + ";" + "tut" + ";" + ";[" + res +"];"+duration;
} }
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
*/ */
package inport; package inport;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
...@@ -30,13 +32,20 @@ public class TransportShip extends MovingObject { ...@@ -30,13 +32,20 @@ public class TransportShip extends MovingObject {
@Override @Override
public String toString() { public String toString() {
return getId() + ";" + getName() + ";" + cargoMax; String res = getId() + ";" + getName() + ";" + cargoMax;
if (getType().isPresent()) {
res += ";" + getType().getAsInt();
}
return res;
} }
public TransportShip(String s) { public TransportShip(String s) {
super(s); super(s);
String[] tokens = s.split(";"); 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