- Timestamp:
- 01/22/18 17:15:29 (7 years ago)
- Location:
- branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PFSP/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PFSP/3.3/FSSPTAILIBInstanceProvider.cs
r15541 r15639 28 28 using System.Text.RegularExpressions; 29 29 30 namespace HeuristicLab.Problems.Instances.PFSP 31 { 32 public class FSSPTAILIBInstanceProvider : ProblemInstanceProvider<FSSPData> 30 namespace HeuristicLab.Problems.Instances.PFSP { 31 public class FSSPTAILIBInstanceProvider : ProblemInstanceProvider<FSSPData> { 32 33 public override string Name 33 34 { 35 get { return "FSSPTAI"; } 36 } 34 37 35 public override string Name 36 { 37 get { return "FSSPTAI"; } 38 public override string Description 39 { 40 get { return "Permutation Flowshop Scheduling Problems (PFSP) as defined by Taillard."; } 41 } 42 43 public override Uri WebLink 44 { 45 get { return new Uri("http://mistic.heig-vd.ch/taillard/problemes.dir/ordonnancement.dir/ordonnancement.html"); } 46 } 47 48 public override string ReferencePublication 49 { 50 get { return String.Empty; } 51 } 52 53 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 54 var instanceArchiveName = GetResourceName("FSSPTAI.zip"); 55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 56 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 58 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 59 yield return new FSSPTAILIBDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 60 } 61 } 62 } 39 63 40 public override string Description 41 { 42 get { return "Permutation Flowshop Scheduling Problems (PFSP) as defined by Taillard."; } 64 public override FSSPData LoadData(IDataDescriptor id) { 65 var descriptor = (FSSPTAILIBDataDescriptor)id; 66 var instanceArchiveName = GetResourceName("FSSPTAI.zip"); 67 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 68 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 69 70 using (var stream = entry.Open()) { 71 var parser = new FSSPTAILIBParser(); 72 parser.Parse(stream); 73 return Load(parser); 43 74 } 75 } 76 } 44 77 45 public override Uri WebLink 46 { 47 get { return new Uri("http://mistic.heig-vd.ch/taillard/problemes.dir/ordonnancement.dir/ordonnancement.html"); } 48 } 78 public override bool CanImportData 79 { 80 get { return true; } 81 } 82 public override FSSPData ImportData(string path) { 83 var parser = new FSSPTAILIBParser(); 84 parser.Parse(path); 85 return Load(parser); 86 } 49 87 50 public override string ReferencePublication 51 { 52 get { return String.Empty; } 53 } 88 private FSSPData Load(FSSPTAILIBParser parser) { 89 var instance = new FSSPData { 90 Name = parser.Name, 91 Description = parser.Description, 92 Jobs = parser.Jobs, 93 Machines = parser.Machines, 94 ProcessingTimes = parser.ProcessingTimes, 95 BestKnownSchedule = parser.BestKnownSchedule, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 54 100 55 public override IEnumerable<IDataDescriptor> GetDataDescriptors()56 57 var instanceArchiveName = GetResourceName("FSSPTAI.zip");58 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 59 105 60 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 61 { 62 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 63 { 64 yield return new FSSPTAILIBDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 65 } 66 } 67 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 68 109 69 public override FSSPData LoadData(IDataDescriptor id) 70 { 71 var descriptor = (FSSPTAILIBDataDescriptor)id; 72 var instanceArchiveName = GetResourceName("FSSPTAI.zip"); 73 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 74 { 75 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 76 77 using (var stream = entry.Open()) 78 { 79 var parser = new FSSPTAILIBParser(); 80 parser.Parse(stream); 81 return Load(parser); 82 } 83 } 84 } 85 86 public override bool CanImportData 87 { 88 get { return true; } 89 } 90 public override FSSPData ImportData(string path) 91 { 92 var parser = new FSSPTAILIBParser(); 93 parser.Parse(path); 94 return Load(parser); 95 } 96 97 private FSSPData Load(FSSPTAILIBParser parser) 98 { 99 var instance = new FSSPData 100 { 101 Name = parser.Name, 102 Description = parser.Description, 103 Jobs = parser.Jobs, 104 Machines = parser.Machines, 105 ProcessingTimes = parser.ProcessingTimes, 106 BestKnownSchedule = parser.BestKnownSchedule, 107 BestKnownQuality = parser.BestKnownQuality 108 }; 109 return instance; 110 } 111 112 public override bool CanExportData 113 { 114 get { return false; } 115 } 116 117 private string GetDescription() 118 { 119 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 120 } 121 122 protected virtual string GetResourceName(string fileName) 123 { 124 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 125 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 126 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 127 113 } 114 } 128 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PFSP/3.3/FSSPTAILIBParser.cs
r15541 r15639 26 26 using System.Text; 27 27 28 namespace HeuristicLab.Problems.Instances.PFSP 29 { 30 public class FSSPTAILIBParser 31 { 32 public string Name { get; set; } 33 public string Description { get; set; } 34 public int Jobs { get; set; } 35 public int Machines { get; set; } 36 public double[,] ProcessingTimes { get; set; } 28 namespace HeuristicLab.Problems.Instances.PFSP { 29 public class FSSPTAILIBParser { 30 public string Name { get; set; } 31 public string Description { get; set; } 32 public int Jobs { get; set; } 33 public int Machines { get; set; } 34 public double[,] ProcessingTimes { get; set; } 37 35 38 39 36 public int[] BestKnownSchedule { get; set; } 37 public int BestKnownQuality { get; set; } 40 38 41 public FSSPTAILIBParser() 42 { 43 Reset(); 39 public FSSPTAILIBParser() { 40 Reset(); 41 } 42 43 public void Reset() { 44 Name = Description = String.Empty; 45 Jobs = Machines = BestKnownQuality = 0; 46 ProcessingTimes = null; 47 BestKnownSchedule = null; 48 } 49 50 public void Parse(string file) { 51 using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { 52 Parse(stream); 53 } 54 } 55 56 public void Export(string file) { 57 using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { 58 Export(stream); 59 } 60 } 61 62 public void Parse(Stream stream) { 63 using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) { 64 Name = reader.ReadLine().Trim(); 65 Description = reader.ReadLine().Trim(); 66 var delim = new char[] { ' ', '\t' }; 67 68 var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 69 Jobs = int.Parse(info[0]); 70 Machines = int.Parse(info[1]); 71 var bestKnownQuality = reader.ReadLine().Trim(); 72 BestKnownQuality = int.Parse(bestKnownQuality); 73 ProcessingTimes = new double[Machines, Jobs]; 74 75 for (int k = 0; k < Machines; k++) { 76 if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream."); 77 var valLine = reader.ReadLine(); 78 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 79 var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 80 81 82 for (int i = 0; i < Jobs; i++) { 83 ProcessingTimes[k, i] = double.Parse(vals[i], CultureInfo.InvariantCulture.NumberFormat); 84 } 44 85 } 45 86 46 public void Reset() 47 { 48 Name = Description = String.Empty; 49 Jobs = Machines = BestKnownQuality = 0; 50 ProcessingTimes = null; 51 BestKnownSchedule = null; 87 while (!reader.EndOfStream) { 88 var vals = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 89 if (vals.Count() == Jobs) { BestKnownSchedule = vals.Select(val => Int32.Parse(val)).ToArray(); } 90 } 91 } 92 } 93 94 public void Export(Stream stream) { 95 using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) { 96 writer.WriteLine(Name); 97 writer.WriteLine(Description); 98 writer.WriteLine(Jobs + '\t' + Machines); 99 writer.WriteLine(BestKnownQuality); 100 101 for (int k = 0; k < Machines; k++) { 102 for (int i = 0; i < Jobs; i++) { 103 writer.Write(ProcessingTimes[k, i] + "\t"); 104 } 105 writer.WriteLine(); 52 106 } 53 107 54 public void Parse(string file) 55 { 56 using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) 57 { 58 Parse(stream); 59 } 108 if (BestKnownSchedule != null) { 109 writer.WriteLine(BestKnownSchedule); 60 110 } 61 62 public void Export(string file) 63 { 64 using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) 65 { 66 Export(stream); 67 } 68 } 69 70 public void Parse(Stream stream) 71 { 72 using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) 73 { 74 Name = reader.ReadLine().Trim(); 75 Description = reader.ReadLine().Trim(); 76 var delim = new char[] { ' ', '\t' }; 77 78 var info = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 79 Jobs = int.Parse(info[0]); 80 Machines = int.Parse(info[1]); 81 var bestKnownQuality = reader.ReadLine().Trim(); 82 BestKnownQuality = int.Parse(bestKnownQuality); 83 ProcessingTimes = new double[Machines, Jobs]; 84 85 for (int k = 0; k < Machines; k++) 86 { 87 if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream."); 88 var valLine = reader.ReadLine(); 89 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 90 var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 91 92 93 for (int i = 0; i < Jobs; i++) 94 { 95 ProcessingTimes[k, i] = double.Parse(vals[i], CultureInfo.InvariantCulture.NumberFormat); 96 } 97 } 98 99 while (!reader.EndOfStream) 100 { 101 var vals = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 102 if (vals.Count() == Jobs) { BestKnownSchedule = vals.Select(val => Int32.Parse(val)).ToArray(); } 103 } 104 } 105 } 106 107 public void Export(Stream stream) 108 { 109 using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) 110 { 111 writer.WriteLine(Name); 112 writer.WriteLine(Description); 113 writer.WriteLine(Jobs + '\t' + Machines); 114 writer.WriteLine(BestKnownQuality); 115 116 for (int k = 0; k < Machines; k++) 117 { 118 for (int i = 0; i < Jobs; i++) 119 { 120 writer.Write(ProcessingTimes[k, i] + "\t"); 121 } 122 writer.WriteLine(); 123 } 124 125 if (BestKnownSchedule != null) { 126 writer.WriteLine(BestKnownSchedule); 127 } 128 writer.Flush(); 129 } 130 } 111 writer.Flush(); 112 } 131 113 } 114 } 132 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PFSP/3.3/Properties/AssemblyInfo.cs
r15541 r15639 55 55 // [assembly: AssemblyVersion("1.0.*")] 56 56 [assembly: AssemblyVersion("3.3.0.0")] 57 [assembly: AssemblyFileVersion("3.3.14.155 21")]57 [assembly: AssemblyFileVersion("3.3.14.15541")]
Note: See TracChangeset
for help on using the changeset viewer.