Changeset 15281 for branches/Async/HeuristicLab.Problems.Instances.Scheduling/3.3/JSSPORLIBParser.cs
- Timestamp:
- 07/23/17 11:17:18 (7 years ago)
- Location:
- branches/Async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Async
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/Async/HeuristicLab.Problems.Instances.Scheduling/3.3/JSSPORLIBParser.cs
r12012 r15281 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.IO; 25 25 using System.Linq; 26 using System.Text; 26 27 27 28 namespace HeuristicLab.Problems.Instances.Scheduling { … … 53 54 54 55 public void Export(string file) { 55 using (Stream stream = new FileStream(file, FileMode. Open, FileAccess.Read)) {56 using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { 56 57 Export(stream); 57 58 } … … 65 66 /// </remarks> 66 67 /// <param name="stream">The stream to read data from.</param> 67 /// <returns>True if the file was successfully read or false otherwise.</returns>68 68 public void Parse(Stream stream) { 69 var reader = new StreamReader(stream);70 Name = reader.ReadLine().Trim();71 Description = reader.ReadLine().Trim();72 var delim = new char[] { ' ', '\t'};69 using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) { 70 Name = reader.ReadLine().Trim(); 71 Description = reader.ReadLine().Trim(); 72 var delim = new char[] {' ', '\t'}; 73 73 74 var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries);75 Jobs = int.Parse(info[0]);76 Resources = int.Parse(info[1]);77 ProcessingTimes = new double[Jobs, Resources];78 Demands = new int[Jobs, Resources];74 var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 75 Jobs = int.Parse(info[0]); 76 Resources = int.Parse(info[1]); 77 ProcessingTimes = new double[Jobs, Resources]; 78 Demands = new int[Jobs, Resources]; 79 79 80 for (int k = 0; k < Jobs; k++) {81 if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream.");82 var valLine = reader.ReadLine();83 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine();84 var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);85 if (vals.Length > 2 * Resources) {86 if (DueDates == null) DueDates = new double[Jobs];87 DueDates[k] = double.Parse(vals.Last(), CultureInfo.InvariantCulture.NumberFormat);88 }80 for (int k = 0; k < Jobs; k++) { 81 if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream."); 82 var valLine = reader.ReadLine(); 83 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 84 var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 85 if (vals.Length > 2 * Resources) { 86 if (DueDates == null) DueDates = new double[Jobs]; 87 DueDates[k] = double.Parse(vals.Last(), CultureInfo.InvariantCulture.NumberFormat); 88 } 89 89 90 for (int i = 0; i < Resources; i++) { 91 Demands[k, i] = int.Parse(vals[2 * i]); 92 ProcessingTimes[k, i] = double.Parse(vals[2 * i + 1], CultureInfo.InvariantCulture.NumberFormat); 90 for (int i = 0; i < Resources; i++) { 91 Demands[k, i] = int.Parse(vals[2 * i]); 92 ProcessingTimes[k, i] = double.Parse(vals[2 * i + 1], CultureInfo.InvariantCulture.NumberFormat); 93 } 93 94 } 94 95 } 95 96 96 } 97 97 98 /// <summary> 99 /// Writes to the given stream data which is expected to be in the JSSP ORLIB format. 100 /// </summary> 101 /// <remarks> 102 /// The stream is not closed or disposed. The caller has to take care of that. 103 /// </remarks> 104 /// <param name="stream">The stream to write data to.</param> 98 105 public void Export(Stream stream) { 99 var writer = new StreamWriter(stream); 100 writer.WriteLine(Name); 101 writer.WriteLine(Description); 102 writer.WriteLine(Jobs.ToString(CultureInfo.InvariantCulture.NumberFormat) + " " + Resources.ToString(CultureInfo.InvariantCulture.NumberFormat)); 103 for (int i = 0; i < Jobs; i++) { 104 for (int j = 0; j < Resources; j++) { 105 writer.Write(Demands[i, j] + " " + ProcessingTimes[i, j] + " "); 106 using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) { 107 writer.WriteLine(Name); 108 writer.WriteLine(Description); 109 writer.WriteLine(Jobs.ToString(CultureInfo.InvariantCulture.NumberFormat) + " " + Resources.ToString(CultureInfo.InvariantCulture.NumberFormat)); 110 for (int i = 0; i < Jobs; i++) { 111 for (int j = 0; j < Resources; j++) { 112 writer.Write(Demands[i, j] + " " + ProcessingTimes[i, j] + " "); 113 } 114 if (DueDates != null) writer.Write(DueDates[i].ToString("r", CultureInfo.InvariantCulture.NumberFormat)); 115 writer.WriteLine(); 106 116 } 107 if (DueDates != null) writer.Write(DueDates[i].ToString(CultureInfo.InvariantCulture.NumberFormat)); 108 writer.WriteLine(); 117 writer.Flush(); 109 118 } 110 writer.Flush();111 119 } 112 120
Note: See TracChangeset
for help on using the changeset viewer.