[7505] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7505] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[7538] | 24 | using System.IO;
|
---|
[11932] | 25 | using System.IO.Compression;
|
---|
[7505] | 26 | using System.Linq;
|
---|
| 27 | using System.Reflection;
|
---|
| 28 | using System.Text.RegularExpressions;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Instances.CordeauGQAP {
|
---|
[7548] | 31 | public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<GQAPData> {
|
---|
[7505] | 32 | public override string Name {
|
---|
| 33 | get { return "Cordeau et al. GQAP instances"; }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public override string Description {
|
---|
| 37 | get { return "GQAP instances published by Cordeau, Gaudioso, Laporte, and Moccia."; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public override Uri WebLink {
|
---|
| 41 | get { return null; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public override string ReferencePublication {
|
---|
| 45 | get {
|
---|
| 46 | return @"Cordeau, J.-F., Gaudioso, M., Laporte, G., Moccia, L. 2006.
|
---|
| 47 | A memetic heuristic for the generalized quadratic assignment problem.
|
---|
| 48 | INFORMS Journal on Computing, 18, pp. 433–443.";
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[7638] | 52 | private const string FileName = "CordeauGQAP";
|
---|
[7879] | 53 |
|
---|
[7548] | 54 | public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
|
---|
[7638] | 55 | var instanceArchiveName = GetResourceName(FileName + @"\.zip");
|
---|
| 56 | if (String.IsNullOrEmpty(instanceArchiveName)) yield break;
|
---|
| 57 |
|
---|
[11932] | 58 | using (var instanceStream = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
|
---|
| 59 | foreach (var entry in instanceStream.Entries.Select(x => x.Name).OrderBy(x => x)) {
|
---|
[7638] | 60 | yield return new CordeauGQAPDataDescriptor(Path.GetFileNameWithoutExtension(entry), GetDescription(), entry);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
[7505] | 63 | }
|
---|
| 64 |
|
---|
[7548] | 65 | public override GQAPData LoadData(IDataDescriptor id) {
|
---|
| 66 | var descriptor = (CordeauGQAPDataDescriptor)id;
|
---|
[7638] | 67 | var instanceArchiveName = GetResourceName(FileName + @"\.zip");
|
---|
[11932] | 68 | using (var instancesZipFile = new ZipArchive(GetType().Assembly.GetManifestResourceStream(instanceArchiveName), ZipArchiveMode.Read)) {
|
---|
[7638] | 69 | var entry = instancesZipFile.GetEntry(descriptor.InstanceIdentifier);
|
---|
[11932] | 70 | using (var stream = entry.Open()) {
|
---|
[7638] | 71 | var parser = new CordeauGQAPParser();
|
---|
| 72 | parser.Parse(stream);
|
---|
| 73 | var instance = Load(parser);
|
---|
[7505] | 74 |
|
---|
[7638] | 75 | instance.Name = id.Name;
|
---|
| 76 | instance.Description = id.Description;
|
---|
[7538] | 77 |
|
---|
[7638] | 78 | return instance;
|
---|
| 79 | }
|
---|
[7505] | 80 | }
|
---|
[7538] | 81 | }
|
---|
| 82 |
|
---|
[8192] | 83 | public override bool CanImportData {
|
---|
| 84 | get { return true; }
|
---|
| 85 | }
|
---|
| 86 | public override GQAPData ImportData(string path) {
|
---|
[7538] | 87 | var parser = new CordeauGQAPParser();
|
---|
| 88 | parser.Parse(path);
|
---|
| 89 | var instance = Load(parser);
|
---|
| 90 |
|
---|
| 91 | instance.Name = Path.GetFileName(path);
|
---|
| 92 | instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
|
---|
| 93 |
|
---|
[7505] | 94 | return instance;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[7548] | 97 | private GQAPData Load(CordeauGQAPParser parser) {
|
---|
| 98 | var instance = new GQAPData();
|
---|
[7879] | 99 | instance.BestKnownQuality = parser.BestKnownQuality;
|
---|
[7538] | 100 | instance.Equipments = parser.Equipments;
|
---|
| 101 | instance.Locations = parser.Locations;
|
---|
| 102 | instance.Demands = parser.Demands;
|
---|
| 103 | instance.Capacities = parser.Capacities;
|
---|
| 104 | instance.Weights = parser.Weights;
|
---|
| 105 | instance.Distances = parser.Distances;
|
---|
| 106 | instance.InstallationCosts = parser.InstallationCosts;
|
---|
| 107 | instance.TransportationCosts = parser.TransportationCosts;
|
---|
| 108 | return instance;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[7505] | 111 | private string GetDescription() {
|
---|
| 112 | return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
|
---|
| 113 | }
|
---|
[7638] | 114 |
|
---|
| 115 | protected virtual string GetResourceName(string fileName) {
|
---|
| 116 | return Assembly.GetExecutingAssembly().GetManifestResourceNames()
|
---|
| 117 | .Where(x => Regex.Match(x, @".*\.Data\." + fileName).Success).SingleOrDefault();
|
---|
| 118 | }
|
---|
[7505] | 119 | }
|
---|
| 120 | }
|
---|