[8882] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15973] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8882] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.IO;
|
---|
[11650] | 25 | using System.IO.Compression;
|
---|
[8882] | 26 | using System.Linq;
|
---|
| 27 | using System.Reflection;
|
---|
| 28 | using System.Text.RegularExpressions;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Instances.Scheduling {
|
---|
| 31 | public class JSSPORLIBInstanceProvider : ProblemInstanceProvider<JSSPData> {
|
---|
| 32 |
|
---|
| 33 | public override string Name {
|
---|
| 34 | get { return "ORLIB JSSP"; }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public override string Description {
|
---|
| 38 | get { return "Job shop scheduling problems from the Operations Research Library."; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public override Uri WebLink {
|
---|
| 42 | get { return new Uri("http://people.brunel.ac.uk/~mastjjb/jeb/orlib/jobshopinfo.html"); }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | public override string ReferencePublication {
|
---|
| 46 | get { return String.Empty; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
|
---|
| 50 | var instanceArchiveName = GetResourceName("JSSPORLIB.zip");
|
---|
| 51 | if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
|
---|
| 52 |
|
---|
[11650] | 53 | using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
|
---|
| 54 | foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
|
---|
[8882] | 55 | yield return new JSSPORLIBDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public override JSSPData LoadData(IDataDescriptor id) {
|
---|
| 61 | var descriptor = (JSSPORLIBDataDescriptor)id;
|
---|
| 62 | var instanceArchiveName = GetResourceName("JSSPORLIB.zip");
|
---|
[11650] | 63 | using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
|
---|
[8882] | 64 | var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
|
---|
| 65 |
|
---|
[11650] | 66 | using (var stream = entry.Open()) {
|
---|
[8882] | 67 | var parser = new JSSPORLIBParser();
|
---|
| 68 | parser.Parse(stream);
|
---|
[15973] | 69 | return Load(parser);
|
---|
[8882] | 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public override bool CanImportData {
|
---|
| 75 | get { return true; }
|
---|
| 76 | }
|
---|
| 77 | public override JSSPData ImportData(string path) {
|
---|
| 78 | var parser = new JSSPORLIBParser();
|
---|
| 79 | parser.Parse(path);
|
---|
[15973] | 80 | return Load(parser);
|
---|
[8882] | 81 | }
|
---|
| 82 |
|
---|
| 83 | private JSSPData Load(JSSPORLIBParser parser) {
|
---|
| 84 | var instance = new JSSPData {
|
---|
[15973] | 85 | Name = parser.Name,
|
---|
| 86 | Description = parser.Description,
|
---|
[8882] | 87 | Jobs = parser.Jobs,
|
---|
| 88 | Resources = parser.Resources,
|
---|
| 89 | ProcessingTimes = parser.ProcessingTimes,
|
---|
| 90 | Demands = parser.Demands,
|
---|
| 91 | DueDates = parser.DueDates
|
---|
| 92 | };
|
---|
| 93 | return instance;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | public override bool CanExportData {
|
---|
| 97 | get { return true; }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public override void ExportData(JSSPData instance, string path) {
|
---|
| 101 | var parser = new JSSPORLIBParser {
|
---|
| 102 | Name = instance.Name,
|
---|
| 103 | Description = instance.Description,
|
---|
| 104 | Jobs = instance.Jobs,
|
---|
| 105 | Resources = instance.Resources,
|
---|
| 106 | ProcessingTimes = instance.ProcessingTimes,
|
---|
| 107 | Demands = instance.Demands,
|
---|
| 108 | DueDates = instance.DueDates
|
---|
| 109 | };
|
---|
| 110 | parser.Export(path);
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | private string GetDescription() {
|
---|
| 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 | return Assembly.GetExecutingAssembly().GetManifestResourceNames()
|
---|
| 119 | .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|