From f75c0cc00277c144118008bf237c52c6a7fb7d5d 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: Thu, 20 Jun 2019 14:02:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=BE?= =?UTF-8?q?=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=BE=D1=82=20?= =?UTF-8?q?=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inport/ConversionUtil.java | 15 ++---- src/inport/Operation.java | 49 +++++++++++++++++- src/inport/TaskCase.java | 72 ++++++++++---------------- tests/with_typing/Bunkers.tipp | 2 + tests/with_typing/FixedOperations.tipp | 3 ++ 5 files changed, 82 insertions(+), 59 deletions(-) diff --git a/src/inport/ConversionUtil.java b/src/inport/ConversionUtil.java index 4af060a..865ed27 100644 --- a/src/inport/ConversionUtil.java +++ b/src/inport/ConversionUtil.java @@ -1321,7 +1321,7 @@ public class ConversionUtil { isFixed.get(i).add(false); } } - for (Operation op : task.getSolution()) { + for (Operation op : task.getFixedOperations()) { if (op.getFixation()) { int operation = opNoByOpIdAndExecutorNo.get(new Pair<>(op.getTemplate().getId(), op.getExecutor().getId())); @@ -1378,7 +1378,7 @@ public class ConversionUtil { opNoByOpData.put(new OperationData(op.getId(), getExecutor(op).getId(), bunkerId), i); } - for (Operation op : task.getSolution()) { + for (Operation op : task.getFixedOperations()) { if (op.getFixation()) { OptionalInt bunkerId = op.getBunker().map(b -> OptionalInt.of(b.getId())).orElse(OptionalInt.empty()); @@ -1580,15 +1580,6 @@ public class ConversionUtil { } } -// System.out.print("#######\n"); -// for (int i = 0; i < sectionNById.size(); i++) { -// for (Integer val : positionsOfConnectedSections.get(i)) { -// System.out.print(val + " "); -// } -// System.out.print("\n"); -// } -// System.out.print("---\n"); - ArrayList operationsMainStorNoInSecondary = new ArrayList<>(); ArrayList operationsSecondaryStorNoInMain = new ArrayList<>(); @@ -1901,7 +1892,7 @@ public class ConversionUtil { isFixed = task.getIsFixedArray(); Set oldSolution = new TreeSet<>(); - for (Operation op : taskCase.getSolution()) { + for (Operation op : taskCase.getFixedOperations()) { if (op.getFixation()) { oldSolution.add(op.toString()); } diff --git a/src/inport/Operation.java b/src/inport/Operation.java index 536d7f4..a98c22a 100644 --- a/src/inport/Operation.java +++ b/src/inport/Operation.java @@ -4,8 +4,7 @@ */ package inport; -import java.util.List; -import java.util.Optional; +import java.util.*; /** * @@ -143,4 +142,50 @@ public class Operation { sb.append(")"); return sb.toString(); } + + public Operation(String str, + Map m_vessel, + Map m_bunker, + Map m_equipment, + Map m_template) { + + String lStr = str.substring(0, str.indexOf('(')).trim(); + String rStr = str.substring(str.indexOf('(') + 1, str.indexOf(')')).trim(); + + { + String[] items = lStr.split(";"); + setStart(Double.parseDouble(items[2].trim())); + setDuration(Double.parseDouble(items[3].trim())); + setTemplate(m_template.get(Integer.parseInt(items[0].trim()))); + + setFixation(items[1].trim().equals("F")); + } + { + String[] items = rStr.substring(rStr.indexOf('[') + 1, rStr.indexOf(']')).split(","); + ArrayList resources = new ArrayList<>(); + for (String item : items) { + if (item.trim().isEmpty()) { + continue; + } + resources.add(m_equipment.get(Integer.valueOf(item.trim()))); + } + setResources(resources); + } + { + String[] items = rStr.substring(0, rStr.indexOf('[')).split(" "); + + MovingObject ex = m_vessel.get(Integer.valueOf(items[0].trim())); + if (ex == null) { + ex = m_bunker.get(Integer.valueOf(items[0].trim())); + } + setExecutor(ex); + if (items.length > 1) { + setBunker(Optional.of(m_bunker.get(Integer.valueOf(items[1].trim())))); + } + } + String intensity = rStr.substring(rStr.indexOf(']') + 1).trim(); + if (! intensity.isEmpty()) { + setIntensity(Optional.of(Integer.valueOf(intensity))); + } + } } diff --git a/src/inport/TaskCase.java b/src/inport/TaskCase.java index fb6cb99..2a9524d 100644 --- a/src/inport/TaskCase.java +++ b/src/inport/TaskCase.java @@ -60,16 +60,26 @@ public class TaskCase { // Горизонт планирования private double planningInterval; - + + // Зафиксированные операции. + private List fixedOperations; + // Тип критерия оптимизации private int criterionType; - + // План - критерий private double solution_result; - + // План - решение private List solution; + public List getFixedOperations() { + return fixedOperations; + } + public void setFixedOperations(List fixedOperations) { + this.fixedOperations = fixedOperations; + } + public Map getBunkerTypes() { return bunkerTypes; } @@ -408,7 +418,9 @@ public class TaskCase { vesselEndState = new ArrayList<>(); storageEndState = new ArrayList<>(); - + + fixedOperations = new ArrayList<>(); + solution = new ArrayList<>(); } @@ -448,6 +460,7 @@ public class TaskCase { Final_Vessel_State ("Final Vessel State"), Final_Storage_State ("Final Storage State"), Task_Properties ("Task Properties"), + Fixed_Operations ("Fixed Operations"), Solution ("Solution"); private final String text; @@ -469,6 +482,7 @@ public class TaskCase { 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(); bunkerTypes.clear(); + fixedOperations.clear(); solution.clear(); // Open the file @@ -688,51 +702,14 @@ public class TaskCase { criterionType = Integer.parseInt(rs[1].trim()); } break; + case Fixed_Operations: + fixedOperations.add(new Operation(strLine, m_vessel, m_bunker, m_equipment, m_template)); + break; case Solution: // Чтение операций. if (numInside == 1) { solution_result = Double.parseDouble(strLine.trim()); } else { - String lStr = strLine.substring(0, strLine.indexOf('(')).trim(); - String rStr = strLine.substring(strLine.indexOf('(') + 1, strLine.indexOf(')')).trim(); - - Operation op = new Operation(); - { - String[] items = lStr.split(";"); - op.setStart(Double.parseDouble(items[2].trim())); - op.setDuration(Double.parseDouble(items[3].trim())); - op.setTemplate(m_template.get(Integer.parseInt(items[0].trim()))); - - op.setFixation(items[1].trim().equals("F")); - } - { - String[] items = rStr.substring(rStr.indexOf('[') + 1, rStr.indexOf(']')).split(","); - ArrayList resources = new ArrayList<>(); - for (String item : items) { - if (item.trim().isEmpty()) { - continue; - } - resources.add(m_equipment.get(Integer.valueOf(item.trim()))); - } - op.setResources(resources); - } - { - String[] items = rStr.substring(0, rStr.indexOf('[')).split(" "); - - MovingObject ex = m_vessel.get(Integer.valueOf(items[0].trim())); - if (ex == null) { - ex = m_bunker.get(Integer.valueOf(items[0].trim())); - } - op.setExecutor(ex); - if (items.length > 1) { - op.setBunker(Optional.of(m_bunker.get(Integer.valueOf(items[1].trim())))); - } - } - String intensity = rStr.substring(rStr.indexOf(']') + 1).trim(); - if (! intensity.isEmpty()) { - op.setIntensity(Optional.of(Integer.valueOf(intensity))); - } - - solution.add(op); + solution.add(new Operation(strLine, m_vessel, m_bunker, m_equipment, m_template)); } break; default: @@ -822,6 +799,11 @@ public class TaskCase { writer.write("\n"); writer.write("\nTask Properties"+"\n"); writer.write(planningInterval+"; "+criterionType+"\n"); + + writer.write("\n" + Tag.Fixed_Operations.text + "\n"); + for (Operation op : fixedOperations) { + writer.write(op.toString() + "\n"); + } writer.write("\n"); writer.write("\nSolution"+"\n"); writer.write(solution_result+"\n"); diff --git a/tests/with_typing/Bunkers.tipp b/tests/with_typing/Bunkers.tipp index 5e67141..2d7694a 100644 --- a/tests/with_typing/Bunkers.tipp +++ b/tests/with_typing/Bunkers.tipp @@ -76,6 +76,8 @@ Final Storage State Task Properties 20.0; 0 +Fixed Operations +20; F; 1.0; 2.0 (101 202 [] 2) Solution 8.0 diff --git a/tests/with_typing/FixedOperations.tipp b/tests/with_typing/FixedOperations.tipp index d4e56ac..ca8ac7e 100644 --- a/tests/with_typing/FixedOperations.tipp +++ b/tests/with_typing/FixedOperations.tipp @@ -62,6 +62,9 @@ Final Storage State Task Properties 30.0; 0 +Fixed Operations +21; F; 0.0; 3.0 (5 []) +19; F; 6.0; 3.0 (5 [] 10) Solution 18.0 -- GitLab