From 7472c3be4585f53be6ff06d457fbf13d59c574f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=81=D0=B5=D0=BB=D1=91=D0=B2=20=D0=92=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2?= Date: Mon, 13 May 2019 21:16:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D1=8B=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D0=BA=D1=80=D0=B5=D1=82=D0=BD=D1=8B=D1=85=20=D0=B1=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D0=B5=D1=80=D0=BE=D0=B2=D1=89=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82.=20=D0=9E=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B1=D1=83=D0=BD=D0=BA?= =?UTF-8?q?=D0=B5=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE?= =?UTF-8?q?=20=D1=84=D0=B8=D0=BA=D1=81=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inport/ConversionUtil.java | 47 +++++++++++++++++++++++++++++----- src/inport/TaskCase.java | 12 ++++++--- tests/with_typing/Bunkers.tipp | 30 +++++++--------------- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/inport/ConversionUtil.java b/src/inport/ConversionUtil.java index f53db0a..d1e6e11 100644 --- a/src/inport/ConversionUtil.java +++ b/src/inport/ConversionUtil.java @@ -1,6 +1,7 @@ package inport; import javafx.util.Pair; +import org.jetbrains.annotations.NotNull; import java.io.*; import java.util.*; @@ -8,7 +9,7 @@ import java.util.function.BiConsumer; import java.util.function.Function; public class ConversionUtil { - static class PairComparator implements Comparator> { + static class PairComparator, U extends Comparable> implements Comparator> { public int compare(Pair p1, Pair p2) { int res = p1.getKey().compareTo(p2.getKey()); if (res != 0) { @@ -1308,15 +1309,49 @@ public class ConversionUtil { ArrayList fixedOpStart = new ArrayList<>(); ArrayList fixedOpEnd = new ArrayList<>(); - Map, Integer> opNoByOpIdAndExecutorNo = new TreeMap<>(new PairComparator<>()); + class OperationData implements Comparable { + 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 opNoByOpData = new TreeMap<>(); for (int i = 0; i < operationTemplates.size(); 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()) { 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 resources = new TreeSet<>(); for (MovingObject obj : op.getResources()) { resources.add(mObjToN(obj)); @@ -1660,12 +1695,12 @@ public class ConversionUtil { op.setResources(resources); } - { + { // Установка бункеровщика. OperationTemplate template = templates.get(opNo - 1); if (template instanceof LoadingTemplate) { LoadingTemplate operation = (LoadingTemplate)template; if (operation.getBunker().isPresent()) { - // TODO Доделать. + op.setBunker(operation.getBunker()); } } } diff --git a/src/inport/TaskCase.java b/src/inport/TaskCase.java index 06c6cf4..e9e9066 100644 --- a/src/inport/TaskCase.java +++ b/src/inport/TaskCase.java @@ -683,7 +683,7 @@ public class TaskCase { criterionType = Integer.parseInt(rs[1].trim()); } break; - case Solution: // Тут чтение операций если надо. Потом подумаем + case Solution: // Чтение операций. if (numInside == 1) { solution_result = Double.parseDouble(strLine.trim()); } else { @@ -710,8 +710,14 @@ public class TaskCase { } 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); } diff --git a/tests/with_typing/Bunkers.tipp b/tests/with_typing/Bunkers.tipp index 6df16f1..009470d 100644 --- a/tests/with_typing/Bunkers.tipp +++ b/tests/with_typing/Bunkers.tipp @@ -42,8 +42,8 @@ Templates 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 +19; loa; []; 4; 10001; 1001; 2; []; 20.0; U +20; loa; []; 2001; 10002; 1001; 2; []; 2.0; U Cargo Flows @@ -58,8 +58,8 @@ Initial Storage State 10002; 101; 0.0 10001; 102; 0.0 10002; 102; 0.0 -10002; 201; 20.0 -10002; 202; 20.0 +10002; 201; 4.0 +10002; 202; 4.0 10001; 4; 10000.0 Final Vessel State @@ -67,10 +67,10 @@ Final Vessel State 102; 1 Final Storage State -10001; 101; 300.0 -10002; 101; 20.0 -10001; 102; 300.0 -10002; 102; 20.0 +10001; 101; 60.0 +10002; 101; 4.0 +10001; 102; 60.0 +10002; 102; 4.0 Task Properties @@ -79,16 +79,4 @@ Task Properties 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 []) +20; F; 1.0; 2.0 (101 202 []) -- GitLab