- Timestamp:
- 11/07/17 13:49:09 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CFSAP/HeuristicLab.Problems.Instances.CFSAP/3.3/BozejkoCFSAPParser.cs
r14757 r15456 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.IO; 25 using System.Linq; 23 26 using System.Text; 24 27 … … 26 29 public class BozejkoCFSAPParser { 27 30 public int Jobs { get; private set; } 28 public int[,] ProcessingTimes { get; private set; } 29 public int[,,] SetupTimes { get; private set; } 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; } 30 35 31 36 public void Parse(Stream stream) { 32 37 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]; 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); 37 43 38 for (var m = 0; m < 2; m++) { 39 for (var j = 0; j < Jobs; j++) { 40 ProcessingTimes[m, j] = GetNextNumber(reader); 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 } 41 52 } 53 ProcessingTimes.Add(pr); 42 54 } 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); 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 } 47 65 } 66 SetupTimes.Add(sp); 48 67 } 49 68 } … … 53 72 } 54 73 55 private int GetNext Number(StreamReader reader) {74 private int GetNextInteger(StreamReader reader) { 56 75 var builder = new StringBuilder(); 57 76 int r = reader.Read(); … … 60 79 if ((c == ' ' || c == '\t' || c == '\r' || c == '\n') && builder.Length > 0) 61 80 return int.Parse(builder.ToString()); 81 if (c == 'N' || c == 'M') { 82 // consume the whole line 83 reader.ReadLine(); 84 r = reader.Read(); 85 continue; 86 } 62 87 if (char.IsNumber(c)) builder.Append(c); 63 88 r = reader.Read(); 89 if (r == -1 && builder.Length > 0) return int.Parse(builder.ToString()); 64 90 } 65 return -1;91 throw new InvalidOperationException("Stream does not contain more numbers"); 66 92 } 67 93 }
Note: See TracChangeset
for help on using the changeset viewer.