Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CFSAP/HeuristicLab.Problems.Instances.CFSAP/3.3/BozejkoCFSAPInstanceProvider.cs @ 15460

Last change on this file since 15460 was 15460, checked in by abeham, 6 years ago

#2747: worked on the CFSAP

  • Added problem definition that defines both sequence and assignment for a single nest
  • Added problem definition that would optimizes both sequence and assignment for multiple nests
  • Added interface
  • Added solving strategy that would use multiple instances of a template algorithm to optimize the worst nest
  • Fixed bug in parser regarding setup times
File size: 6.6 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    public override CFSAPData ImportData(string path) {
65      var instance = LoadInstance(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
66      instance.Name = Path.GetFileName(path);
67      instance.Description = "Imported from " + path + " " + DateTime.Now;
68      return instance;
69    }
70
71    public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
72      var instanceArchiveName = GetResourceName(@"BozejkoCFSAP\.zip");
73      if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
74
75      using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
76        foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
77          yield return new BozejkoCFSAPDataDescriptor(Path.GetFileNameWithoutExtension(entry),
78                                                      GetInstanceDescription(), entry);
79        }
80      }
81    }
82
83    public override CFSAPData LoadData(IDataDescriptor id) {
84      var descriptor = (BozejkoCFSAPDataDescriptor)id;
85      var instanceArchiveName = GetResourceName(@"BozejkoCFSAP\.zip");
86      using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
87        var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
88        var instance = LoadInstance(entry.Open());
89        instance.Name = id.Name;
90        instance.Description = id.Description;
91        int bkct;
92        if (bestKnownCycleTimes.TryGetValue(id.Name, out bkct))
93          instance.BestKnownCycleTime = bkct;
94        return instance;
95      }
96    }
97
98    private string GetResourceName(string fileName) {
99      return Assembly.GetExecutingAssembly()
100                     .GetManifestResourceNames()
101                     .SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
102    }
103
104    private string GetInstanceDescription() {
105      return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
106    }
107
108    private static readonly Dictionary<string, int> bestKnownCycleTimes = new Dictionary<string, int>() {
109{ "gi_001", 608 },
110{ "gi_002", 623 },
111{ "gi_003", 500 },
112{ "gi_004", 585 },
113{ "gi_005", 549 },
114{ "gi_006", 629 },
115{ "gi_007", 603 },
116{ "gi_008", 506 },
117{ "gi_009", 588 },
118{ "gi_010", 493 },
119{ "gi_011", 597 },
120{ "gi_012", 554 },
121{ "gi_013", 594 },
122{ "gi_014", 505 },
123{ "gi_015", 631 },
124{ "gi_016", 626 },
125{ "gi_017", 585 },
126{ "gi_018", 529 },
127{ "gi_019", 649 },
128{ "gi_020", 561 },
129{ "gi_021", 535 },
130{ "gi_022", 586 },
131{ "gi_023", 602 },
132{ "gi_024", 607 },
133{ "gi_025", 598 },
134{ "gi_026", 572 },
135{ "gi_027", 605 },
136{ "gi_028", 619 },
137{ "gi_029", 646 },
138{ "gi_030", 591 },
139{ "gi_031", 958 },
140{ "gi_032", 838 },
141{ "gi_033", 974 },
142{ "gi_034", 904 },
143{ "gi_035", 1002 },
144{ "gi_036", 998 },
145{ "gi_037", 988 },
146{ "gi_038", 872 },
147{ "gi_039", 1009 },
148{ "gi_040", 1000 },
149{ "gi_041", 992 },
150{ "gi_042", 1097 },
151{ "gi_043", 989 },
152{ "gi_044", 1038 },
153{ "gi_045", 998 },
154{ "gi_046", 1077 },
155{ "gi_047", 997 },
156{ "gi_048", 921 },
157{ "gi_049", 902 },
158{ "gi_050", 1035 },
159{ "gi_051", 914 },
160{ "gi_052", 1019 },
161{ "gi_053", 997 },
162{ "gi_054", 928 },
163{ "gi_055", 973 },
164{ "gi_056", 1011 },
165{ "gi_057", 943 },
166{ "gi_058", 959 },
167{ "gi_059", 1079 },
168{ "gi_060", 940 },
169{ "gi_061", 2176 },
170{ "gi_062", 2100 },
171{ "gi_063", 2147 },
172{ "gi_064", 2289 },
173{ "gi_065", 2171 },
174{ "gi_066", 2185 },
175{ "gi_067", 2152 },
176{ "gi_068", 2321 },
177{ "gi_069", 2173 },
178{ "gi_070", 2242 },
179{ "gi_071", 2222 },
180{ "gi_072", 2403 },
181{ "gi_073", 2305 },
182{ "gi_074", 2279 },
183{ "gi_075", 2283 },
184{ "gi_076", 2014 },
185{ "gi_077", 2185 },
186{ "gi_078", 2236 },
187{ "gi_079", 2223 },
188{ "gi_080", 2136 },
189{ "gi_081", 2147 },
190{ "gi_082", 2285 },
191{ "gi_083", 2270 },
192{ "gi_084", 2264 },
193{ "gi_085", 2192 },
194{ "gi_086", 2052 },
195{ "gi_087", 2130 },
196{ "gi_088", 2172 },
197{ "gi_089", 2530 },
198{ "gi_090", 2498 },
199{ "gi_091", 4465 },
200{ "gi_092", 4269 },
201{ "gi_093", 4201 },
202{ "gi_094", 4330 },
203{ "gi_095", 4158 },
204{ "gi_096", 4355 },
205{ "gi_097", 4363 },
206{ "gi_098", 4268 },
207{ "gi_099", 4143 },
208{ "gi_100", 4313 },
209{ "gi_101", 4285 },
210{ "gi_102", 4421 },
211{ "gi_103", 4288 },
212{ "gi_104", 4295 },
213{ "gi_105", 4295 },
214{ "gi_106", 4257 },
215{ "gi_107", 4610 },
216{ "gi_108", 4579 },
217{ "gi_109", 4578 },
218{ "gi_110", 4219 },
219{ "gi_111", 4472 },
220{ "gi_112", 4460 },
221{ "gi_113", 4446 },
222{ "gi_114", 4504 },
223{ "gi_115", 4417 },
224{ "gi_116", 4503 },
225{ "gi_117", 4442 },
226{ "gi_118", 4411 },
227{ "gi_119", 4506 },
228{ "gi_120", 4556 }
229    };
230  }
231}
Note: See TracBrowser for help on using the repository browser.