1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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;
|
---|
25 | using System.IO.Compression;
|
---|
26 | using System.Linq;
|
---|
27 | using System.Reflection;
|
---|
28 | using System.Text.RegularExpressions;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.Instances.PermutationProblems.PFSP {
|
---|
31 | public class FSSPTAILIBInstanceProvider : ProblemInstanceProvider<FSSPData> {
|
---|
32 |
|
---|
33 | public override string Name
|
---|
34 | {
|
---|
35 | get { return "FSSPTAI"; }
|
---|
36 | }
|
---|
37 |
|
---|
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 "Taillard, E. (1993). Benchmarks for basic scheduling problems. European Journal of Operational Research, 64(2), 278–285. https://doi.org/10.1016/0377-2217(93)90182-m"; }
|
---|
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);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
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);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
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 | }
|
---|
87 |
|
---|
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 | }
|
---|
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 | }
|
---|
114 | }
|
---|
115 | }
|
---|