#region License Information /* HeuristicLab * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace HeuristicLab.Problems.Instances.CFSAP { public class BozejkoCFSAPParser { public int Jobs { get; private set; } public int[] Machines { get; private set; } public int Nests { get; private set; } public List ProcessingTimes { get; private set; } public List SetupTimes { get; private set; } public void Parse(Stream stream) { using (var reader = new StreamReader(stream)) { Nests = GetNextInteger(reader); Jobs = GetNextInteger(reader); Machines = Enumerable.Range(0, Nests).Select(x => GetNextInteger(reader)).ToArray(); ProcessingTimes = new List(Nests); SetupTimes = new List(Nests); for (var n = 0; n < Nests; n++) { var machines = Machines[n]; var pr = new int[machines][]; for (var m = 0; m < machines; m++) { pr[m] = new int[Jobs]; for (var j = 0; j < Jobs; j++) { pr[m][j] = GetNextInteger(reader); } } ProcessingTimes.Add(pr); } for (var n = 0; n < Nests; n++) { var machines = Machines[n]; var sp = new int[machines][][]; for (var m = 0; m < machines; m++) { sp[m] = new int[Jobs][]; for (var j = 0; j < Jobs; j++) { sp[m][j] = new int[Jobs]; for (var i = 0; i < Jobs; i++) { sp[m][j][i] = GetNextInteger(reader); } } } SetupTimes.Add(sp); } reader.Close(); stream.Close(); } } private int GetNextInteger(StreamReader reader) { var builder = new StringBuilder(); int r = reader.Read(); while (r >= 0) { var c = (char)r; if ((c == ' ' || c == '\t' || c == '\r' || c == '\n') && builder.Length > 0) return int.Parse(builder.ToString()); if (c == 'N' || c == 'M') { // consume the whole line reader.ReadLine(); r = reader.Read(); continue; } if (char.IsNumber(c)) builder.Append(c); r = reader.Read(); if (r == -1 && builder.Length > 0) return int.Parse(builder.ToString()); } throw new InvalidOperationException("Stream does not contain more numbers"); } } }