#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.IO; using System.Text; namespace HeuristicLab.Problems.Instances.CFSAP { public class BozejkoCFSAPParser { public int Jobs { get; private set; } public int[,] ProcessingTimes { get; private set; } public int[,,] SetupTimes { get; private set; } public void Parse(Stream stream) { using (var reader = new StreamReader(stream)) { Jobs = GetNextNumber(reader); var seed = GetNextNumber(reader); ProcessingTimes = new int[2, Jobs]; SetupTimes = new int[2, Jobs, Jobs]; for (var m = 0; m < 2; m++) { for (var j = 0; j < Jobs; j++) { ProcessingTimes[m, j] = GetNextNumber(reader); } } for (var m = 0; m < 2; m++) { for (var j = 0; j < Jobs; j++) { for (var i = 0; i < Jobs; i++) { SetupTimes[m, j, i] = GetNextNumber(reader); } } } reader.Close(); stream.Close(); } } private int GetNextNumber(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 (char.IsNumber(c)) builder.Append(c); r = reader.Read(); } return -1; } } }