Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2864_PermutationProblems/HeuristicLab.Problems.Instances.PFSP/3.3/FSSPTAILIBInstanceProvider.cs @ 15529

Last change on this file since 15529 was 15521, checked in by fholzing, 7 years ago

#2864: First commit of new branch of Permutation based benchmark problems.

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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
22using System;
23using System.Collections.Generic;
24using System.IO;
25using System.IO.Compression;
26using System.Linq;
27using System.Reflection;
28using System.Text.RegularExpressions;
29
30namespace HeuristicLab.Problems.Instances.PFSP
31{
32    public class FSSPTAILIBInstanceProvider : ProblemInstanceProvider<FSSPData>
33    {
34
35        public override string Name
36        {
37            get { return "FSSPTAI"; }
38        }
39
40        public override string Description
41        {
42            get { return "Permutation Flowshop scheduling problems as defined by Taillard."; }
43        }
44
45        public override Uri WebLink
46        {
47            get { return new Uri("http://mistic.heig-vd.ch/taillard/problemes.dir/ordonnancement.dir/ordonnancement.html"); }
48        }
49
50        public override string ReferencePublication
51        {
52            get { return String.Empty; }
53        }
54
55        public override IEnumerable<IDataDescriptor> GetDataDescriptors()
56        {
57            var instanceArchiveName = GetResourceName("FSSPTAI.zip");
58            if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
59
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        }
68
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 true; }
115        }
116
117        public override void ExportData(FSSPData instance, string path)
118        {
119            var parser = new FSSPTAILIBParser
120            {
121                Name = instance.Name,
122                Description = instance.Description,
123                Jobs = instance.Jobs,
124                Machines = instance.Machines,
125                ProcessingTimes = instance.ProcessingTimes,
126            };
127            parser.Export(path);
128        }
129
130        private string GetDescription()
131        {
132            return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
133        }
134
135        protected virtual string GetResourceName(string fileName)
136        {
137            return Assembly.GetExecutingAssembly().GetManifestResourceNames()
138              .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
139        }
140    }
141}
Note: See TracBrowser for help on using the repository browser.