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 |
|
---|
22 | using System.IO;
|
---|
23 | using System.Text;
|
---|
24 |
|
---|
25 | namespace HeuristicLab.Problems.Instances.CFSAP {
|
---|
26 | public class BozejkoCFSAPParser {
|
---|
27 | public int Jobs { get; private set; }
|
---|
28 | public int[,] ProcessingTimes { get; private set; }
|
---|
29 | public int[,,] SetupTimes { get; private set; }
|
---|
30 |
|
---|
31 | public void Parse(Stream stream) {
|
---|
32 | using (var reader = new StreamReader(stream)) {
|
---|
33 | Jobs = GetNextNumber(reader);
|
---|
34 | var seed = GetNextNumber(reader);
|
---|
35 | ProcessingTimes = new int[2, Jobs];
|
---|
36 | SetupTimes = new int[2, Jobs, Jobs];
|
---|
37 |
|
---|
38 | for (var m = 0; m < 2; m++) {
|
---|
39 | for (var j = 0; j < Jobs; j++) {
|
---|
40 | ProcessingTimes[m, j] = GetNextNumber(reader);
|
---|
41 | }
|
---|
42 | }
|
---|
43 | for (var m = 0; m < 2; m++) {
|
---|
44 | for (var j = 0; j < Jobs; j++) {
|
---|
45 | for (var i = 0; i < Jobs; i++) {
|
---|
46 | SetupTimes[m, j, i] = GetNextNumber(reader);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 | reader.Close();
|
---|
51 | stream.Close();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | private int GetNextNumber(StreamReader reader) {
|
---|
56 | var builder = new StringBuilder();
|
---|
57 | int r = reader.Read();
|
---|
58 | while (r >= 0) {
|
---|
59 | var c = (char)r;
|
---|
60 | if ((c == ' ' || c == '\t' || c == '\r' || c == '\n') && builder.Length > 0)
|
---|
61 | return int.Parse(builder.ToString());
|
---|
62 | if (char.IsNumber(c)) builder.Append(c);
|
---|
63 | r = reader.Read();
|
---|
64 | }
|
---|
65 | return -1;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|