Changeset 14506
- Timestamp:
- 12/20/16 10:53:51 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.Instances.Scheduling/3.3/JSSPORLIBInstanceProvider.cs
r14185 r14506 67 67 var parser = new JSSPORLIBParser(); 68 68 parser.Parse(stream); 69 var instance = Load(parser); 70 instance.Name = id.Name; 71 instance.Description = id.Description; 72 73 return instance; 69 return Load(parser); 74 70 } 75 71 } … … 82 78 var parser = new JSSPORLIBParser(); 83 79 parser.Parse(path); 84 var instance = Load(parser); 85 instance.Name = Path.GetFileName(path); 86 instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString(); 87 return instance; 80 return Load(parser); 88 81 } 89 82 90 83 private JSSPData Load(JSSPORLIBParser parser) { 91 84 var instance = new JSSPData { 85 Name = parser.Name, 86 Description = parser.Description, 92 87 Jobs = parser.Jobs, 93 88 Resources = parser.Resources, -
trunk/sources/HeuristicLab.Problems.Instances.Scheduling/3.3/JSSPORLIBParser.cs
r14185 r14506 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.ReadWrite)) { 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 -
trunk/sources/HeuristicLab.Problems.Scheduling/3.3/JobShopSchedulingProblem.cs
r14185 r14506 225 225 BestKnownQuality = new DoubleValue(MakespanEvaluator.GetMakespan(BestKnownSolution)); 226 226 } 227 227 Name = data.Name; 228 Description = data.Description; 228 229 JobData = jobData; 229 230 Jobs = data.Jobs;
Note: See TracChangeset
for help on using the changeset viewer.