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.QAPLIB {
|
---|
30 | public class QAPLIBInstanceProvider : ProblemInstanceProvider<IQAPInstance> {
|
---|
31 | public override string Name {
|
---|
32 | get { return "QAPLIB"; }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public override string Description {
|
---|
36 | get { return "Quadratic Assignment Problem Library"; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public override Uri WebLink {
|
---|
40 | get { return new Uri("http://www.seas.upenn.edu/qaplib/"); }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override string ReferencePublication {
|
---|
44 | get {
|
---|
45 | return @"R. E. Burkard, S. E. Karisch, and F. Rendl. 1997.
|
---|
46 | QAPLIB - A Quadratic Assignment Problem Library.
|
---|
47 | Journal of Global Optimization, 10, pp. 391-403.";
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override IEnumerable<IInstanceDescriptor> GetInstanceDescriptors() {
|
---|
52 | var solutions = Assembly.GetExecutingAssembly()
|
---|
53 | .GetManifestResourceNames()
|
---|
54 | .Where(x => x.EndsWith(".sln"))
|
---|
55 | .ToDictionary(x => Path.GetFileNameWithoutExtension(x) + ".dat", x => x);
|
---|
56 |
|
---|
57 | return Assembly.GetExecutingAssembly()
|
---|
58 | .GetManifestResourceNames()
|
---|
59 | .Where(x => x.EndsWith(".dat"))
|
---|
60 | .OrderBy(x => x)
|
---|
61 | .Select(x => new QAPLIBInstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));
|
---|
62 | }
|
---|
63 |
|
---|
64 | public override IQAPInstance GetInstance(IInstanceDescriptor id) {
|
---|
65 | var descriptor = (QAPLIBInstanceDescriptor)id;
|
---|
66 | var instance = new QAPLIBInstance();
|
---|
67 | using (var stream = Assembly.GetExecutingAssembly()
|
---|
68 | .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
|
---|
69 | QAPLIBParser datParser = new QAPLIBParser();
|
---|
70 | datParser.Parse(stream);
|
---|
71 | if (datParser.Error != null) throw datParser.Error;
|
---|
72 | instance.Dimension = datParser.Size;
|
---|
73 | instance.Distances = datParser.Distances;
|
---|
74 | instance.Weights = datParser.Weights;
|
---|
75 |
|
---|
76 | instance.Name = id.Name;
|
---|
77 | instance.Description = id.Description;
|
---|
78 |
|
---|
79 | if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
|
---|
80 | using (Stream solStream = Assembly.GetExecutingAssembly()
|
---|
81 | .GetManifestResourceStream(descriptor.SolutionIdentifier)) {
|
---|
82 | QAPLIBSolutionParser slnParser = new QAPLIBSolutionParser();
|
---|
83 | slnParser.Parse(solStream, true);
|
---|
84 | if (slnParser.Error != null) throw slnParser.Error;
|
---|
85 |
|
---|
86 | instance.BestKnownAssignment = slnParser.Assignment;
|
---|
87 | instance.BestKnownQuality = slnParser.Quality;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 | return instance;
|
---|
92 | }
|
---|
93 |
|
---|
94 | private string GetPrettyName(string instanceIdentifier) {
|
---|
95 | return Regex.Match(instanceIdentifier, GetType().Namespace + @"\.Data\.(.*)\.dat").Groups[1].Captures[0].Value;
|
---|
96 | }
|
---|
97 |
|
---|
98 | private string GetDescription() {
|
---|
99 | return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|