Commit a815785e authored by Vladislav Kiselev's avatar Vladislav Kiselev
parents 0eac4c02 d98cea2f
set out_dir=temp
if not exist %out_dir% mkdir %out_dir%
javac -d %out_dir% -encoding UTF-8 -classpath annotations-java8.jar src/inport/*.java src/inport/ConversionUtils/*.java
jar cfe Conversion.jar inport.Main -C %out_dir% inport -C src constraints
rmdir /s /q %out_dir%
out_dir = temp
Conversion.jar: src/inport/*.java src/constraints/*.mzn manifest.txt
mkdir -p $(out_dir)
javac -d $(out_dir) -encoding UTF-8 -classpath annotations-java8.jar src/inport/*.java
cd $(out_dir) && jar -cvfm ../Conversion.jar ../manifest.txt inport/* ../src/constraints/../constraints/*
# Внутрипортовое планирование
Описание сведения к minizinc-у можно найти в "Планирование портовых операций.docx".
### Сборка
Для создания jar-архива необходимо запустить
+ Make.bat - для Windows.
+ Makefile - для Linux.
### Запуск
`java -jar Conversion.jar solve example.tipp [conversion_type]` <br>
где
+ example.tipp - файл с исходными данными, в него же будет дописан результат.
+ conversion_type - тип сведения, может быть
- "Without splitting" - операции грузообработки всегда выполняются полностью, ограничения из constraints/conversion_2.mzn. Вариант по умолчанию.
- "With splitting" - интенсивность операции может изменятся от 1 до её максимального значения, ограничения из constraints/conversion_2_with_partial_cargo_operations.mzn.
- "Greedy v2" - "жадный алгоритм", ограничения из conversion_2_greedy_v2.mzn.
### Тестирование
Проверенные тесты находятся в tests/with_typing . Их последовательный запуск: <br>
`java -jar Conversion.jar testing [conversion_type]` <br> где
+ conversion_type - тип сведения, тот же что и при запуске.
...@@ -279,7 +279,7 @@ constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) ( % Само о ...@@ -279,7 +279,7 @@ constraint forall (obj in 1..n_moving_obj, t in 1..n_intervals) ( % Само о
solve minimize sum(is_not_terminated); solve minimize sum(is_not_terminated);
output [show(sum(is_not_terminated)), "\n", output [show(sum(is_not_terminated)), "\n",
show(op_status), "\n\n", "op_status = ", show(op_status), "\n\n",
"m_obj_loc = ", show(m_obj_loc), "\n\n", "m_obj_loc = ", show(m_obj_loc), "\n\n",
"op_fin = ", show(op_fin), "\n\n", "op_fin = ", show(op_fin), "\n\n",
"op_start = ", show(op_start), "\n\n", "op_start = ", show(op_start), "\n\n",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -69,7 +69,7 @@ public class Berth { ...@@ -69,7 +69,7 @@ public class Berth {
@Override @Override
public String toString() { public String toString() {
return id + ";" + name; return id + "; " + name;
} }
public Berth(String s) { public Berth(String s) {
......
...@@ -4,30 +4,26 @@ ...@@ -4,30 +4,26 @@
*/ */
package inport; package inport;
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.Map;
/** /**
* *
* @author topazh_ag * @author topazh_ag
*/ */
public class Bunker extends MovingObject { public class Bunker extends TransportShip {
public Bunker(int id, String name) { public Bunker(int id, String name, ArrayList<Pair<Cargo, Double>> storageSections) {
super(id, name); super(id, name, storageSections);
} }
public Bunker() { public Bunker() {
super( ); super( );
} }
public Bunker(String s, Map<Integer, Cargo> mCargo) {
@Override super(s, mCargo);
public String toString() {
return getId() + ";" + getName();
}
public Bunker(String s) {
super(s);
} }
} }
...@@ -79,7 +79,7 @@ public class Cargo { ...@@ -79,7 +79,7 @@ public class Cargo {
@Override @Override
public String toString() { public String toString() {
return id + ";" + name + ";" + cost; return id + "; " + name + "; " + cost;
} }
public Cargo(String s) { public Cargo(String s) {
......
...@@ -117,7 +117,7 @@ public class CargoFlow { ...@@ -117,7 +117,7 @@ public class CargoFlow {
res += s + ":" + flow.get(s); res += s + ":" + flow.get(s);
first = false; first = false;
} }
return storage.getId() + ";[" + res +"]"; return storage.getId() + "; [" + res +"]";
} }
public CargoFlow(String s, Map<Integer, Storage> mp, Map<Integer, Cargo> cp) { public CargoFlow(String s, Map<Integer, Storage> mp, Map<Integer, Cargo> cp) {
......
package inport;
public class ConversionException extends Exception {
ConversionException(String mess) {
super(mess);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package inport; package inport.ConversionUtils;
public class ParserException extends Exception { public class ParserException extends RuntimeException {
ParserException(String mess) { ParserException(String mess) {
super(mess); super(mess);
} }
......
This diff is collapsed.
package inport.ConversionUtils;
import inport.*;
import javafx.util.Pair;
import java.util.*;
public class Utils {
static class PairComparator<T extends Comparable<T>, U extends Comparable<U>> implements Comparator<Pair<T, U>> {
public int compare(Pair<T, U> p1, Pair<T, U> p2) {
int res = p1.getKey().compareTo(p2.getKey());
if (res != 0) {
return res;
} else {
return p1.getValue().compareTo(p2.getValue());
}
}
}
static public ArrayList<Integer> integerArray(int size, int initVal) {
ArrayList<Integer> res = new ArrayList<>();
for (int i = 0; i < size; i++) {
res.add(initVal);
}
return res;
}
static public ArrayList<ArrayList<Integer>> arrayOfIntegerArrays(int size) {
ArrayList<ArrayList<Integer>> res = new ArrayList<>();
for (int i = 0; i < size; i++) {
res.add(new ArrayList<>());
}
return res;
}
static public ArrayList<Set<Integer>> arrayOfIntegerSet(int size) {
ArrayList<Set<Integer>> res = new ArrayList<>();
for (int i = 0; i < size; i++) {
res.add(new TreeSet<>());
}
return res;
}
static public MovingObject getExecutor(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;
}
static public List<MovingObject> getResources(OperationTemplate t) {
List<MovingObject> 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;
}
static public boolean isCompatible(OperationTemplate t1, OperationTemplate t2) {
MovingObject exec1 = getExecutor(t1);
Berth place1 = t1.getStartLocation();
List<MovingObject> resources1 = getResources(t1);
MovingObject exec2 = getExecutor(t2);
Berth place2 = t2.getStartLocation();
List<MovingObject> resources2 = getResources(t2);
// Пересекаемость ресурсов
for (Object res2 : resources2)
if (resources1.contains(res2))
return false;
// Выполнитель = ресурс
if (resources1.contains(exec2))
return false;
// Ресурс = выполнитель
if (resources2.contains(exec1))
return false;
// Выполнитель = выполнитель
if (exec1.equals(exec2))
{
// Это не погрузка
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;
}
}
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
*/ */
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 >= 3) {
setType(OptionalInt.of(Integer.parseInt(tokens[2].trim())));
}
} }
} }
...@@ -6,6 +6,8 @@ package inport; ...@@ -6,6 +6,8 @@ package inport;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
/** /**
* *
...@@ -14,12 +16,37 @@ import java.util.List; ...@@ -14,12 +16,37 @@ 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 Optional<Bunker> bunker = Optional.empty();
private OptionalInt bunkerType = 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 getBunkerType() {
return bunkerType;
}
public void setBunkerType(OptionalInt bunkerType) {
this.bunkerType = bunkerType;
}
public Optional<Bunker> getBunker() {
return bunker;
}
public void setBunker(Optional<Bunker> bunker) {
this.bunker = bunker;
}
public OptionalInt getLoaderType() {
return loaderType;
}
public void setLoaderType(OptionalInt loaderType) {
this.loaderType = loaderType;
}
/** /**
* Get the value of resources * Get the value of resources
* *
...@@ -37,7 +64,14 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -37,7 +64,14 @@ public class LoadingTemplate extends OperationTemplate {
public void setResources(List<LoadingEquipment> resources) { public void setResources(List<LoadingEquipment> resources) {
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;
} }
...@@ -78,37 +112,63 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -78,37 +112,63 @@ public class LoadingTemplate extends OperationTemplate {
return cargo; return cargo;
} }
public LoadingTemplate(TransportShip loader, Berth berth, Storage storage, double intensity, int id) { public LoadingTemplate(TransportShip loader,
Berth berth,
Storage storage,
Cargo cargo,
Optional<Bunker> bunker,
List<Integer> resourcesTypes,
boolean withMooring,
double intensity,
int id) {
super(id, berth); super(id, berth);
this.loader = loader; this.loader = loader;
this.storage = storage; this.storage = storage;
this.bunker = bunker;
this.resources = new ArrayList<>(); this.resources = new ArrayList<>();
this.resourcesTypes = new ArrayList<>(resourcesTypes);
this.withMooring = withMooring;
this.intensity = intensity; this.intensity = intensity;
this.cargo = cargo;
} }
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 (intensity>0) if (!first)
source = storage.getId(); res += ", " + t;
int target = loader.getId(); else
if (intensity<=0) res += t;
target = storage.getId(); first = false;
return getId() + ";" + "loa;" + twtoString() + ";" + source + ";" + cargo.getId() + ";" + target + ";" }
+ getStartLocation().getId() + ";[" + res +"];" + Math.abs(intensity) + ";" + (withMooring ? "M" : "U");
} int source = (loaderType.isPresent() ? loaderType.getAsInt() : loader.getId());
int target;
if (bunkerType.isPresent()) {
target = bunkerType.getAsInt();
} else target = bunker.map(MovingObject::getId).orElseGet(() -> storage.getId());
if (intensity > 0) {
int temp = source;
source = target;
target = temp;
}
return getId() + "; " + "loa; " + twtoString() + "; " + source + "; " + cargo.getId() + "; " + target + "; "
+ getStartLocation().getId() + "; [" + res +"]; " + Math.abs(intensity) + "; "
+ (withMooring ? "M" : "U");
}
} }
This diff is collapsed.
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
*/ */
package inport; package inport;
import java.util.List;
import java.util.OptionalInt;
/** /**
* *
* @author topazh_ag * @author topazh_ag
...@@ -11,8 +14,16 @@ package inport; ...@@ -11,8 +14,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
* *
...@@ -49,10 +60,11 @@ public class MooringTemplate extends TowUsingTemplate { ...@@ -49,10 +60,11 @@ public class MooringTemplate extends TowUsingTemplate {
this.moorer = moorer; this.moorer = moorer;
} }
public MooringTemplate(TransportShip moorer, Berth berth, double duration, boolean direct, int id) { public MooringTemplate(TransportShip moorer, Berth berth, List<Integer> resourcesTypes, double duration, boolean direct, int id) {
super(duration, id, berth); super(duration, id, berth);
this.moorer = moorer; this.moorer = moorer;
this.direct = direct; this.direct = direct;
this.setResourcesTypes(resourcesTypes);
} }
public MooringTemplate() { public MooringTemplate() {
...@@ -63,18 +75,31 @@ public class MooringTemplate extends TowUsingTemplate { ...@@ -63,18 +75,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();
} }
} }
...@@ -64,7 +64,7 @@ public class MovingObjectState { ...@@ -64,7 +64,7 @@ public class MovingObjectState {
@Override @Override
public String toString() { public String toString() {
return getVessel().getId() + ";" + getLocation().getId(); return getVessel().getId() + "; " + getLocation().getId();
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -45,7 +45,7 @@ Final Storage State ...@@ -45,7 +45,7 @@ Final Storage State
0; 11; 2.0 0; 11; 2.0
Task Properties Task Properties
15.0;0 20.0;0
Solution Solution
12.0 15.0
This diff is collapsed.
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