#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 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.PermutationProblems.PFSP {
public class FSSPTAILIBInstanceProvider : ProblemInstanceProvider {
public override string Name
{
get { return "FSSPTAI"; }
}
public override string Description
{
get { return "Permutation Flowshop Scheduling Problems (PFSP) as defined by Taillard."; }
}
public override Uri WebLink
{
get { return new Uri("http://mistic.heig-vd.ch/taillard/problemes.dir/ordonnancement.dir/ordonnancement.html"); }
}
public override string ReferencePublication
{
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"; }
}
public override IEnumerable GetDataDescriptors() {
var instanceArchiveName = GetResourceName("FSSPTAI.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 FSSPTAILIBDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry, null);
}
}
}
public override FSSPData LoadData(IDataDescriptor id) {
var descriptor = (FSSPTAILIBDataDescriptor)id;
var instanceArchiveName = GetResourceName("FSSPTAI.zip");
using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
using (var stream = entry.Open()) {
var parser = new FSSPTAILIBParser();
parser.Parse(stream);
return Load(parser);
}
}
}
public override bool CanImportData
{
get { return true; }
}
public override FSSPData ImportData(string path) {
var parser = new FSSPTAILIBParser();
parser.Parse(path);
return Load(parser);
}
private FSSPData Load(FSSPTAILIBParser parser) {
var instance = new FSSPData {
Name = parser.Name,
Description = parser.Description,
Jobs = parser.Jobs,
Machines = parser.Machines,
ProcessingTimes = parser.ProcessingTimes,
BestKnownSchedule = parser.BestKnownSchedule,
BestKnownQuality = parser.BestKnownQuality
};
return instance;
}
public override bool CanExportData
{
get { return false; }
}
private string GetDescription() {
return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast().First().Version + ".";
}
protected virtual string GetResourceName(string fileName) {
return Assembly.GetExecutingAssembly().GetManifestResourceNames()
.SingleOrDefault(x => Regex.Match(x, @".*\.Data\." + fileName).Success);
}
}
}