Changeset 15639
- Timestamp:
- 01/22/18 17:15:29 (7 years ago)
- Location:
- branches/2864_PermutationProblems
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPDataDescriptor.cs
r15541 r15639 22 22 using HeuristicLab.Problems.Instances; 23 23 24 namespace HeuristicLab.Problems.Instances.LinearOrdering 25 { 26 internal class LOPDataDescriptor : IDataDescriptor 27 { 28 public string Name { get; internal set; } 29 public string Description { get; internal set; } 24 namespace HeuristicLab.Problems.Instances.LinearOrdering { 25 internal class LOPDataDescriptor : IDataDescriptor { 26 public string Name { get; internal set; } 27 public string Description { get; internal set; } 30 28 31 32 29 internal string InstanceIdentifier { get; set; } 30 internal string SolutionIdentifier { get; set; } 33 31 34 internal LOPDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier) 35 { 36 this.Name = name; 37 this.Description = description; 38 this.InstanceIdentifier = instanceIdentifier; 39 this.SolutionIdentifier = solutionIdentifier; 40 } 32 internal LOPDataDescriptor(string name, string description, string instanceIdentifier, string solutionIdentifier) { 33 this.Name = name; 34 this.Description = description; 35 this.InstanceIdentifier = instanceIdentifier; 36 this.SolutionIdentifier = solutionIdentifier; 41 37 } 38 } 42 39 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPIOInstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPIOInstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPIOInstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "IO"; } 37 } 35 38 36 public override string Name { 37 get { return "IO"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems IO test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/IO.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("IO.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems IO test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("IO.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/IO.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 47 83 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 84 public override LOPData ImportData(string path) { 85 var parser = new LOPParser(); 86 parser.Parse(path); 87 return Load(parser); 88 } 51 89 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors() 53 { 54 var instanceArchiveName = GetResourceName("IO.zip"); 55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 90 private LOPData Load(LOPParser parser) { 91 var instance = new LOPData { 92 Name = parser.Name, 93 Description = parser.Description, 94 Dimension = parser.Dimension, 95 Matrix = parser.Matrix, 96 BestKnownPermutation = parser.BestKnownPermutation, 97 BestKnownQuality = parser.BestKnownQuality 98 }; 99 return instance; 100 } 56 101 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 102 public override bool CanExportData 103 { 104 get { return false; } 105 } 65 106 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("IO.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 107 private string GetDescription() { 108 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 109 } 73 110 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 87 public override LOPData ImportData(string path) 88 { 89 var parser = new LOPParser(); 90 parser.Parse(path); 91 return Load(parser); 92 } 93 94 private LOPData Load(LOPParser parser) 95 { 96 var instance = new LOPData 97 { 98 Name = parser.Name, 99 Description = parser.Description, 100 Dimension = parser.Dimension, 101 Matrix = parser.Matrix, 102 BestKnownPermutation = parser.BestKnownPermutation, 103 BestKnownQuality = parser.BestKnownQuality 104 }; 105 return instance; 106 } 107 108 public override bool CanExportData { 109 get { return false; } 110 } 111 112 private string GetDescription() 113 { 114 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 115 } 116 117 protected virtual string GetResourceName(string fileName) 118 { 119 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 120 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 } 111 protected virtual string GetResourceName(string fileName) { 112 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 113 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 122 114 } 115 } 123 116 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPMBInstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPMBInstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPMBInstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "MB"; } 37 } 35 38 36 public override string Name { 37 get { return "MB"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems MB test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/MB.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("MB.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems MB test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("MB.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/MB.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("MB.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("MB.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPParser.cs
r15541 r15639 26 26 using System.Text; 27 27 28 namespace HeuristicLab.Problems.Instances.LinearOrdering 29 { 30 public class LOPParser 31 { 32 public string Name { get; set; } 33 public string Description { get; set; } 34 public int Dimension { get; set; } 35 public double[,] Matrix { get; set; } 36 public int[] BestKnownPermutation { get; set; } 37 public double? BestKnownQuality { get; set; } 28 namespace HeuristicLab.Problems.Instances.LinearOrdering { 29 public class LOPParser { 30 public string Name { get; set; } 31 public string Description { get; set; } 32 public int Dimension { get; set; } 33 public double[,] Matrix { get; set; } 34 public int[] BestKnownPermutation { get; set; } 35 public double? BestKnownQuality { get; set; } 38 36 39 public LOPParser() 40 { 41 Reset(); 37 public LOPParser() { 38 Reset(); 39 } 40 41 public void Reset() { 42 Name = Description = String.Empty; 43 Dimension = 0; 44 BestKnownQuality = 0; 45 Matrix = null; 46 BestKnownPermutation = null; 47 } 48 49 public void Parse(string file) { 50 using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) { 51 Parse(stream); 52 } 53 } 54 55 public void Export(string file) { 56 using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) { 57 Export(stream); 58 } 59 } 60 61 public void Parse(Stream stream) { 62 using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) { 63 Name = reader.ReadLine().Trim(); 64 Description = reader.ReadLine().Trim(); 65 BestKnownQuality = double.Parse(reader.ReadLine().Trim()); 66 var delim = new char[] { ' ', '\t' }; 67 68 Dimension = int.Parse(reader.ReadLine().Trim()); 69 Matrix = new double[Dimension, Dimension]; 70 71 for (int k = 0; k < Dimension; k++) { 72 if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream."); 73 var valLine = reader.ReadLine(); 74 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 75 var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 76 77 78 for (int i = 0; i < Dimension; i++) { 79 Matrix[k, i] = double.Parse(vals[i], CultureInfo.InvariantCulture.NumberFormat); 80 } 42 81 } 43 82 44 public void Reset() 45 { 46 Name = Description = String.Empty; 47 Dimension = 0; 48 BestKnownQuality = 0; 49 Matrix = null; 50 BestKnownPermutation = null; 83 while (!reader.EndOfStream) { 84 var vals = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 85 if (vals.Count() == Dimension) { BestKnownPermutation = vals.Select(val => Int32.Parse(val)).ToArray(); } 86 } 87 } 88 } 89 90 public void Export(Stream stream) { 91 using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) { 92 writer.WriteLine(Name); 93 writer.WriteLine(Description); 94 writer.WriteLine(BestKnownQuality); 95 writer.WriteLine(Dimension); 96 97 for (int k = 0; k < Dimension; k++) { 98 for (int i = 0; i < Dimension; i++) { 99 writer.Write(Matrix[k, i] + '\t'); 100 } 101 writer.WriteLine(); 51 102 } 52 103 53 public void Parse(string file) 54 { 55 using (Stream stream = new FileStream(file, FileMode.Open, FileAccess.Read)) 56 { 57 Parse(stream); 58 } 104 if (BestKnownPermutation != null) { 105 writer.WriteLine(BestKnownPermutation); 59 106 } 60 61 public void Export(string file) 62 { 63 using (Stream stream = new FileStream(file, FileMode.Create, FileAccess.Write)) 64 { 65 Export(stream); 66 } 67 } 68 69 public void Parse(Stream stream) 70 { 71 using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4092, true)) 72 { 73 Name = reader.ReadLine().Trim(); 74 Description = reader.ReadLine().Trim(); 75 BestKnownQuality = double.Parse(reader.ReadLine().Trim()); 76 var delim = new char[] { ' ', '\t' }; 77 78 Dimension = int.Parse(reader.ReadLine().Trim()); 79 Matrix = new double[Dimension, Dimension]; 80 81 for (int k = 0; k < Dimension; k++) 82 { 83 if (reader.EndOfStream) throw new InvalidDataException("Unexpected End of Stream."); 84 var valLine = reader.ReadLine(); 85 while (String.IsNullOrWhiteSpace(valLine)) valLine = reader.ReadLine(); 86 var vals = valLine.Split(delim, StringSplitOptions.RemoveEmptyEntries); 87 88 89 for (int i = 0; i < Dimension; i++) 90 { 91 Matrix[k, i] = double.Parse(vals[i], CultureInfo.InvariantCulture.NumberFormat); 92 } 93 } 94 95 while (!reader.EndOfStream) 96 { 97 var vals = reader.ReadLine().Split(delim, StringSplitOptions.RemoveEmptyEntries); 98 if (vals.Count() == Dimension) { BestKnownPermutation = vals.Select(val => Int32.Parse(val)).ToArray(); } 99 } 100 } 101 } 102 103 public void Export(Stream stream) 104 { 105 using (var writer = new StreamWriter(stream, Encoding.UTF8, 4092, true)) 106 { 107 writer.WriteLine(Name); 108 writer.WriteLine(Description); 109 writer.WriteLine(BestKnownQuality); 110 writer.WriteLine(Dimension); 111 112 for (int k = 0; k < Dimension; k++) 113 { 114 for (int i = 0; i < Dimension; i++) 115 { 116 writer.Write(Matrix[k, i] + '\t'); 117 } 118 writer.WriteLine(); 119 } 120 121 if (BestKnownPermutation != null) { 122 writer.WriteLine(BestKnownPermutation); 123 } 124 writer.Flush(); 125 } 126 } 107 writer.Flush(); 108 } 127 109 } 110 } 128 111 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPRANDA1InstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPRANDA1InstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPRANDA1InstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "RANDA1"; } 37 } 35 38 36 public override string Name { 37 get { return "RANDA1"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems RANDA1 test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/RANDA1.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("RANDA1.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems RANDA1 test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("RANDA1.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/RANDA1.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("RANDA1.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("RANDA1.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPRANDA2InstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPRANDA2InstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPRANDA2InstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "RANDA2"; } 37 } 35 38 36 public override string Name { 37 get { return "RANDA2"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems RANDA2 test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/RANDA2.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("RANDA2.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems RANDA2 test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("RANDA2.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/RANDA2.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("RANDA2.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("RANDA2.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPRANDBInstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPRANDBInstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPRANDBInstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "RANDB"; } 37 } 35 38 36 public override string Name { 37 get { return "RANDB"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems RANDB test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/RANDB.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("RANDB.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems RANDB test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("RANDB.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/RANDB.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("RANDB.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("RANDB.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPSGBInstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPSGBInstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPSGBInstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "SGB"; } 37 } 35 38 36 public override string Name { 37 get { return "SGB"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems SGB test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/SGB.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("SGB.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems SGB test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("SGB.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/SGB.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("SGB.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("SGB.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPSPECInstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPSPECInstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPSPECInstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "SPEC"; } 37 } 35 38 36 public override string Name { 37 get { return "SPEC"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems SPEC test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/SPEC.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("SPEC.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems SPEC test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("SPEC.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/SPEC.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("SPEC.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("SPEC.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/3.3/LOPXLOLIBInstanceProvider.cs
r15541 r15639 29 29 using System.Text.RegularExpressions; 30 30 31 namespace HeuristicLab.Problems.Instances.LinearOrdering 32 { 33 public class LOPXLOLIBInstanceProvider : ProblemInstanceProvider<LOPData> 31 namespace HeuristicLab.Problems.Instances.LinearOrdering { 32 public class LOPXLOLIBInstanceProvider : ProblemInstanceProvider<LOPData> { 33 34 public override string Name 34 35 { 36 get { return "XLOLIB"; } 37 } 35 38 36 public override string Name { 37 get { return "XLOLIB"; } 39 public override string Description 40 { 41 get { return "Linear Ordering Problems XLOLIB test instances"; } 42 } 43 44 public override Uri WebLink 45 { 46 get { return new Uri("http://www.optsicom.es/lolib/lop/XLOLIB.zip"); } 47 } 48 49 public override string ReferencePublication 50 { 51 get { return String.Empty; } 52 } 53 54 public override IEnumerable<IDataDescriptor> GetDataDescriptors() { 55 var instanceArchiveName = GetResourceName("XLOLIB.zip"); 56 if (String.IsNullOrEmpty(instanceArchiveName)) yield break; 57 58 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) { 60 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 38 61 } 62 } 63 } 39 64 40 public override string Description { 41 get { return "Linear Ordering Problems XLOLIB test instances"; } 65 public override LOPData LoadData(IDataDescriptor id) { 66 var descriptor = (LOPDataDescriptor)id; 67 var instanceArchiveName = GetResourceName("XLOLIB.zip"); 68 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) { 69 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 70 71 using (var stream = entry.Open()) { 72 var parser = new LOPParser(); 73 parser.Parse(stream); 74 return Load(parser); 42 75 } 76 } 77 } 43 78 44 public override Uri WebLink { 45 get { return new Uri("http://www.optsicom.es/lolib/lop/XLOLIB.zip"); } 46 } 79 public override bool CanImportData 80 { 81 get { return true; } 82 } 83 public override LOPData ImportData(string path) { 84 var parser = new LOPParser(); 85 parser.Parse(path); 86 return Load(parser); 87 } 47 88 48 public override string ReferencePublication { 49 get { return String.Empty; } 50 } 89 private LOPData Load(LOPParser parser) { 90 var instance = new LOPData { 91 Name = parser.Name, 92 Description = parser.Description, 93 Dimension = parser.Dimension, 94 Matrix = parser.Matrix, 95 BestKnownPermutation = parser.BestKnownPermutation, 96 BestKnownQuality = parser.BestKnownQuality 97 }; 98 return instance; 99 } 51 100 52 public override IEnumerable<IDataDescriptor> GetDataDescriptors()53 54 var instanceArchiveName = GetResourceName("XLOLIB.zip");55 if (String.IsNullOrEmpty(instanceArchiveName)) yield break;101 public override bool CanExportData 102 { 103 get { return false; } 104 } 56 105 57 using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 58 { 59 foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) 60 { 61 yield return new LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null); 62 } 63 } 64 } 106 private string GetDescription() { 107 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 108 } 65 109 66 public override LOPData LoadData(IDataDescriptor id) 67 { 68 var descriptor = (LOPDataDescriptor)id; 69 var instanceArchiveName = GetResourceName("XLOLIB.zip"); 70 using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) 71 { 72 var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier); 73 74 using (var stream = entry.Open()) 75 { 76 var parser = new LOPParser(); 77 parser.Parse(stream); 78 return Load(parser); 79 } 80 } 81 } 82 83 public override bool CanImportData { 84 get { return true; } 85 } 86 public override LOPData ImportData(string path) 87 { 88 var parser = new LOPParser(); 89 parser.Parse(path); 90 return Load(parser); 91 } 92 93 private LOPData Load(LOPParser parser) 94 { 95 var instance = new LOPData 96 { 97 Name = parser.Name, 98 Description = parser.Description, 99 Dimension = parser.Dimension, 100 Matrix = parser.Matrix, 101 BestKnownPermutation = parser.BestKnownPermutation, 102 BestKnownQuality = parser.BestKnownQuality 103 }; 104 return instance; 105 } 106 107 public override bool CanExportData { 108 get { return false; } 109 } 110 111 private string GetDescription() 112 { 113 return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + "."; 114 } 115 116 protected virtual string GetResourceName(string fileName) 117 { 118 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 119 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 120 } 110 protected virtual string GetResourceName(string fileName) { 111 return Assembly.GetExecutingAssembly().GetManifestResourceNames() 112 .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success); 121 113 } 114 } 122 115 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.LinearOrdering/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. 0")]57 [assembly: AssemblyFileVersion("3.3.14.15541")] -
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")] -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances/3.3/Plugin.cs
r15541 r15639 23 23 24 24 namespace HeuristicLab.Problems.Instances { 25 [Plugin("HeuristicLab.Problems.Instances", "3.3.14. 0")]25 [Plugin("HeuristicLab.Problems.Instances", "3.3.14.15541")] 26 26 [PluginFile("HeuristicLab.Problems.Instances-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Common", "3.3")] -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances/3.3/ProblemInstanceProvider.cs
r15541 r15639 34 34 public abstract TData LoadData(IDataDescriptor descriptor); 35 35 36 public virtual bool CanImportData { 36 public virtual bool CanImportData 37 { 37 38 get { return false; } 38 39 } … … 41 42 } 42 43 43 public virtual bool CanExportData { 44 public virtual bool CanExportData 45 { 44 46 get { return false; } 45 47 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances/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. 0")]57 [assembly: AssemblyFileVersion("3.3.14.15541")] -
branches/2864_PermutationProblems/HeuristicLab.Problems.LinearOrdering/3.3/HeuristicLab.Problems.LinearOrdering-3.3.csproj
r15541 r15639 88 88 </ItemGroup> 89 89 <ItemGroup> 90 <Compile Include="Evaluators\SuperdiagonalMatrixTriangulationEvaluator.cs" />91 <Compile Include="Evaluators\MatrixTriangulationEvaluator.cs" />92 <Compile Include="Evaluators\LOPEvaluator.cs" />93 <Compile Include="Interfaces\IMatrixTriangulationEvaluator.cs" />94 <Compile Include="Interfaces\ILOPEvaluator.cs" />95 90 <Compile Include="LinearOrderingProblem.cs" /> 96 91 <Compile Include="Plugin.cs" /> -
branches/2864_PermutationProblems/HeuristicLab.Problems.LinearOrdering/3.3/LinearOrderingProblem.cs
r15541 r15639 34 34 using HeuristicLab.Problems.Instances; 35 35 36 namespace HeuristicLab.Problems.LinearOrdering 37 { 38 [Item("Linear Ordering Problem (LOP)", "Represents a Linear Ordering Problem")] 39 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 999)] 40 [StorableClass] 41 public sealed class LinearOrderingProblem : SingleObjectiveHeuristicOptimizationProblem<ILOPEvaluator, IPermutationCreator>, IProblemInstanceConsumer<LOPData>, IProblemInstanceExporter<LOPData>, IStorableContent 42 { 43 #region Default Instance 44 private static readonly LOPData DefaultInstance = new LOPData() 45 { 46 Name = "Linaer Ordering Problem (LOP)", 47 Description = "The default instance of the LOP in HeuristicLab", 48 Dimension = 4, 49 Matrix = new double[,] { 36 namespace HeuristicLab.Problems.LinearOrdering { 37 [Item("Linear Ordering Problem (LOP)", "Represents a Linear Ordering Problem")] 38 [Creatable(CreatableAttribute.Categories.CombinatorialProblems)] 39 [StorableClass] 40 public sealed class LinearOrderingProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IProblemInstanceConsumer<LOPData>, IProblemInstanceExporter<LOPData>, IStorableContent { 41 #region Fields 42 private static readonly LOPData DefaultInstance = new LOPData() { 43 Name = "Linaer Ordering Problem (LOP)", 44 Description = "The default instance of the LOP in HeuristicLab", 45 Dimension = 4, 46 Matrix = new double[,] { 50 47 {0 ,3, 6 ,6}, 51 48 {2 ,0, 8 ,4}, … … 53 50 {5 ,3, 8 ,0} 54 51 } 55 }; 56 #endregion 52 }; 53 public event EventHandler BestKnownSolutionChanged; 54 #endregion 57 55 58 public string Filename { get; set; } 56 #region Getter/Setter 57 public OptionalValueParameter<Permutation> BestKnownSolutionParameter 58 { 59 get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; } 60 } 61 public OptionalValueParameter<DoubleMatrix> MatrixParameter 62 { 63 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Matrix"]; } 64 } 65 public Permutation BestKnownSolution 66 { 67 get { return BestKnownSolutionParameter.Value; } 68 set 69 { 70 BestKnownSolutionParameter.Value = value; 71 if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); } 72 } 73 } 74 public DoubleMatrix Matrix 75 { 76 get { return MatrixParameter.Value; } 77 set { MatrixParameter.Value = value; } 78 } 59 79 60 #region Parameter Properties 61 public OptionalValueParameter<Permutation> BestKnownSolutionParameter 62 { 63 get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; } 80 public override bool Maximization { get { return true; } } 81 #endregion 82 83 #region Ctor 84 [StorableConstructor] 85 private LinearOrderingProblem(bool deserializing) : base(deserializing) { } 86 private LinearOrderingProblem(LinearOrderingProblem original, Cloner cloner) : base(original, cloner) { } 87 public LinearOrderingProblem() { 88 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this LOP instance.")); 89 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Matrix", "The matrix which contains the corresponding LOP-values")); 90 91 Load(DefaultInstance); 92 EvaluatorParameter.GetsCollected = false; 93 EvaluatorParameter.Hidden = true; 94 95 Evaluator.QualityParameter.ActualName = "SuperDiagonale"; 96 } 97 #endregion 98 99 #region Methods 100 101 public override IDeepCloneable Clone(Cloner cloner) { 102 return new LinearOrderingProblem(this, cloner); 103 } 104 105 public void Load(LOPData data) { 106 if (data.BestKnownQuality.HasValue) { 107 BestKnownQuality = data.BestKnownQuality.Value; 108 } 109 Name = data.Name; 110 Description = data.Description; 111 Matrix = new DoubleMatrix(data.Matrix); 112 Encoding.Length = Matrix.Columns; 113 114 if (data.BestKnownPermutation != null) { 115 int[] permut = data.BestKnownPermutation; 116 //Clean up if the first index = 1 117 if (!permut.Contains(0)) { permut = permut.Select(v => v - 1).ToArray(); } 118 119 BestKnownSolution = new Permutation(PermutationTypes.Absolute, data.BestKnownPermutation); 120 BestKnownQuality = Evaluate(permut, Matrix); 121 } 122 } 123 124 public LOPData Export() { 125 var result = new LOPData { 126 Name = Name, 127 Description = Description, 128 BestKnownQuality = BestKnownQuality, 129 BestKnownPermutation = BestKnownSolution.ToArray(), 130 Dimension = Matrix.Rows, 131 Matrix = Matrix.CloneAsMatrix() 132 }; 133 134 return result; 135 } 136 137 public override double Evaluate(Individual individual, IRandom random) { 138 return Evaluate(individual.Permutation().ToArray(), Matrix); 139 } 140 141 #endregion 142 143 #region Helper Methods 144 private void OnBestKnownSolutionChanged() { 145 BestKnownSolutionChanged?.Invoke(this, EventArgs.Empty); 146 } 147 148 private double Evaluate(int[] permutation, DoubleMatrix matrix) { 149 double sum = 0; 150 for (int i = 1; i < matrix.Columns; i++) { 151 for (int j = 0; j < i; j++) { 152 sum += matrix[permutation[j], permutation[i]]; 64 153 } 154 } 65 155 66 public OptionalValueParameter<DoubleMatrix> MatrixParameter 67 { 68 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Matrix"]; } 69 } 70 #endregion 71 72 #region Properties 73 public Permutation BestKnownSolution 74 { 75 get { return BestKnownSolutionParameter.Value; } 76 set 77 { 78 BestKnownSolutionParameter.Value = value; 79 if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); } 80 } 81 } 82 public DoubleMatrix Matrix 83 { 84 get { return MatrixParameter.Value; } 85 set { MatrixParameter.Value = value; } 86 } 87 #endregion 88 89 public event EventHandler BestKnownSolutionChanged; 90 private void OnBestKnownSolutionChanged() 91 { 92 var changed = BestKnownSolutionChanged; 93 if (changed != null) 94 changed(this, EventArgs.Empty); 95 } 96 97 // BackwardsCompatibility3.3 98 #region Backwards compatible code, remove with 3.4 99 [Obsolete] 100 [Storable(Name = "operators")] 101 private IEnumerable<IOperator> oldOperators 102 { 103 get { return null; } 104 set 105 { 106 if (value != null && value.Any()) 107 Operators.AddRange(value); 108 } 109 } 110 #endregion 111 112 [StorableConstructor] 113 private LinearOrderingProblem(bool deserializing) : base(deserializing) { } 114 private LinearOrderingProblem(LinearOrderingProblem original, Cloner cloner) 115 : base(original, cloner) 116 { 117 } 118 public LinearOrderingProblem() 119 : base(new SuperdiagonalMatrixTriangulationEvaluator(), new RandomPermutationCreator()) 120 { 121 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this LOP instance.")); 122 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Matrix", "The matrix which contains the corresponding LOP-values")); 123 124 Load(DefaultInstance); 125 EvaluatorParameter.GetsCollected = false; 126 EvaluatorParameter.Hidden = true; 127 128 Maximization.Value = true; 129 MaximizationParameter.Hidden = true; 130 131 SolutionCreator.PermutationParameter.ActualName = "LOPOrder"; 132 Evaluator.QualityParameter.ActualName = "SuperDiagonale"; 133 ParameterizeSolutionCreator(); 134 ParameterizeEvaluator(); 135 136 InitializeOperators(); 137 } 138 139 public override IDeepCloneable Clone(Cloner cloner) 140 { 141 return new LinearOrderingProblem(this, cloner); 142 } 143 144 [StorableHook(HookType.AfterDeserialization)] 145 private void AfterDeserialization() 146 { 147 } 148 149 #region Problem Instance Handling 150 public void Load(LOPData data) 151 { 152 BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 153 Name = data.Name; 154 Description = data.Description; 155 Matrix = new DoubleMatrix(data.Matrix); 156 157 if (data.BestKnownPermutation != null) 158 { 159 int[] permut = data.BestKnownPermutation; 160 //Clean up if the first index = 1 161 if (!permut.Contains(0)) { permut = permut.Select(v => v - 1).ToArray(); } 162 double bestKnownQuality = MatrixTriangulationEvaluator.Apply( 163 new SuperdiagonalMatrixTriangulationEvaluator(), 164 new DoubleMatrix(data.Matrix), 165 new Permutation(PermutationTypes.Absolute, permut) 166 ); 167 168 BestKnownSolution = new Permutation(PermutationTypes.Absolute, data.BestKnownPermutation); 169 BestKnownQuality = new DoubleValue(bestKnownQuality); 170 } 171 172 ParameterizeSolutionCreator(); 173 } 174 175 public LOPData Export() 176 { 177 var result = new LOPData 178 { 179 Name = Name, 180 Description = Description, 181 BestKnownQuality = BestKnownQuality.Value, 182 BestKnownPermutation = BestKnownSolution.ToArray(), 183 Dimension = Matrix.Rows, 184 Matrix = Matrix.CloneAsMatrix() 185 }; 186 187 return result; 188 } 189 #endregion 190 191 #region Helpers 192 private void InitializeOperators() 193 { 194 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>()); 195 ParameterizeOperators(); 196 UpdateMoveEvaluators(); 197 } 198 199 200 private void ParameterizeOperators() 201 { 202 foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) 203 { 204 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 205 op.ParentsParameter.Hidden = true; 206 op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 207 op.ChildParameter.Hidden = true; 208 } 209 foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) 210 { 211 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 212 op.PermutationParameter.Hidden = true; 213 } 214 foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) 215 { 216 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 217 op.PermutationParameter.Hidden = true; 218 } 219 foreach (IPermutationMultiNeighborhoodShakingOperator op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 220 { 221 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 222 op.PermutationParameter.Hidden = true; 223 } 224 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) 225 { 226 op.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 227 op.SolutionParameter.Hidden = true; 228 } 229 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) 230 { 231 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 232 op.ParentsParameter.Hidden = true; 233 } 234 foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>()) 235 { 236 op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName; 237 op.QualityVariableName = Evaluator.QualityParameter.ActualName; 238 } 239 } 240 #endregion 241 242 private void UpdateMoveEvaluators() 243 { 244 ParameterizeOperators(); 245 OnOperatorsChanged(); 246 } 247 248 private void ParameterizeSolutionCreator() 249 { 250 SolutionCreator.LengthParameter.Value = new IntValue(Matrix.Columns); 251 252 SolutionCreator.LengthParameter.Hidden = SolutionCreator.LengthParameter.Value != null; 253 SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected); 254 SolutionCreator.PermutationTypeParameter.Hidden = true; 255 } 256 private void ParameterizeEvaluator() 257 { 258 if (Evaluator is IMatrixTriangulationEvaluator) 259 { 260 IMatrixTriangulationEvaluator evaluator = (IMatrixTriangulationEvaluator)Evaluator; 261 evaluator.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 262 evaluator.PermutationParameter.Hidden = true; 263 } 264 } 156 return sum; 265 157 } 158 #endregion 159 } 266 160 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.LinearOrdering/3.3/Properties/AssemblyInfo.cs
r15541 r15639 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3.14.155 21")]56 [assembly: AssemblyFileVersion("3.3.14.15541")] 57 57 -
branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP.Views/3.3/JobShopSchedulingProblemView.cs
r15541 r15639 29 29 using System.Linq; 30 30 31 namespace HeuristicLab.Problems.PFSP.Views 32 { 33 [View("Permutation Flowshop Scheduling Problem View")] 34 [Content(typeof(PermutationFlowshopSchedulingProblem), true)] 35 public partial class JobShopSchedulingProblemView : ProblemView 31 namespace HeuristicLab.Problems.PFSP.Views { 32 [View("Permutation Flowshop Scheduling Problem View")] 33 [Content(typeof(PermutationFlowshopSchedulingProblem), true)] 34 public partial class JobShopSchedulingProblemView : ProblemView { 35 36 public new PermutationFlowshopSchedulingProblem Content 36 37 { 38 get { return (PermutationFlowshopSchedulingProblem)base.Content; } 39 set { base.Content = value; } 40 } 37 41 38 public new PermutationFlowshopSchedulingProblem Content 39 { 40 get { return (PermutationFlowshopSchedulingProblem)base.Content; } 41 set { base.Content = value; } 42 public JobShopSchedulingProblemView() { 43 InitializeComponent(); 44 Controls.Remove(parameterCollectionView); 45 parameterCollectionView.Dock = DockStyle.Fill; 46 problemTabPage.Controls.Add(parameterCollectionView); 47 } 48 49 protected override void OnContentChanged() { 50 base.OnContentChanged(); 51 FillGanttChart(); 52 } 53 54 protected override void DeregisterContentEvents() { 55 Content.BestKnownSolutionChanged -= Content_PermutationChanged; 56 base.DeregisterContentEvents(); 57 } 58 protected override void RegisterContentEvents() { 59 base.RegisterContentEvents(); 60 Content.BestKnownSolutionChanged += new EventHandler(Content_PermutationChanged); 61 } 62 63 private void Content_PermutationChanged(object sender, EventArgs e) { 64 if (InvokeRequired) { 65 Invoke(new EventHandler(Content_PermutationChanged), sender, e); 66 } else { 67 FillGanttChart(); 68 } 69 } 70 71 private void FillGanttChart() { 72 ganttChart.Reset(); 73 if (Content != null) { 74 var matrix = Content.JobMatrix; 75 var perm = Content.BestKnownSolution; 76 if (matrix == null) { return; } 77 78 if (perm == null) { 79 perm = new Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.Absolute, Enumerable.Range(0, matrix.Columns).ToArray()); 42 80 } 43 81 44 public JobShopSchedulingProblemView() 45 { 46 InitializeComponent(); 47 Controls.Remove(parameterCollectionView); 48 parameterCollectionView.Dock = DockStyle.Fill; 49 problemTabPage.Controls.Add(parameterCollectionView); 82 int[] permutation = perm.ToArray(); 83 84 if (!permutation.Contains(0)) { permutation = permutation.Select(v => v - 1).ToArray(); } 85 DoubleMatrix calculatedTime = new DoubleMatrix(matrix.Rows, matrix.Columns); 86 87 for (var machineIdx = 0; machineIdx < matrix.Rows; machineIdx++) { 88 for (var jobIdx = 0; jobIdx < matrix.Columns; jobIdx++) { 89 double runtimeCur = matrix[machineIdx, permutation[jobIdx]]; 90 double runtimePrev = 0; 91 92 if (jobIdx == 0 && machineIdx == 0) { } else if (machineIdx == 0) { runtimePrev = calculatedTime[machineIdx, jobIdx - 1]; } else if (jobIdx == 0) { runtimePrev = calculatedTime[machineIdx - 1, jobIdx]; } else { 93 double runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx]; 94 double runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1]; 95 runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine; 96 } 97 98 calculatedTime[machineIdx, jobIdx] = runtimeCur + runtimePrev; 99 ganttChart.AddData("Machine " + machineIdx, permutation[jobIdx], jobIdx, runtimePrev, calculatedTime[machineIdx, jobIdx], ""); 100 } 50 101 } 51 52 protected override void OnContentChanged() 53 { 54 base.OnContentChanged(); 55 FillGanttChart(); 56 } 57 58 protected override void DeregisterContentEvents() 59 { 60 Content.BestKnownSolutionChanged -= Content_PermutationChanged; 61 base.DeregisterContentEvents(); 62 } 63 protected override void RegisterContentEvents() 64 { 65 base.RegisterContentEvents(); 66 Content.BestKnownSolutionChanged += new EventHandler(Content_PermutationChanged); 67 } 68 69 private void Content_PermutationChanged(object sender, EventArgs e) 70 { 71 if (InvokeRequired) 72 { 73 Invoke(new EventHandler(Content_PermutationChanged), sender, e); 74 } 75 else 76 { 77 FillGanttChart(); 78 } 79 } 80 81 private void FillGanttChart() 82 { 83 ganttChart.Reset(); 84 if (Content != null) 85 { 86 var matrix = Content.JobMatrix; 87 var perm = Content.BestKnownSolution; 88 if (matrix == null) { return; } 89 90 if (perm == null) 91 { 92 perm = new Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.Absolute, Enumerable.Range(0, matrix.Columns).ToArray()); 93 } 94 95 int[] permutation = perm.ToArray(); 96 97 if (!permutation.Contains(0)) { permutation = permutation.Select(v => v - 1).ToArray(); } 98 DoubleMatrix calculatedTime = new DoubleMatrix(matrix.Rows, matrix.Columns); 99 100 for (var machineIdx = 0; machineIdx < matrix.Rows; machineIdx++) 101 { 102 for (var jobIdx = 0; jobIdx < matrix.Columns; jobIdx++) 103 { 104 double runtimeCur = matrix[machineIdx, permutation[jobIdx]]; 105 double runtimePrev = 0; 106 107 if (jobIdx == 0 && machineIdx == 0) { } 108 else if (machineIdx == 0) { runtimePrev = calculatedTime[machineIdx, jobIdx - 1]; } 109 else if (jobIdx == 0) { runtimePrev = calculatedTime[machineIdx - 1, jobIdx]; } 110 else 111 { 112 double runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx]; 113 double runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1]; 114 runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine; 115 } 116 117 calculatedTime[machineIdx, jobIdx] = runtimeCur + runtimePrev; 118 ganttChart.AddData("Machine " + machineIdx, permutation[jobIdx], jobIdx, runtimePrev, calculatedTime[machineIdx, jobIdx], ""); 119 } 120 } 121 } 122 } 102 } 123 103 } 104 } 124 105 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP.Views/3.3/Plugin.cs
r15541 r15639 23 23 24 24 namespace HeuristicLab.Problems.PFSP.Views { 25 [Plugin("HeuristicLab.Problems.PFSP.Views", "3.3.14.155 21")]25 [Plugin("HeuristicLab.Problems.PFSP.Views", "3.3.14.15541")] 26 26 [PluginFile("HeuristicLab.Problems.PFSP.Views-3.3.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP.Views/3.3/Properties/AssemblyInfo.cs
r15541 r15639 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.3.0.0")] 55 [assembly: AssemblyFileVersion("3.3.14.155 21")]55 [assembly: AssemblyFileVersion("3.3.14.15541")] -
branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP/3.3/HeuristicLab.Problems.PFSP-3.3.csproj
r15541 r15639 88 88 </ItemGroup> 89 89 <ItemGroup> 90 <Compile Include="Evaluators\CmaxMakeSpanEvaluator.cs" />91 <Compile Include="Evaluators\MakeSpanEvaluator.cs" />92 <Compile Include="Evaluators\PFSPEvaluator.cs" />93 <Compile Include="Interfaces\IMakespanEvaluator.cs" />94 <Compile Include="JobMatrix.cs" />95 <Compile Include="Interfaces\IPFSPEvaluator.cs" />96 90 <Compile Include="PermutationFlowshopSchedulingProblem.cs" /> 97 91 <Compile Include="Plugin.cs" /> -
branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP/3.3/PermutationFlowshopSchedulingProblem.cs
r15541 r15639 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Drawing;24 23 using System.Linq; 25 24 using HeuristicLab.Common; … … 29 28 using HeuristicLab.Parameters; 30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.PluginInfrastructure;32 30 using HeuristicLab.Problems.Instances; 33 31 using HeuristicLab.Optimization; 34 using System.Collections.Generic;35 32 36 namespace HeuristicLab.Problems.PFSP 37 { 38 [Item("Permutation Flowshop Scheduling Problem (PFSP)", "Represents a Permutation Flowshop Scheduling Problem")] 39 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 999)] 40 [StorableClass] 41 public sealed class PermutationFlowshopSchedulingProblem : SingleObjectiveHeuristicOptimizationProblem<IPFSPEvaluator, IPermutationCreator>, IProblemInstanceConsumer<FSSPData>, IProblemInstanceExporter<FSSPData>, IStorableContent 42 { 43 #region Default Instance 44 private static readonly FSSPData DefaultInstance = new FSSPData() 45 { 46 Name = "Permutation Flowshop Scheduling Problem (PFSP)", 47 Description = "The default instance of the PFSP problem in HeuristicLab", 48 Jobs = 4, 49 Machines = 4, 50 //BestKnownQuality = 328, 51 ProcessingTimes = new double[,] { 33 namespace HeuristicLab.Problems.PFSP { 34 [Item("Permutation Flowshop Scheduling Problem (PFSP)", "Represents a Permutation Flowshop Scheduling Problem")] 35 [Creatable(CreatableAttribute.Categories.CombinatorialProblems)] 36 [StorableClass] 37 public sealed class PermutationFlowshopSchedulingProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IProblemInstanceConsumer<FSSPData>, IProblemInstanceExporter<FSSPData> { 38 #region Fields 39 private static readonly FSSPData DefaultInstance = new FSSPData() { 40 Name = "Permutation Flowshop Scheduling Problem (PFSP)", 41 Description = "The default instance of the PFSP problem in HeuristicLab", 42 Jobs = 4, 43 Machines = 4, 44 //BestKnownQuality = 328, 45 ProcessingTimes = new double[,] { 52 46 {5 ,3, 6 ,6 }, 53 47 {2 ,4, 8 ,4}, … … 55 49 {5 ,3, 8 ,6} 56 50 } 57 }; 58 #endregion 51 }; 52 public event EventHandler BestKnownSolutionChanged; 53 #endregion 59 54 60 public string Filename { get; set; } 55 #region Getter/Setter 56 public OptionalValueParameter<Permutation> BestKnownSolutionParameter 57 { 58 get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; } 59 } 60 public OptionalValueParameter<DoubleMatrix> JobMatrixParameter 61 { 62 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["JobMatrix"]; } 63 } 64 public Permutation BestKnownSolution 65 { 66 get { return BestKnownSolutionParameter.Value; } 67 set 68 { 69 BestKnownSolutionParameter.Value = value; 70 if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); } 71 } 72 } 73 public DoubleMatrix JobMatrix 74 { 75 get { return JobMatrixParameter.Value; } 76 set { JobMatrixParameter.Value = value; } 77 } 61 78 62 #region Parameter Properties 63 public OptionalValueParameter<Permutation> BestKnownSolutionParameter 64 { 65 get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; } 79 public override bool Maximization { get { return false; } } 80 #endregion 81 82 #region Ctor 83 [StorableConstructor] 84 private PermutationFlowshopSchedulingProblem(bool deserializing) : base(deserializing) { } 85 private PermutationFlowshopSchedulingProblem(PermutationFlowshopSchedulingProblem original, Cloner cloner) : base(original, cloner) { } 86 public PermutationFlowshopSchedulingProblem() { 87 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this FSSP instance.")); 88 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("JobMatrix", "The matrix which contains the jobs,machines and duration.")); 89 90 Load(DefaultInstance); 91 EvaluatorParameter.GetsCollected = false; 92 EvaluatorParameter.Hidden = true; 93 94 Evaluator.QualityParameter.ActualName = "Makespan"; 95 } 96 #endregion 97 98 #region Methods 99 public override IDeepCloneable Clone(Cloner cloner) { 100 return new PermutationFlowshopSchedulingProblem(this, cloner); 101 } 102 103 public void Load(FSSPData data) { 104 if (data.BestKnownQuality.HasValue) { 105 BestKnownQuality = data.BestKnownQuality.Value; 106 } 107 Name = data.Name; 108 Description = data.Description; 109 JobMatrix = new DoubleMatrix(data.ProcessingTimes); 110 Encoding.Length = JobMatrix.Columns; 111 112 if (data.BestKnownSchedule != null) { 113 int[] permut = data.BestKnownSchedule; 114 //Clean up if the first index = 1 115 if (!permut.Contains(0)) { permut = permut.Select(v => v - 1).ToArray(); } 116 117 BestKnownSolution = new Permutation(PermutationTypes.Absolute, data.BestKnownSchedule); 118 BestKnownQuality = Evaluate(permut, JobMatrix); 119 } 120 } 121 public FSSPData Export() { 122 var result = new FSSPData { 123 Name = Name, 124 Description = Description, 125 ProcessingTimes = new double[JobMatrix.Rows, JobMatrix.Columns] 126 }; 127 128 result.BestKnownQuality = BestKnownQuality; 129 130 if (JobMatrix != null) { 131 result.Jobs = JobMatrix.Rows; 132 result.Machines = JobMatrix.Columns; 133 } 134 135 for (int i = 0; i < JobMatrix.Rows; i++) { 136 for (int j = 0; j < JobMatrix.Columns; j++) { 137 result.ProcessingTimes[i, j] = JobMatrix[i, j]; 66 138 } 139 } 67 140 68 public OptionalValueParameter<JobMatrix> JobMatrixParameter 69 { 70 get { return (OptionalValueParameter<JobMatrix>)Parameters["JobMatrix"]; } 141 result.BestKnownSchedule = BestKnownSolution != null ? (BestKnownSolution as IntArray).ToArray() : null; 142 143 return result; 144 } 145 146 public override double Evaluate(Individual individual, IRandom random) { 147 return Evaluate(individual.Permutation().ToArray(), JobMatrix); 148 } 149 #endregion 150 151 #region Helper Methods 152 private void OnBestKnownSolutionChanged() { 153 BestKnownSolutionChanged?.Invoke(this, EventArgs.Empty); 154 } 155 156 /// <summary> 157 /// Calculates the makespan (cMax), meaning the total time from start till the last job on the last machine is done 158 /// </summary> 159 /// <param name="permutation"></param> 160 /// <param name="matrix"></param> 161 /// <returns></returns> 162 private double Evaluate(int[] permutation, DoubleMatrix matrix) { 163 DoubleMatrix calculatedTime = new DoubleMatrix(matrix.Rows, matrix.Columns); 164 double runtimePrev; 165 166 double runtimePrevMachine; 167 double runtimePrevJobOnThisMachine; 168 169 for (var machineIdx = 0; machineIdx < matrix.Rows; machineIdx++) { 170 for (var jobIdx = 0; jobIdx < matrix.Columns; jobIdx++) { 171 runtimePrev = 0; 172 173 if (jobIdx == 0 && machineIdx == 0) { //Nothing to calculate 174 } else if (machineIdx == 0) { 175 runtimePrev = calculatedTime[machineIdx, jobIdx - 1]; 176 } else if (jobIdx == 0) { 177 runtimePrev = calculatedTime[machineIdx - 1, jobIdx]; 178 } else { 179 runtimePrevMachine = calculatedTime[machineIdx - 1, jobIdx]; 180 runtimePrevJobOnThisMachine = calculatedTime[machineIdx, jobIdx - 1]; 181 runtimePrev = runtimePrevMachine > runtimePrevJobOnThisMachine ? runtimePrevMachine : runtimePrevJobOnThisMachine; 182 } 183 calculatedTime[machineIdx, jobIdx] = matrix[machineIdx, permutation[jobIdx]] + runtimePrev; 71 184 } 72 #endregion 73 74 #region Properties 75 public Permutation BestKnownSolution 76 { 77 get { return BestKnownSolutionParameter.Value; } 78 set 79 { 80 BestKnownSolutionParameter.Value = value; 81 if (BestKnownSolutionChanged != null) { OnBestKnownSolutionChanged(); } 82 } 83 } 84 public JobMatrix JobMatrix 85 { 86 get { return JobMatrixParameter.Value; } 87 set { JobMatrixParameter.Value = value; } 88 } 89 #endregion 90 91 public event EventHandler BestKnownSolutionChanged; 92 private void OnBestKnownSolutionChanged() 93 { 94 var changed = BestKnownSolutionChanged; 95 if (changed != null) 96 changed(this, EventArgs.Empty); 97 } 98 99 [StorableConstructor] 100 private PermutationFlowshopSchedulingProblem(bool deserializing) : base(deserializing) { } 101 private PermutationFlowshopSchedulingProblem(PermutationFlowshopSchedulingProblem original, Cloner cloner) 102 : base(original, cloner) 103 { 104 } 105 public PermutationFlowshopSchedulingProblem() 106 : base(new CmaxMakeSpanEvaluator(), new RandomPermutationCreator()) 107 { 108 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this FSSP instance.")); 109 Parameters.Add(new OptionalValueParameter<JobMatrix>("JobMatrix", "The matrix which contains the jobs,machines and duration.")); 110 111 Load(DefaultInstance); 112 EvaluatorParameter.GetsCollected = false; 113 EvaluatorParameter.Hidden = true; 114 115 Maximization.Value = false; 116 MaximizationParameter.Hidden = true; 117 118 SolutionCreator.PermutationParameter.ActualName = "PFSPOrder"; 119 Evaluator.QualityParameter.ActualName = "Makespan"; 120 ParameterizeSolutionCreator(); 121 ParameterizeEvaluator(); 122 123 InitializeOperators(); 124 } 125 126 public override IDeepCloneable Clone(Cloner cloner) 127 { 128 return new PermutationFlowshopSchedulingProblem(this, cloner); 129 } 130 131 [StorableHook(HookType.AfterDeserialization)] 132 private void AfterDeserialization() { } 133 134 #region Problem Instance Handling 135 public void Load(FSSPData data) 136 { 137 138 BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 139 Name = data.Name; 140 Description = data.Description; 141 JobMatrix = new JobMatrix(data.ProcessingTimes); 142 143 if (data.BestKnownSchedule != null) 144 { 145 int[] permut = data.BestKnownSchedule; 146 //Clean up if the first index = 1 147 if (!permut.Contains(0)) { permut = permut.Select(v => v - 1).ToArray(); } 148 double bestKnownQuality = MakeSpanEvaluator.Apply( 149 new CmaxMakeSpanEvaluator(), 150 new DoubleMatrix(data.ProcessingTimes), 151 new Permutation(PermutationTypes.Absolute, permut) 152 ); 153 154 BestKnownSolution = new Permutation(PermutationTypes.Absolute, data.BestKnownSchedule); 155 BestKnownQuality = new DoubleValue(bestKnownQuality); 156 } 157 158 ParameterizeSolutionCreator(); 159 } 160 public FSSPData Export() 161 { 162 var result = new FSSPData 163 { 164 Name = Name, 165 Description = Description, 166 ProcessingTimes = new double[JobMatrix.Rows, JobMatrix.Columns] 167 }; 168 169 if (BestKnownQuality != null) 170 { 171 result.BestKnownQuality = BestKnownQuality.Value; 172 } 173 174 if (JobMatrix != null) 175 { 176 result.Jobs = JobMatrix.Rows; 177 result.Machines = JobMatrix.Columns; 178 } 179 180 for (int i = 0; i < JobMatrix.Rows; i++) 181 { 182 for (int j = 0; j < JobMatrix.Columns; j++) 183 { 184 result.ProcessingTimes[i, j] = JobMatrix[i, j]; 185 } 186 } 187 188 result.BestKnownSchedule = BestKnownSolution != null ? (BestKnownSolution as IntArray).ToArray() : null; 189 190 return result; 191 } 192 #endregion 193 194 #region Helpers 195 private void InitializeOperators() 196 { 197 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPermutationOperator>()); 198 ParameterizeOperators(); 199 } 200 private void ParameterizeOperators() 201 { 202 foreach (IPermutationCrossover op in Operators.OfType<IPermutationCrossover>()) 203 { 204 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 205 op.ParentsParameter.Hidden = true; 206 op.ChildParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 207 op.ChildParameter.Hidden = true; 208 } 209 foreach (IPermutationManipulator op in Operators.OfType<IPermutationManipulator>()) 210 { 211 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 212 op.PermutationParameter.Hidden = true; 213 } 214 foreach (IPermutationMoveOperator op in Operators.OfType<IPermutationMoveOperator>()) 215 { 216 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 217 op.PermutationParameter.Hidden = true; 218 } 219 foreach (IPermutationMultiNeighborhoodShakingOperator op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 220 { 221 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 222 op.PermutationParameter.Hidden = true; 223 } 224 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) 225 { 226 op.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 227 op.SolutionParameter.Hidden = true; 228 } 229 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) 230 { 231 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 232 op.ParentsParameter.Hidden = true; 233 } 234 foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>()) 235 { 236 op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName; 237 op.QualityVariableName = Evaluator.QualityParameter.ActualName; 238 } 239 } 240 private void ParameterizeSolutionCreator() 241 { 242 SolutionCreator.LengthParameter.Value = new IntValue(JobMatrix.Columns); 243 244 SolutionCreator.LengthParameter.Hidden = SolutionCreator.LengthParameter.Value != null; 245 SolutionCreator.PermutationTypeParameter.Value = new PermutationType(PermutationTypes.RelativeUndirected); 246 SolutionCreator.PermutationTypeParameter.Hidden = true; 247 } 248 private void ParameterizeEvaluator() 249 { 250 if (Evaluator is CmaxMakeSpanEvaluator) 251 { 252 IMakespanEvaluator evaluator = (IMakespanEvaluator)Evaluator; 253 evaluator.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 254 evaluator.PermutationParameter.Hidden = true; 255 } 256 } 257 #endregion 185 } 186 return calculatedTime[calculatedTime.Rows - 1, calculatedTime.Columns - 1]; 258 187 } 188 #endregion 189 } 259 190 } -
branches/2864_PermutationProblems/HeuristicLab.Problems.PFSP/3.3/Properties/AssemblyInfo.cs
r15541 r15639 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3.14.155 21")]56 [assembly: AssemblyFileVersion("3.3.14.15541")] 57 57
Note: See TracChangeset
for help on using the changeset viewer.