1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.IO;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Reflection;
|
---|
27 | using System.Text.RegularExpressions;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.Instances.CordeauGQAP {
|
---|
30 | public class CordeauGQAPInstanceProvider : ProblemInstanceProvider<GQAPData> {
|
---|
31 | public override string Name {
|
---|
32 | get { return "Cordeau et al. GQAP instances"; }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public override string Description {
|
---|
36 | get { return "GQAP instances published by Cordeau, Gaudioso, Laporte, and Moccia."; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public override Uri WebLink {
|
---|
40 | get { return null; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override string ReferencePublication {
|
---|
44 | get {
|
---|
45 | return @"Cordeau, J.-F., Gaudioso, M., Laporte, G., Moccia, L. 2006.
|
---|
46 | A memetic heuristic for the generalized quadratic assignment problem.
|
---|
47 | INFORMS Journal on Computing, 18, pp. 433–443.";
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override IEnumerable<IDataDescriptor> GetDataDescriptors() {
|
---|
52 | return Assembly.GetExecutingAssembly()
|
---|
53 | .GetManifestResourceNames()
|
---|
54 | .Where(x => x.EndsWith(".txt"))
|
---|
55 | .OrderBy(x => x)
|
---|
56 | .Select(x => new CordeauGQAPDataDescriptor(GetPrettyName(x), GetDescription(), x));
|
---|
57 | }
|
---|
58 |
|
---|
59 | public override GQAPData LoadData(IDataDescriptor id) {
|
---|
60 | var descriptor = (CordeauGQAPDataDescriptor)id;
|
---|
61 | using (var stream = Assembly.GetExecutingAssembly()
|
---|
62 | .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
|
---|
63 | var parser = new CordeauGQAPParser();
|
---|
64 | parser.Parse(stream);
|
---|
65 | var instance = Load(parser);
|
---|
66 |
|
---|
67 | instance.Name = id.Name;
|
---|
68 | instance.Description = id.Description;
|
---|
69 |
|
---|
70 | return instance;
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | public override GQAPData LoadData(string path) {
|
---|
75 | var parser = new CordeauGQAPParser();
|
---|
76 | parser.Parse(path);
|
---|
77 | var instance = Load(parser);
|
---|
78 |
|
---|
79 | instance.Name = Path.GetFileName(path);
|
---|
80 | instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
|
---|
81 |
|
---|
82 | return instance;
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override void SaveData(GQAPData instance, string path) {
|
---|
86 | throw new NotSupportedException();
|
---|
87 | }
|
---|
88 |
|
---|
89 | private GQAPData Load(CordeauGQAPParser parser) {
|
---|
90 | var instance = new GQAPData();
|
---|
91 | instance.Equipments = parser.Equipments;
|
---|
92 | instance.Locations = parser.Locations;
|
---|
93 | instance.Demands = parser.Demands;
|
---|
94 | instance.Capacities = parser.Capacities;
|
---|
95 | instance.Weights = parser.Weights;
|
---|
96 | instance.Distances = parser.Distances;
|
---|
97 | instance.InstallationCosts = parser.InstallationCosts;
|
---|
98 | instance.TransportationCosts = parser.TransportationCosts;
|
---|
99 | return instance;
|
---|
100 | }
|
---|
101 |
|
---|
102 | private string GetPrettyName(string instanceIdentifier) {
|
---|
103 | return Regex.Match(instanceIdentifier, GetType().Namespace + @"\.Data\.(.*)\.txt").Groups[1].Captures[0].Value;
|
---|
104 | }
|
---|
105 |
|
---|
106 | private string GetDescription() {
|
---|
107 | return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|