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.ElloumiCTAP {
|
---|
30 | public class ElloumiCTAPInstanceProvider : ProblemInstanceProvider<CTAPInstance> {
|
---|
31 | public override string Name {
|
---|
32 | get { return "Elloumi's CTAP instances"; }
|
---|
33 | }
|
---|
34 |
|
---|
35 | public override string Description {
|
---|
36 | get { return "CTAP instances published by Sourour Elloumi"; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public override Uri WebLink {
|
---|
40 | get { return new Uri("http://cedric.cnam.fr/oc/TAP/TAP.html"); }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override string ReferencePublication {
|
---|
44 | get {
|
---|
45 | return @"Elloumi, S. 1991.
|
---|
46 | Contribution for solving non linear programs with o-1 variables, application to task assignment problems in distributed systems.
|
---|
47 | PhD Thesis. Conservatoire National des Arts et Métiers, Paris.";
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override IEnumerable<IInstanceDescriptor> GetInstanceDescriptors() {
|
---|
52 | var solutions = Assembly.GetExecutingAssembly()
|
---|
53 | .GetManifestResourceNames()
|
---|
54 | .Where(x => x.EndsWith(".sol"))
|
---|
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 ElloumiCTAPInstanceDescriptor(GetPrettyName(x), GetDescription(), x, solutions.ContainsKey(x) ? solutions[x] : String.Empty));
|
---|
62 | }
|
---|
63 |
|
---|
64 | public override CTAPInstance LoadInstance(IInstanceDescriptor id) {
|
---|
65 | var descriptor = (ElloumiCTAPInstanceDescriptor)id;
|
---|
66 | using (var stream = Assembly.GetExecutingAssembly()
|
---|
67 | .GetManifestResourceStream(descriptor.InstanceIdentifier)) {
|
---|
68 | var parser = new ElloumiCTAPParser();
|
---|
69 | parser.Parse(stream);
|
---|
70 | var instance = Load(parser);
|
---|
71 |
|
---|
72 | instance.Name = id.Name;
|
---|
73 | instance.Description = id.Description;
|
---|
74 |
|
---|
75 | if (!String.IsNullOrEmpty(descriptor.SolutionIdentifier)) {
|
---|
76 | using (Stream solStream = Assembly.GetExecutingAssembly()
|
---|
77 | .GetManifestResourceStream(descriptor.SolutionIdentifier)) {
|
---|
78 | ElloumiCTAPSolutionParser slnParser = new ElloumiCTAPSolutionParser();
|
---|
79 | slnParser.Parse(solStream, instance.MemoryRequirements.Length);
|
---|
80 | if (slnParser.Error != null) throw slnParser.Error;
|
---|
81 |
|
---|
82 | instance.BestKnownAssignment = slnParser.Assignment;
|
---|
83 | instance.BestKnownQuality = slnParser.Quality;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | return instance;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override CTAPInstance LoadInstance(string path) {
|
---|
91 | var parser = new ElloumiCTAPParser();
|
---|
92 | parser.Parse(path);
|
---|
93 | var instance = Load(parser);
|
---|
94 | instance.Name = Path.GetFileName(path);
|
---|
95 | instance.Description = "Loaded from file \"" + path + "\" on " + DateTime.Now.ToString();
|
---|
96 | return instance;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public override void SaveInstance(CTAPInstance instance, string path) {
|
---|
100 | throw new NotSupportedException();
|
---|
101 | }
|
---|
102 |
|
---|
103 | private CTAPInstance Load(ElloumiCTAPParser parser) {
|
---|
104 | var instance = new CTAPInstance();
|
---|
105 | instance.Processors = parser.Processors;
|
---|
106 | instance.Tasks = parser.Tasks;
|
---|
107 | instance.ExecutionCosts = parser.ExecutionCosts;
|
---|
108 | instance.CommunicationCosts = parser.CommunicationCosts;
|
---|
109 | instance.MemoryRequirements = parser.MemoryRequirements;
|
---|
110 | instance.MemoryCapacities = parser.MemoryCapacities;
|
---|
111 | return instance;
|
---|
112 | }
|
---|
113 |
|
---|
114 | private string GetPrettyName(string instanceIdentifier) {
|
---|
115 | return Regex.Match(instanceIdentifier, GetType().Namespace + @"\.Data\.(.*)\.dat").Groups[1].Captures[0].Value;
|
---|
116 | }
|
---|
117 |
|
---|
118 | private string GetDescription() {
|
---|
119 | return "Embedded instance of plugin version " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().First().Version + ".";
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|