[14757] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[15456] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[14757] | 24 | using System.IO;
|
---|
[15456] | 25 | using System.Linq;
|
---|
[14757] | 26 | using System.Text;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Problems.Instances.CFSAP {
|
---|
| 29 | public class BozejkoCFSAPParser {
|
---|
| 30 | public int Jobs { get; private set; }
|
---|
[15456] | 31 | public int[] Machines { get; private set; }
|
---|
| 32 | public int Nests { get; private set; }
|
---|
| 33 | public List<int[][]> ProcessingTimes { get; private set; }
|
---|
| 34 | public List<int[][][]> SetupTimes { get; private set; }
|
---|
[14757] | 35 |
|
---|
| 36 | public void Parse(Stream stream) {
|
---|
| 37 | using (var reader = new StreamReader(stream)) {
|
---|
[15456] | 38 | Nests = GetNextInteger(reader);
|
---|
| 39 | Jobs = GetNextInteger(reader);
|
---|
| 40 | Machines = Enumerable.Range(0, Nests).Select(x => GetNextInteger(reader)).ToArray();
|
---|
| 41 | ProcessingTimes = new List<int[][]>(Nests);
|
---|
| 42 | SetupTimes = new List<int[][][]>(Nests);
|
---|
[14757] | 43 |
|
---|
[15456] | 44 | for (var n = 0; n < Nests; n++) {
|
---|
| 45 | var machines = Machines[n];
|
---|
| 46 | var pr = new int[machines][];
|
---|
| 47 | for (var m = 0; m < machines; m++) {
|
---|
| 48 | pr[m] = new int[Jobs];
|
---|
| 49 | for (var j = 0; j < Jobs; j++) {
|
---|
| 50 | pr[m][j] = GetNextInteger(reader);
|
---|
| 51 | }
|
---|
[14757] | 52 | }
|
---|
[15456] | 53 | ProcessingTimes.Add(pr);
|
---|
[14757] | 54 | }
|
---|
[15456] | 55 | for (var n = 0; n < Nests; n++) {
|
---|
| 56 | var machines = Machines[n];
|
---|
| 57 | var sp = new int[machines][][];
|
---|
| 58 | for (var m = 0; m < machines; m++) {
|
---|
| 59 | sp[m] = new int[Jobs][];
|
---|
| 60 | for (var j = 0; j < Jobs; j++) {
|
---|
| 61 | sp[m][j] = new int[Jobs];
|
---|
| 62 | for (var i = 0; i < Jobs; i++) {
|
---|
| 63 | sp[m][j][i] = GetNextInteger(reader);
|
---|
| 64 | }
|
---|
[14757] | 65 | }
|
---|
| 66 | }
|
---|
[15460] | 67 | SetupTimes.Add(sp);
|
---|
[14757] | 68 | }
|
---|
| 69 | reader.Close();
|
---|
| 70 | stream.Close();
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[15456] | 74 | private int GetNextInteger(StreamReader reader) {
|
---|
[14757] | 75 | var builder = new StringBuilder();
|
---|
| 76 | int r = reader.Read();
|
---|
| 77 | while (r >= 0) {
|
---|
| 78 | var c = (char)r;
|
---|
| 79 | if ((c == ' ' || c == '\t' || c == '\r' || c == '\n') && builder.Length > 0)
|
---|
| 80 | return int.Parse(builder.ToString());
|
---|
[15456] | 81 | if (c == 'N' || c == 'M') {
|
---|
| 82 | // consume the whole line
|
---|
| 83 | reader.ReadLine();
|
---|
| 84 | r = reader.Read();
|
---|
| 85 | continue;
|
---|
| 86 | }
|
---|
[14757] | 87 | if (char.IsNumber(c)) builder.Append(c);
|
---|
| 88 | r = reader.Read();
|
---|
[15456] | 89 | if (r == -1 && builder.Length > 0) return int.Parse(builder.ToString());
|
---|
[14757] | 90 | }
|
---|
[15456] | 91 | throw new InvalidOperationException("Stream does not contain more numbers");
|
---|
[14757] | 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|