Commit 2766a7f9 authored by Vladislav Kiselev's avatar Vladislav Kiselev

Добавлена возможность бункеровки, упрощено сведение.

parent c22255ea
This diff is collapsed.
...@@ -8,26 +8,17 @@ package inport; ...@@ -8,26 +8,17 @@ package inport;
* *
* @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, double cargoMax) {
super(id, name); super(id, name, cargoMax);
} }
public Bunker() { public Bunker() {
super( ); super( );
} }
@Override
public String toString() {
return getId() + ";" + getName();
}
public Bunker(String s) { public Bunker(String s) {
super(s); super(s);
} }
} }
This diff is collapsed.
...@@ -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.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
/** /**
...@@ -16,6 +17,8 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -16,6 +17,8 @@ public class LoadingTemplate extends OperationTemplate {
private TransportShip loader; private TransportShip loader;
private OptionalInt loaderType = OptionalInt.empty(); 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 List<Integer> resourcesTypes;
...@@ -23,6 +26,20 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -23,6 +26,20 @@ public class LoadingTemplate extends OperationTemplate {
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() { public OptionalInt getLoaderType() {
return loaderType; return loaderType;
} }
...@@ -95,11 +112,19 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -95,11 +112,19 @@ public class LoadingTemplate extends OperationTemplate {
return cargo; return cargo;
} }
public LoadingTemplate(TransportShip loader, Berth berth, Storage storage, Cargo cargo, public LoadingTemplate(TransportShip loader,
List<Integer> resourcesTypes, boolean withMooring, double intensity, int id) { 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.resourcesTypes = new ArrayList<>(resourcesTypes);
this.withMooring = withMooring; this.withMooring = withMooring;
...@@ -130,20 +155,20 @@ public class LoadingTemplate extends OperationTemplate { ...@@ -130,20 +155,20 @@ public class LoadingTemplate extends OperationTemplate {
res += t; res += t;
first = false; first = false;
} }
int startId;
if (loaderType.isPresent()) {
startId = loaderType.getAsInt();
} else {
startId = loader.getId();
}
int source = startId; int source = (loaderType.isPresent() ? loaderType.getAsInt() : loader.getId());
if (intensity>0) int target;
source = storage.getId(); if (bunkerType.isPresent()) {
int target = startId; target = bunkerType.getAsInt();
if (intensity<=0) } else target = bunker.map(MovingObject::getId).orElseGet(() -> storage.getId());
target = storage.getId();
if (intensity > 0) {
int temp = source;
source = target;
target = temp;
}
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");
} }
} }
...@@ -100,7 +100,6 @@ public class Main { ...@@ -100,7 +100,6 @@ public class Main {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
break; break;
} }
String error = solveTask_2(task); String error = solveTask_2(task);
if (!error.isEmpty()) { if (!error.isEmpty()) {
...@@ -148,10 +147,7 @@ public class Main { ...@@ -148,10 +147,7 @@ public class Main {
} }
Task t = new Task(task, ""); Task t = new Task(task, "");
{ {
ArrayList<MovingObject> movingObjects = new ArrayList<>(); ArrayList<MovingObject> movingObjects = Task.calcMovingObjects(task);
movingObjects.addAll(task.getShips());
movingObjects.addAll(task.getTows());
movingObjects.addAll(task.getEquipments());
Map<Integer, MovingObject> objByNo = new TreeMap<>(); Map<Integer, MovingObject> objByNo = new TreeMap<>();
for (MovingObject obj : movingObjects) { for (MovingObject obj : movingObjects) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package inport; package inport;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* *
...@@ -17,8 +18,16 @@ public class Operation { ...@@ -17,8 +18,16 @@ public class Operation {
private double start; private double start;
private double duration; private double duration;
private MovingObject executor; private MovingObject executor;
private Optional<Bunker> bunker = Optional.empty();
private List<MovingObject> resources; private List<MovingObject> resources;
public Optional<Bunker> getBunker() {
return bunker;
}
public void setBunker(Optional<Bunker> bunker) {
this.bunker = bunker;
}
public boolean getFixation() { public boolean getFixation() {
return fixation; return fixation;
} }
...@@ -110,7 +119,8 @@ public class Operation { ...@@ -110,7 +119,8 @@ public class Operation {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(template.getId()).append("; "); sb.append(template.getId()).append("; ");
sb.append(fixation ? "F" : "R").append("; ").append(start).append("; ").append(duration); sb.append(fixation ? "F" : "R").append("; ").append(start).append("; ").append(duration);
sb.append(" (").append(executor.getId()).append(" ["); sb.append(" (").append(executor.getId()).append(" ");
sb.append(bunker.map(b -> b.getId() + " ").orElse("")).append("[");
boolean isFirst = true; boolean isFirst = true;
for (MovingObject obj : resources) { for (MovingObject obj : resources) {
if (isFirst) { if (isFirst) {
......
...@@ -101,7 +101,7 @@ public class Storage { ...@@ -101,7 +101,7 @@ public class Storage {
@Override @Override
public String toString() { public String toString() {
return id + "; " + name + "; " + cargo.getId() + "; " +volume; return id + "; " + name + "; " + cargo.getId() + "; " + volume;
} }
public Storage(String s, Map<Integer, Cargo> cargoes) { public Storage(String s, Map<Integer, Cargo> cargoes) {
......
...@@ -82,15 +82,24 @@ public class StorageState { ...@@ -82,15 +82,24 @@ public class StorageState {
return ""; return "";
} }
public StorageState(String s, Map<Integer, Storage> mp, Map<Integer, MovingObject> vp, Map<Integer, Cargo> cp) { public StorageState(String s,
Map<Integer, Storage> mp,
Map<Integer, MovingObject> vp,
Map<Integer, Bunker> bunkers,
Map<Integer, Cargo> cp) {
String[] tokens = s.split(";"); String[] tokens = s.split(";");
int key = Integer.parseInt(tokens[0].trim()); int key = Integer.parseInt(tokens[0].trim());
cargo = cp.get(key); cargo = cp.get(key);
key = Integer.parseInt(tokens[1].trim()); key = Integer.parseInt(tokens[1].trim());
if (mp.containsKey(key)) if (mp.containsKey(key)) {
storage = mp.get(key); storage = mp.get(key);
if (vp.containsKey(key)) }
if (vp.containsKey(key)) {
storage = vp.get(key); storage = vp.get(key);
}
if (bunkers.containsKey(key)) {
storage = bunkers.get(key);
}
cargoState = Double.parseDouble(tokens[2].trim()); cargoState = Double.parseDouble(tokens[2].trim());
} }
......
This diff is collapsed.
Typified
1
Cargoes
10001; Нечто; 0.0
10002; Топливо; 0.0
Berths
1; Raid
2; Pier 1
3; Pier 2
Storages
4; Storage 1; 10001; 10000.0
Vessel Types
1001; Тип судна 1
Bunker Types
2001; Тип бункировщика 1
Bunkers
201; Bunker 1; 2000.0; 2001
202; Bunker 2; 2000.0; 2001
Tows
Loading Equipment Types
Loading Equipments
Transport Ships
101; Ship 1; 2000.0; 1001
102; Ship 2; 2000.0; 1001
Templates
7; mov; []; 1001; 1; 2; []; 1.0
8; mov; []; 1001; 2; 1; []; 1.0
9; mov; []; 1001; 1; 3; []; 1.0
10; mov; []; 1001; 3; 1; []; 1.0
11; mov; []; 1001; 2; 3; []; 1.0
12; mov; []; 1001; 3; 2; []; 1.0
13; mov; []; 2001; 3; 2; []; 1.0
14; mov; []; 2001; 3; 2; []; 1.0
19; loa; []; 4; 10001; 1001; 2; []; 100.0; U
20; loa; []; 2001; 10002; 1001; 2; []; 10.0; U
Cargo Flows
Initial Vessel State
101; 1
102; 1
201; 2
202; 2
Initial Storage State
10001; 101; 0.0
10002; 101; 0.0
10001; 102; 0.0
10002; 102; 0.0
10002; 201; 20.0
10002; 202; 20.0
10001; 4; 10000.0
Final Vessel State
101; 1
102; 1
Final Storage State
10001; 101; 300.0
10002; 101; 20.0
10001; 102; 300.0
10002; 102; 20.0
Task Properties
30.0; 0
Solution
8.0
7; R; 0.0; 1.0 (101 [])
9; R; 0.0; 1.0 (102 [])
19; R; 1.0; 3.0 (101 [])
20; R; 1.0; 1.0 (101 [])
10; R; 2.0; 1.0 (102 [])
7; R; 3.0; 1.0 (102 [])
20; R; 3.0; 1.0 (101 [])
11; R; 4.0; 1.0 (101 [])
19; R; 4.0; 3.0 (102 [])
20; R; 4.0; 1.0 (102 [])
20; R; 5.0; 1.0 (102 [])
8; R; 7.0; 1.0 (102 [])
10; R; 7.0; 1.0 (101 [])
...@@ -69,7 +69,7 @@ Final Storage State ...@@ -69,7 +69,7 @@ Final Storage State
Task Properties Task Properties
30.0; 0 22.0; 0
Solution Solution
......
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