Commit 7472c3be authored by Vladislav Kiselev's avatar Vladislav Kiselev

Добывлен вывод конкретных бункеровщиков в ответ. Оперрации бункеровки можно корректно фиксировать.

parent df752fb2
package inport; package inport;
import javafx.util.Pair; import javafx.util.Pair;
import org.jetbrains.annotations.NotNull;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
...@@ -8,7 +9,7 @@ import java.util.function.BiConsumer; ...@@ -8,7 +9,7 @@ import java.util.function.BiConsumer;
import java.util.function.Function; import java.util.function.Function;
public class ConversionUtil { public class ConversionUtil {
static class PairComparator<T extends Comparable, U extends Comparable> implements Comparator<Pair<T, U>> { 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) { public int compare(Pair<T, U> p1, Pair<T, U> p2) {
int res = p1.getKey().compareTo(p2.getKey()); int res = p1.getKey().compareTo(p2.getKey());
if (res != 0) { if (res != 0) {
...@@ -1308,15 +1309,49 @@ public class ConversionUtil { ...@@ -1308,15 +1309,49 @@ public class ConversionUtil {
ArrayList<Integer> fixedOpStart = new ArrayList<>(); ArrayList<Integer> fixedOpStart = new ArrayList<>();
ArrayList<Integer> fixedOpEnd = new ArrayList<>(); ArrayList<Integer> fixedOpEnd = new ArrayList<>();
Map<Pair<Integer, Integer>, Integer> opNoByOpIdAndExecutorNo = new TreeMap<>(new PairComparator<>()); class OperationData implements Comparable<OperationData> {
private int opId, executorId;
private OptionalInt bunkerId;
OperationData(int opId, int executorId, OptionalInt bunkerId) {
this.opId = opId;
this.executorId = executorId;
this.bunkerId = bunkerId;
}
@Override
public int compareTo(@NotNull OperationData o) {
if (opId != o.opId) {
return Integer.compare(opId, o.opId);
}
if (executorId != o.executorId) {
return Integer.compare(opId, o.opId);
}
if (! bunkerId.isPresent()) {
return -1;
}
if (! o.bunkerId.isPresent()) {
return 1;
}
return Integer.compare(bunkerId.getAsInt(), o.bunkerId.getAsInt());
}
};
Map<OperationData, Integer> opNoByOpData = new TreeMap<>();
for (int i = 0; i < operationTemplates.size(); i++) { for (int i = 0; i < operationTemplates.size(); i++) {
OperationTemplate op = operationTemplates.get(i); OperationTemplate op = operationTemplates.get(i);
opNoByOpIdAndExecutorNo.put(new Pair<>(op.getId(), getExecutor(op).getId()), i); OptionalInt bunkerId = OptionalInt.empty();
if ((op instanceof LoadingTemplate) && (((LoadingTemplate)op).getBunker().isPresent())) {
bunkerId = OptionalInt.of(((LoadingTemplate)op).getBunker().get().getId());
}
opNoByOpData.put(new OperationData(op.getId(), getExecutor(op).getId(), bunkerId), i);
} }
for (Operation op : task.getSolution()) { for (Operation op : task.getSolution()) {
if (op.getFixation()) { if (op.getFixation()) {
fixedOp.add(opNoByOpIdAndExecutorNo.get(new Pair<>(op.getTemplate().getId(), op.getExecutor().getId())) + 1); OptionalInt bunkerId = op.getBunker().map(b -> OptionalInt.of(b.getId())).orElse(OptionalInt.empty());
fixedOp.add(opNoByOpData.get(new OperationData(op.getTemplate().getId(), op.getExecutor().getId(), bunkerId)) + 1);
TreeSet<Integer> resources = new TreeSet<>(); TreeSet<Integer> resources = new TreeSet<>();
for (MovingObject obj : op.getResources()) { for (MovingObject obj : op.getResources()) {
resources.add(mObjToN(obj)); resources.add(mObjToN(obj));
...@@ -1660,12 +1695,12 @@ public class ConversionUtil { ...@@ -1660,12 +1695,12 @@ public class ConversionUtil {
op.setResources(resources); op.setResources(resources);
} }
{ { // Установка бункеровщика.
OperationTemplate template = templates.get(opNo - 1); OperationTemplate template = templates.get(opNo - 1);
if (template instanceof LoadingTemplate) { if (template instanceof LoadingTemplate) {
LoadingTemplate operation = (LoadingTemplate)template; LoadingTemplate operation = (LoadingTemplate)template;
if (operation.getBunker().isPresent()) { if (operation.getBunker().isPresent()) {
// TODO Доделать. op.setBunker(operation.getBunker());
} }
} }
} }
......
...@@ -683,7 +683,7 @@ public class TaskCase { ...@@ -683,7 +683,7 @@ public class TaskCase {
criterionType = Integer.parseInt(rs[1].trim()); criterionType = Integer.parseInt(rs[1].trim());
} }
break; break;
case Solution: // Тут чтение операций если надо. Потом подумаем case Solution: // Чтение операций.
if (numInside == 1) { if (numInside == 1) {
solution_result = Double.parseDouble(strLine.trim()); solution_result = Double.parseDouble(strLine.trim());
} else { } else {
...@@ -710,8 +710,14 @@ public class TaskCase { ...@@ -710,8 +710,14 @@ public class TaskCase {
} }
op.setResources(resources); op.setResources(resources);
} }
int exId = Integer.valueOf(rStr.substring(0, rStr.indexOf('[')).trim()); {
op.setExecutor(m_vessel.get(exId)); String[] items = rStr.substring(0, rStr.indexOf('[')).split(" ");
op.setExecutor(m_vessel.get(Integer.valueOf(items[0].trim())));
if (items.length > 1) {
op.setBunker(Optional.of(m_bunker.get(Integer.valueOf(items[1].trim()))));
}
}
solution.add(op); solution.add(op);
} }
......
...@@ -42,8 +42,8 @@ Templates ...@@ -42,8 +42,8 @@ Templates
12; mov; []; 1001; 3; 2; []; 1.0 12; mov; []; 1001; 3; 2; []; 1.0
13; mov; []; 2001; 3; 2; []; 1.0 13; mov; []; 2001; 3; 2; []; 1.0
14; mov; []; 2001; 3; 2; []; 1.0 14; mov; []; 2001; 3; 2; []; 1.0
19; loa; []; 4; 10001; 1001; 2; []; 100.0; U 19; loa; []; 4; 10001; 1001; 2; []; 20.0; U
20; loa; []; 2001; 10002; 1001; 2; []; 10.0; U 20; loa; []; 2001; 10002; 1001; 2; []; 2.0; U
Cargo Flows Cargo Flows
...@@ -58,8 +58,8 @@ Initial Storage State ...@@ -58,8 +58,8 @@ Initial Storage State
10002; 101; 0.0 10002; 101; 0.0
10001; 102; 0.0 10001; 102; 0.0
10002; 102; 0.0 10002; 102; 0.0
10002; 201; 20.0 10002; 201; 4.0
10002; 202; 20.0 10002; 202; 4.0
10001; 4; 10000.0 10001; 4; 10000.0
Final Vessel State Final Vessel State
...@@ -67,10 +67,10 @@ Final Vessel State ...@@ -67,10 +67,10 @@ Final Vessel State
102; 1 102; 1
Final Storage State Final Storage State
10001; 101; 300.0 10001; 101; 60.0
10002; 101; 20.0 10002; 101; 4.0
10001; 102; 300.0 10001; 102; 60.0
10002; 102; 20.0 10002; 102; 4.0
Task Properties Task Properties
...@@ -79,16 +79,4 @@ Task Properties ...@@ -79,16 +79,4 @@ Task Properties
Solution Solution
8.0 8.0
7; R; 0.0; 1.0 (101 []) 20; F; 1.0; 2.0 (101 202 [])
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 [])
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