[14838] | 1 | #region License Information
|
---|
| 2 |
|
---|
| 3 | /* HeuristicLab
|
---|
[16565] | 4 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14838] | 5 | *
|
---|
| 6 | * This file is part of HeuristicLab.
|
---|
| 7 | *
|
---|
| 8 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 9 | * it under the terms of the GNU General Public License as published by
|
---|
| 10 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 11 | * (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * You should have received a copy of the GNU General Public License
|
---|
| 19 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #endregion
|
---|
| 23 |
|
---|
| 24 | using System;
|
---|
| 25 | using System.Collections.Generic;
|
---|
| 26 | using System.IO;
|
---|
| 27 | using System.Text;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Problems.BinPacking3D {
|
---|
| 30 | public class ThreeDInstanceParser {
|
---|
| 31 | public PackingShape Bin { get; private set; }
|
---|
| 32 | public List<PackingItem> Items { get; private set; }
|
---|
| 33 |
|
---|
| 34 | public void Parse(Stream stream) {
|
---|
| 35 | var reader = new StreamReader(stream);
|
---|
[15229] | 36 | var length = GetNextInteger(reader);
|
---|
| 37 | var width = GetNextInteger(reader);
|
---|
| 38 | var height = GetNextInteger(reader);
|
---|
| 39 | var maxWeight = GetNextInteger(reader);
|
---|
[14838] | 40 | Bin = new PackingShape(width, height, length);
|
---|
| 41 | Items = new List<PackingItem>();
|
---|
| 42 | while (true) {
|
---|
| 43 | try {
|
---|
[15229] | 44 | var id = GetNextInteger(reader);
|
---|
| 45 | var pieces = GetNextInteger(reader);
|
---|
| 46 | length = GetNextInteger(reader);
|
---|
| 47 | width = GetNextInteger(reader);
|
---|
| 48 | height = GetNextInteger(reader);
|
---|
| 49 | var weight = GetNextInteger(reader);
|
---|
| 50 | var stack = GetNextInteger(reader);
|
---|
| 51 | var material = GetNextInteger(reader);
|
---|
| 52 | var rotate = GetNextInteger(reader);
|
---|
| 53 | var tilt = GetNextInteger(reader);
|
---|
[14838] | 54 | for (var i = 0; i < pieces; i++) {
|
---|
[15229] | 55 | Items.Add(new PackingItem(width, height, length, Bin, weight, material));
|
---|
[14838] | 56 | }
|
---|
| 57 | } catch (InvalidOperationException) {
|
---|
| 58 | break;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[15229] | 63 | private int GetNextInteger(StreamReader reader) {
|
---|
[14838] | 64 | var next = reader.Read();
|
---|
| 65 | var builder = new StringBuilder();
|
---|
| 66 | while (next >= 0 && !char.IsDigit((char)next)) next = reader.Read();
|
---|
[15229] | 67 | if (next == -1) throw new InvalidOperationException("No further integer available");
|
---|
[14838] | 68 | while (char.IsDigit((char)next)) {
|
---|
| 69 | builder.Append((char)next);
|
---|
| 70 | next = reader.Read();
|
---|
| 71 | if (next == -1) break;
|
---|
| 72 | }
|
---|
| 73 | return int.Parse(builder.ToString());
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|