#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
namespace HeuristicLab.Problems.Instances.CFSAP {
public class BozejkoCFSAPInstanceProvider : ProblemInstanceProvider {
public override string Name {
get { return "Bozejko (random CFSAP)"; }
}
public override string Description {
get { return string.Empty; }
}
public override Uri WebLink {
get { return null; }
}
public override string ReferencePublication {
get { return string.Empty; }
}
public override bool CanImportData {
get { return true; }
}
private CFSAPData LoadInstance(Stream stream) {
var parser = new BozejkoCFSAPParser();
parser.Parse(stream);
return new CFSAPData {
Jobs = parser.Jobs,
Nests = parser.Nests,
Machines = parser.Machines,
ProcessingTimes = parser.ProcessingTimes,
SetupTimes = parser.SetupTimes
};
}
public override CFSAPData ImportData(string path) {
var instance = LoadInstance(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
instance.Name = Path.GetFileName(path);
instance.Description = "Imported from " + path + " " + DateTime.Now;
return instance;
}
public override IEnumerable GetDataDescriptors() {
var instanceArchiveName = GetResourceName(@"BozejkoCFSAP\.zip");
if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
yield return new BozejkoCFSAPDataDescriptor(Path.GetFileNameWithoutExtension(entry),
GetInstanceDescription(), entry);
}
}
}
public override CFSAPData LoadData(IDataDescriptor id) {
var descriptor = (BozejkoCFSAPDataDescriptor)id;
var instanceArchiveName = GetResourceName(@"BozejkoCFSAP\.zip");
using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
var instance = LoadInstance(entry.Open());
instance.Name = id.Name;
instance.Description = id.Description;
int bkct;
if (bestKnownCycleTimes.TryGetValue(id.Name, out bkct))
instance.BestKnownCycleTime = bkct;
return instance;
}
}
private string GetResourceName(string fileName) {
return Assembly.GetExecutingAssembly()
.GetManifestResourceNames()
.SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
}
private string GetInstanceDescription() {
return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast().First().Version + ".";
}
private static readonly Dictionary bestKnownCycleTimes = new Dictionary() {
{ "gi_001", 608 },
{ "gi_002", 623 },
{ "gi_003", 500 },
{ "gi_004", 585 },
{ "gi_005", 549 },
{ "gi_006", 629 },
{ "gi_007", 603 },
{ "gi_008", 506 },
{ "gi_009", 588 },
{ "gi_010", 493 },
{ "gi_011", 597 },
{ "gi_012", 554 },
{ "gi_013", 594 },
{ "gi_014", 505 },
{ "gi_015", 631 },
{ "gi_016", 626 },
{ "gi_017", 585 },
{ "gi_018", 529 },
{ "gi_019", 649 },
{ "gi_020", 561 },
{ "gi_021", 535 },
{ "gi_022", 586 },
{ "gi_023", 602 },
{ "gi_024", 607 },
{ "gi_025", 598 },
{ "gi_026", 572 },
{ "gi_027", 605 },
{ "gi_028", 619 },
{ "gi_029", 646 },
{ "gi_030", 591 },
{ "gi_031", 958 },
{ "gi_032", 838 },
{ "gi_033", 974 },
{ "gi_034", 904 },
{ "gi_035", 1002 },
{ "gi_036", 998 },
{ "gi_037", 988 },
{ "gi_038", 872 },
{ "gi_039", 1009 },
{ "gi_040", 1000 },
{ "gi_041", 992 },
{ "gi_042", 1097 },
{ "gi_043", 989 },
{ "gi_044", 1038 },
{ "gi_045", 998 },
{ "gi_046", 1077 },
{ "gi_047", 997 },
{ "gi_048", 921 },
{ "gi_049", 902 },
{ "gi_050", 1035 },
{ "gi_051", 914 },
{ "gi_052", 1019 },
{ "gi_053", 997 },
{ "gi_054", 928 },
{ "gi_055", 973 },
{ "gi_056", 1011 },
{ "gi_057", 943 },
{ "gi_058", 959 },
{ "gi_059", 1079 },
{ "gi_060", 940 },
{ "gi_061", 2176 },
{ "gi_062", 2100 },
{ "gi_063", 2147 },
{ "gi_064", 2289 },
{ "gi_065", 2171 },
{ "gi_066", 2185 },
{ "gi_067", 2152 },
{ "gi_068", 2321 },
{ "gi_069", 2173 },
{ "gi_070", 2242 },
{ "gi_071", 2222 },
{ "gi_072", 2403 },
{ "gi_073", 2305 },
{ "gi_074", 2279 },
{ "gi_075", 2283 },
{ "gi_076", 2014 },
{ "gi_077", 2185 },
{ "gi_078", 2236 },
{ "gi_079", 2223 },
{ "gi_080", 2132 },
{ "gi_081", 2147 },
{ "gi_082", 2285 },
{ "gi_083", 2270 },
{ "gi_084", 2264 },
{ "gi_085", 2192 },
{ "gi_086", 2052 },
{ "gi_087", 2130 },
{ "gi_088", 2172 },
{ "gi_089", 2530 },
{ "gi_090", 2498 },
{ "gi_091", 4465 },
{ "gi_092", 4269 },
{ "gi_093", 4199 },
{ "gi_094", 4319 },
{ "gi_095", 4154 },
{ "gi_096", 4355 },
{ "gi_097", 4363 },
{ "gi_098", 4264 },
{ "gi_099", 4133 },
{ "gi_100", 4313 },
{ "gi_101", 4284 },
{ "gi_102", 4421 },
{ "gi_103", 4279 },
{ "gi_104", 4295 },
{ "gi_105", 4290 },
{ "gi_106", 4257 },
{ "gi_107", 4604 },
{ "gi_108", 4285 },
{ "gi_109", 4570 },
{ "gi_110", 4219 },
{ "gi_111", 4472 },
{ "gi_112", 4460 },
{ "gi_113", 4446 },
{ "gi_114", 4504 },
{ "gi_115", 4417 },
{ "gi_116", 4503 },
{ "gi_117", 4442 },
{ "gi_118", 4411 },
{ "gi_119", 4506 },
{ "gi_120", 4556 }
};
}
}