Changeset 16013


Ignore:
Timestamp:
07/24/18 17:16:00 (3 years ago)
Author:
fholzing
Message:

#2864: Implemented a base class as the instance provider of LOPs

Location:
branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/HeuristicLab.Problems.Instances.PermutationProblems-3.3.csproj

    r15686 r16013  
    5656  <ItemGroup>
    5757    <Compile Include="LOP\LOPDataDescriptor.cs" />
     58    <Compile Include="LOP\LOPInstanceProvider.cs" />
    5859    <Compile Include="LOP\LOPXLOLIBInstanceProvider.cs" />
    5960    <Compile Include="LOP\LOPSPECInstanceProvider.cs" />
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPIOInstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPIOInstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPIOInstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/IO.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("IO.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("IO.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82 
    83     public override LOPData ImportData(string path) {
    84       var parser = new LOPParser();
    85       parser.Parse(path);
    86       return Load(parser);
    87     }
    88 
    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     }
    100 
    101     public override bool CanExportData
    102     {
    103       get { return false; }
    104     }
    105 
    106     private string GetDescription() {
    107       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    108     }
    109 
    110     protected virtual string GetResourceName(string fileName) {
    111       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    112         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    113     }
    11441  }
    11542}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPMBInstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPMBInstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPMBInstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/MB.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("MB.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("MB.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPRANDA1InstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPRANDA1InstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPRANDA1InstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/RandA1.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("RANDA1.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("RANDA1.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPRANDA2InstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPRANDA2InstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPRANDA2InstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/RandA2.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("RANDA2.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("RANDA2.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPRANDBInstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPRANDBInstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPRANDBInstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/RandB.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("RANDB.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("RANDB.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPSGBInstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPSGBInstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPSGBInstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/SGB.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("SGB.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("SGB.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPSPECInstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPSPECInstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPSPECInstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/Spec.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("SPEC.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("SPEC.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
  • branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PermutationProblems/3.3/LOP/LOPXLOLIBInstanceProvider.cs

    r16009 r16013  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.IO;
    25 using System.IO.Compression;
    26 using System.Linq;
    27 using System.Reflection;
    28 using System.Text.RegularExpressions;
    2923
    3024namespace HeuristicLab.Problems.Instances.PermutationProblems.LinearOrdering {
    31   public class LOPXLOLIBInstanceProvider : ProblemInstanceProvider<LOPData> {
     25  public class LOPXLOLIBInstanceProvider : LOPInstanceProvider {
    3226
    3327    public override string Name
     
    4539      get { return new Uri("http://www.optsicom.es/lolib/lop/xLOLIB.zip"); }
    4640    }
    47 
    48     public override string ReferencePublication
    49     {
    50       get { return "Martí, R., & Reinelt, G. (2011). The Linear Ordering Problem. Applied Mathematical Sciences. Springer Berlin Heidelberg. https://doi.org/10.1007/978-3-642-16729-4"; }
    51     }
    52 
    53     public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
    54       var instanceArchiveName = GetResourceName("XLOLIB.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 LOPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
    60         }
    61       }
    62     }
    63 
    64     public override LOPData LoadData(IDataDescriptor id) {
    65       var descriptor = (LOPDataDescriptor)id;
    66       var instanceArchiveName = GetResourceName("XLOLIB.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 LOPParser();
    72           parser.Parse(stream);
    73           return Load(parser);
    74         }
    75       }
    76     }
    77 
    78     public override bool CanImportData
    79     {
    80       get { return true; }
    81     }
    82     public override LOPData ImportData(string path) {
    83       var parser = new LOPParser();
    84       parser.Parse(path);
    85       return Load(parser);
    86     }
    87 
    88     private LOPData Load(LOPParser parser) {
    89       var instance = new LOPData {
    90         Name = parser.Name,
    91         Description = parser.Description,
    92         Dimension = parser.Dimension,
    93         Matrix = parser.Matrix,
    94         BestKnownPermutation = parser.BestKnownPermutation,
    95         BestKnownQuality = parser.BestKnownQuality
    96       };
    97       return instance;
    98     }
    99 
    100     public override bool CanExportData
    101     {
    102       get { return false; }
    103     }
    104 
    105     private string GetDescription() {
    106       return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
    107     }
    108 
    109     protected virtual string GetResourceName(string fileName) {
    110       return Assembly.GetExecutingAssembly().GetManifestResourceNames()
    111         .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
    112     }
    11341  }
    11442}
Note: See TracChangeset for help on using the changeset viewer.