Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2747_CFSAP/HeuristicLab.Problems.Instances.CFSAP/3.3/BozejkoCFSAPInstanceProvider.cs @ 17945

Last change on this file since 17945 was 15493, checked in by abeham, 7 years ago

#2747: Implemeted hard-coded genetic algorithm for faster evaluation

File size: 6.9 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.CFSAP {
31  public class BozejkoCFSAPInstanceProvider : ProblemInstanceProvider<CFSAPData> {
32
33    public override string Name {
34      get { return "Bozejko (random CFSAP)"; }
35    }
36
37    public override string Description {
38      get { return string.Empty; }
39    }
40
41    public override Uri WebLink {
42      get { return null; }
43    }
44
45    public override string ReferencePublication {
46      get { return string.Empty; }
47    }
48
49    public override bool CanImportData {
50      get { return true; }
51    }
52
53    private CFSAPData LoadInstance(Stream stream) {
54      var parser = new BozejkoCFSAPParser();
55      parser.Parse(stream);
56      return new CFSAPData {
57        Jobs = parser.Jobs,
58        Nests = parser.Nests,
59        Machines = parser.Machines,
60        ProcessingTimes = parser.ProcessingTimes,
61        SetupTimes = parser.SetupTimes
62      };
63    }
64
65    public override CFSAPData ImportData(string path) {
66      var instance = LoadInstance(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
67      instance.Name = Path.GetFileName(path);
68      instance.Description = "Imported from " + path + " " + DateTime.Now;
69      return instance;
70    }
71
72    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
73      var instanceArchiveName = GetResourceName(@"BozejkoCFSAP\.zip");
74      if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
75
76      using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
77        foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
78          yield return new BozejkoCFSAPDataDescriptor(Path.GetFileNameWithoutExtension(entry),
79                                                      GetInstanceDescription(), entry);
80        }
81      }
82    }
83
84    public override CFSAPData LoadData(IDataDescriptor id) {
85      var descriptor = (BozejkoCFSAPDataDescriptor)id;
86      var instanceArchiveName = GetResourceName(@"BozejkoCFSAP\.zip");
87      using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
88        var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
89        var instance = LoadInstance(entry.Open());
90        instance.Name = id.Name;
91        instance.Description = id.Description;
92        int bkct;
93        if (bestKnownCycleTimes.TryGetValue(id.Name, out bkct))
94          instance.BestKnownCycleTime = bkct;
95        return instance;
96      }
97    }
98
99    private string GetResourceName(string fileName) {
100      return Assembly.GetExecutingAssembly()
101                     .GetManifestResourceNames()
102                     .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
103    }
104
105    private string GetInstanceDescription() {
106      return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
107    }
108
109    private static readonly Dictionary<string, int> bestKnownCycleTimes = new Dictionary<string, int>() {
110{ "gi_001",  608 },
111{ "gi_002",  623 },
112{ "gi_003",  500 },
113{ "gi_004",  585 },
114{ "gi_005",  549 },
115{ "gi_006",  629 },
116{ "gi_007",  603 },
117{ "gi_008",  506 },
118{ "gi_009",  588 },
119{ "gi_010",  493 },
120{ "gi_011",  597 },
121{ "gi_012",  554 },
122{ "gi_013",  594 },
123{ "gi_014",  505 },
124{ "gi_015",  631 },
125{ "gi_016",  626 },
126{ "gi_017",  585 },
127{ "gi_018",  529 },
128{ "gi_019",  649 },
129{ "gi_020",  561 },
130{ "gi_021",  535 },
131{ "gi_022",  586 },
132{ "gi_023",  602 },
133{ "gi_024",  607 },
134{ "gi_025",  598 },
135{ "gi_026",  572 },
136{ "gi_027",  605 },
137{ "gi_028",  619 },
138{ "gi_029",  646 },
139{ "gi_030",  591 },
140{ "gi_031",  958 },
141{ "gi_032",  838 },
142{ "gi_033",  974 },
143{ "gi_034",  904 },
144{ "gi_035", 1002 },
145{ "gi_036",  998 },
146{ "gi_037",  988 },
147{ "gi_038",  872 },
148{ "gi_039", 1009 },
149{ "gi_040", 1000 },
150{ "gi_041",  992 },
151{ "gi_042", 1097 },
152{ "gi_043",  989 },
153{ "gi_044", 1038 },
154{ "gi_045",  998 },
155{ "gi_046", 1077 },
156{ "gi_047",  997 },
157{ "gi_048",  921 },
158{ "gi_049",  902 },
159{ "gi_050", 1035 },
160{ "gi_051",  914 },
161{ "gi_052", 1019 },
162{ "gi_053",  997 },
163{ "gi_054",  928 },
164{ "gi_055",  973 },
165{ "gi_056", 1011 },
166{ "gi_057",  943 },
167{ "gi_058",  959 },
168{ "gi_059", 1079 },
169{ "gi_060",  940 },
170{ "gi_061", 2176 },
171{ "gi_062", 2100 },
172{ "gi_063", 2147 },
173{ "gi_064", 2289 },
174{ "gi_065", 2171 },
175{ "gi_066", 2185 },
176{ "gi_067", 2152 },
177{ "gi_068", 2321 },
178{ "gi_069", 2173 },
179{ "gi_070", 2242 },
180{ "gi_071", 2222 },
181{ "gi_072", 2403 },
182{ "gi_073", 2305 },
183{ "gi_074", 2279 },
184{ "gi_075", 2283 },
185{ "gi_076", 2014 },
186{ "gi_077", 2185 },
187{ "gi_078", 2236 },
188{ "gi_079", 2223 },
189{ "gi_080", 2132 },
190{ "gi_081", 2147 },
191{ "gi_082", 2285 },
192{ "gi_083", 2270 },
193{ "gi_084", 2264 },
194{ "gi_085", 2192 },
195{ "gi_086", 2052 },
196{ "gi_087", 2130 },
197{ "gi_088", 2172 },
198{ "gi_089", 2530 },
199{ "gi_090", 2498 },
200{ "gi_091", 4465 },
201{ "gi_092", 4269 },
202{ "gi_093", 4199 },
203{ "gi_094", 4319 },
204{ "gi_095", 4154 },
205{ "gi_096", 4355 },
206{ "gi_097", 4363 },
207{ "gi_098", 4264 },
208{ "gi_099", 4133 },
209{ "gi_100", 4313 },
210{ "gi_101", 4284 },
211{ "gi_102", 4421 },
212{ "gi_103", 4279 },
213{ "gi_104", 4295 },
214{ "gi_105", 4290 },
215{ "gi_106", 4257 },
216{ "gi_107", 4604 },
217{ "gi_108", 4285 },
218{ "gi_109", 4570 },
219{ "gi_110", 4219 },
220{ "gi_111", 4472 },
221{ "gi_112", 4460 },
222{ "gi_113", 4446 },
223{ "gi_114", 4504 },
224{ "gi_115", 4417 },
225{ "gi_116", 4503 },
226{ "gi_117", 4442 },
227{ "gi_118", 4411 },
228{ "gi_119", 4506 },
229{ "gi_120", 4556 }
230    };
231  }
232}
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
Note: See TracBrowser for help on using the repository browser.